FIX: use correct site setting when uploading images

FIX: use correct site setting when uploading images

diff --git a/app/assets/javascripts/discourse/app/models/user.js b/app/assets/javascripts/discourse/app/models/user.js
index 58195f7..2dca08a 100644
--- a/app/assets/javascripts/discourse/app/models/user.js
+++ b/app/assets/javascripts/discourse/app/models/user.js
@@ -664,10 +664,12 @@ const User = RestModel.extend({
   },
 
   isAllowedToUploadAFile(type) {
+    const settingName = type === "image" ? "embedded_media" : "attachments";
+
     return (
       this.staff ||
       this.trust_level > 0 ||
-      this.siteSettings[`newuser_max_${type}s`] > 0
+      this.siteSettings[`newuser_max_${settingName}`] > 0
     );
   },
 
diff --git a/test/javascripts/lib/uploads-test.js b/test/javascripts/lib/uploads-test.js
index fae7042..a8492d7 100644
--- a/test/javascripts/lib/uploads-test.js
+++ b/test/javascripts/lib/uploads-test.js
@@ -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) {
   this.siteSettings.newuser_max_attachments = 0;
   sandbox.stub(bootbox, "alert");

GitHub sha: 6391db59

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/discobots-new-user-tutorial-stuck-at-upload-image-step/160529/11

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/new-user-cannot-upload-images/160435/4