DEV: prevents staff computed property to be overridden (#7931)

DEV: prevents staff computed property to be overridden (#7931)

diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6
index d907a0f..5728401 100644
--- a/app/assets/javascripts/discourse/controllers/composer.js.es6
+++ b/app/assets/javascripts/discourse/controllers/composer.js.es6
@@ -199,11 +199,7 @@ export default Ember.Controller.extend({
     );
   },
 
-  @computed
-  isStaffUser() {
-    const currentUser = this.currentUser;
-    return currentUser && currentUser.get("staff");
-  },
+  isStaffUser: Ember.computed.reads("currentUser.staff"),
 
   canUnlistTopic: Ember.computed.and("model.creatingTopic", "isStaffUser"),
 
diff --git a/app/assets/javascripts/discourse/models/user.js.es6 b/app/assets/javascripts/discourse/models/user.js.es6
index 9beef8e..8d3ad41 100644
--- a/app/assets/javascripts/discourse/models/user.js.es6
+++ b/app/assets/javascripts/discourse/models/user.js.es6
@@ -54,7 +54,16 @@ const User = RestModel.extend({
     return UserDraftsStream.create({ user: this });
   },
 
-  staff: Ember.computed.or("admin", "moderator"),
+  staff: Ember.computed("admin", "moderator", {
+    get() {
+      return this.admin || this.moderator;
+    },
+
+    // prevents staff property to be overridden
+    set() {
+      return this.admin || this.moderator;
+    }
+  }),
 
   destroySession() {
     return ajax(`/session/${this.username}`, { type: "DELETE" });
diff --git a/plugins/poll/test/javascripts/acceptance/poll-builder-disabled-test.js.es6 b/plugins/poll/test/javascripts/acceptance/poll-builder-disabled-test.js.es6
index 6a126d6..bb04f7c 100644
--- a/plugins/poll/test/javascripts/acceptance/poll-builder-disabled-test.js.es6
+++ b/plugins/poll/test/javascripts/acceptance/poll-builder-disabled-test.js.es6
@@ -14,7 +14,7 @@ acceptance("Poll Builder - polls are disabled", {
 });
 
 test("regular user - sufficient trust level", assert => {
-  updateCurrentUser({ staff: false, trust_level: 3 });
+  updateCurrentUser({ moderator: false, admin: false, trust_level: 3 });
 
   displayPollBuilderButton();
 
@@ -27,7 +27,7 @@ test("regular user - sufficient trust level", assert => {
 });
 
 test("regular user - insufficient trust level", assert => {
-  updateCurrentUser({ staff: false, trust_level: 1 });
+  updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
 
   displayPollBuilderButton();
 
@@ -40,7 +40,7 @@ test("regular user - insufficient trust level", assert => {
 });
 
 test("staff", assert => {
-  updateCurrentUser({ staff: true });
+  updateCurrentUser({ moderator: true });
 
   displayPollBuilderButton();
 
diff --git a/plugins/poll/test/javascripts/acceptance/poll-builder-enabled-test.js.es6 b/plugins/poll/test/javascripts/acceptance/poll-builder-enabled-test.js.es6
index 8880c28..853fd0d 100644
--- a/plugins/poll/test/javascripts/acceptance/poll-builder-enabled-test.js.es6
+++ b/plugins/poll/test/javascripts/acceptance/poll-builder-enabled-test.js.es6
@@ -14,7 +14,7 @@ acceptance("Poll Builder - polls are enabled", {
 });
 
 test("regular user - sufficient trust level", assert => {
-  updateCurrentUser({ staff: false, trust_level: 1 });
+  updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
 
   displayPollBuilderButton();
 
@@ -27,7 +27,7 @@ test("regular user - sufficient trust level", assert => {
 });
 
 test("regular user - insufficient trust level", assert => {
-  updateCurrentUser({ staff: false, trust_level: 0 });
+  updateCurrentUser({ moderator: false, admin: false, trust_level: 0 });
 
   displayPollBuilderButton();
 
@@ -40,7 +40,7 @@ test("regular user - insufficient trust level", assert => {
 });
 
 test("staff - with insufficient trust level", assert => {
-  updateCurrentUser({ staff: true, trust_level: 0 });
+  updateCurrentUser({ moderator: true, trust_level: 0 });
 
   displayPollBuilderButton();
 
diff --git a/test/javascripts/acceptance/composer-actions-test.js.es6 b/test/javascripts/acceptance/composer-actions-test.js.es6
index 7f690dc..fe4dceb 100644
--- a/test/javascripts/acceptance/composer-actions-test.js.es6
+++ b/test/javascripts/acceptance/composer-actions-test.js.es6
@@ -305,7 +305,7 @@ QUnit.test("replying to post - toggle_topic_bump", async assert => {
 QUnit.test("replying to post as staff", async assert => {
   const composerActions = selectKit(".composer-actions");
 
-  updateCurrentUser({ staff: true, admin: false });
+  updateCurrentUser({ admin: true });
   await visit("/t/internationalization-localization/280");
   await click("article#post_3 button.reply");
   await composerActions.expand();
@@ -317,7 +317,7 @@ QUnit.test("replying to post as staff", async assert => {
 QUnit.test("replying to post as TL3 user", async assert => {
   const composerActions = selectKit(".composer-actions");
 
-  updateCurrentUser({ staff: false, admin: false, trust_level: 3 });
+  updateCurrentUser({ moderator: false, admin: false, trust_level: 3 });
   await visit("/t/internationalization-localization/280");
   await click("article#post_3 button.reply");
   await composerActions.expand();
@@ -335,7 +335,7 @@ QUnit.test("replying to post as TL3 user", async assert => {
 QUnit.test("replying to post as TL4 user", async assert => {
   const composerActions = selectKit(".composer-actions");
 
-  updateCurrentUser({ staff: false, admin: false, trust_level: 4 });
+  updateCurrentUser({ moderator: false, admin: false, trust_level: 4 });
   await visit("/t/internationalization-localization/280");
   await click("article#post_3 button.reply");
   await composerActions.expand();
diff --git a/test/javascripts/acceptance/composer-topic-links-test.js.es6 b/test/javascripts/acceptance/composer-topic-links-test.js.es6
index 8e72180..4de900d 100644
--- a/test/javascripts/acceptance/composer-topic-links-test.js.es6
+++ b/test/javascripts/acceptance/composer-topic-links-test.js.es6
@@ -156,7 +156,7 @@ acceptance("Composer topic featured links when uncategorized is not allowed", {
 });
 
 QUnit.test("Pasting a link enables the text input area", async assert => {
-  updateCurrentUser({ admin: false, staff: false, trust_level: 1 });
+  updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
 
   await visit("/");
   await click("#create-topic");
diff --git a/test/javascripts/acceptance/composer-uncategorized-test.js.es6 b/test/javascripts/acceptance/composer-uncategorized-test.js.es6
index 93fc5eb..c048509 100644
--- a/test/javascripts/acceptance/composer-uncategorized-test.js.es6
+++ b/test/javascripts/acceptance/composer-uncategorized-test.js.es6
@@ -18,7 +18,7 @@ acceptance("Composer and uncategorized is not allowed", {
 });
 
 QUnit.test("Disable body until category is selected", async assert => {
-  updateCurrentUser({ admin: false, staff: false, trust_level: 1 });
+  updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
 
   await visit("/");
   await click("#create-topic");
diff --git a/test/javascripts/acceptance/email-notice-test.js.es6 b/test/javascripts/acceptance/email-notice-test.js.es6
index 0c31703..824b93c 100644
--- a/test/javascripts/acceptance/email-notice-test.js.es6
+++ b/test/javascripts/acceptance/email-notice-test.js.es6
@@ -26,7 +26,7 @@ QUnit.test("shows banner when required", async assert => {
     "alert is displayed when email disabled for non-staff"
   );
 
-  updateCurrentUser({ staff: true, moderator: true });
+  updateCurrentUser({ moderator: true });
   await visit("/");
   assert.ok(
     exists(".alert-emails-disabled"),
diff --git a/test/javascripts/acceptance/enforce-second-factor-test.js.es6 b/test/javascripts/acceptance/enforce-second-factor-test.js.es6
index 87b6ca3..cd4570f 100644
--- a/test/javascripts/acceptance/enforce-second-factor-test.js.es6
+++ b/test/javascripts/acceptance/enforce-second-factor-test.js.es6
@@ -35,7 +35,7 @@ QUnit.test("as an admin", async assert => {
 });
 
 QUnit.test("as a user", async assert => {
-  updateCurrentUser({ staff: false, admin: false });
+  updateCurrentUser({ moderator: false, admin: false });
 

[... diff too long, it was truncated ...]

GitHub sha: c1d2fb11