FIX: use correct site setting when uploading images

This commit is contained in:
jbrw 2020-08-11 18:13:55 -04:00
parent c05aced094
commit 6391db5921
No known key found for this signature in database
GPG Key ID: FAFF7D94CE3F957B
2 changed files with 28 additions and 1 deletions

View File

@ -664,10 +664,12 @@ const User = RestModel.extend({
}, },
isAllowedToUploadAFile(type) { isAllowedToUploadAFile(type) {
const settingName = type === "image" ? "embedded_media" : "attachments";
return ( return (
this.staff || this.staff ||
this.trust_level > 0 || this.trust_level > 0 ||
this.siteSettings[`newuser_max_${type}s`] > 0 this.siteSettings[`newuser_max_${settingName}`] > 0
); );
}, },

View File

@ -56,6 +56,31 @@ QUnit.test("new user cannot upload images", function(assert) {
); );
}); });
QUnit.test("new user can upload images if allowed", function(assert) {
this.siteSettings.newuser_max_embedded_media = 1;
this.siteSettings.default_trust_level = 0;
sandbox.stub(bootbox, "alert");
assert.ok(
validateUploadedFiles([{ name: "image.png" }], {
user: User.create(),
siteSettings: this.siteSettings
})
);
});
QUnit.test("TL1 can upload images", function(assert) {
this.siteSettings.newuser_max_embedded_media = 0;
sandbox.stub(bootbox, "alert");
assert.ok(
validateUploadedFiles([{ name: "image.png" }], {
user: User.create({ trust_level: 1 }),
siteSettings: this.siteSettings
})
);
});
QUnit.test("new user cannot upload attachments", function(assert) { QUnit.test("new user cannot upload attachments", function(assert) {
this.siteSettings.newuser_max_attachments = 0; this.siteSettings.newuser_max_attachments = 0;
sandbox.stub(bootbox, "alert"); sandbox.stub(bootbox, "alert");