A platform for community discussion. Free, open, simple.
FIX: show 404 on new category page for moderators when Site Setting disabled (#21448)
David Battersbya19027afae3c
diff --git a/app/assets/javascripts/discourse/app/routes/new-category.js b/app/assets/javascripts/discourse/app/routes/new-category.jsindex 7dbead0fad1..8a0152174e7 100644--- a/app/assets/javascripts/discourse/app/routes/new-category.js+++ b/app/assets/javascripts/discourse/app/routes/new-category.js@@ -12,6 +12,21 @@ export function setNewCategoryDefaultColors(backgroundColor, textColor) {}export default DiscourseRoute.extend({+ beforeModel() {+ if (!this.currentUser) {+ this.replaceWith("/404");+ return;+ }+ if (!this.currentUser.admin) {+ if (+ !this.currentUser.moderator ||+ this.siteSettings.moderators_manage_categories_and_groups === false+ ) {+ this.replaceWith("/404");+ }+ }+ },+model() {return Promise.resolve(this.groupPermissions()).then((permissions) => {diff --git a/app/assets/javascripts/discourse/tests/acceptance/category-new-test.js b/app/assets/javascripts/discourse/tests/acceptance/category-new-test.jsindex 77f4cdd89d0..e5b04cc03a2 100644--- a/app/assets/javascripts/discourse/tests/acceptance/category-new-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/category-new-test.js@@ -10,6 +10,33 @@ import sinon from "sinon";import { test } from "qunit";import selectKit from "discourse/tests/helpers/select-kit-helper";+acceptance("New category access for moderators", function (needs) {+ needs.user({ moderator: true, admin: false, trust_level: 1 });++ test("Authorizes access based on site setting", async function (assert) {+ this.siteSettings.moderators_manage_categories_and_groups = false;+ await visit("/new-category");++ assert.strictEqual(currentURL(), "/404");++ this.siteSettings.moderators_manage_categories_and_groups = true;+ await visit("/new-category");++ assert.strictEqual(+ currentURL(),+ "/new-category",+ "it allows access to new category when site setting is enabled"+ );+ });+});++acceptance("New category access for non authorized users", function () {+ test("Prevents access when not signed in", async function (assert) {+ await visit("/new-category");+ assert.strictEqual(currentURL(), "/404");+ });+});+acceptance("Category New", function (needs) {needs.user();diff --git a/config/site_settings.yml b/config/site_settings.ymlindex bb298ea862b..6f99c27d387 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -1708,7 +1708,9 @@ security:allow_indexing_non_canonical_urls:default: truehidden: true- moderators_manage_categories_and_groups: false+ moderators_manage_categories_and_groups:+ default: false+ client: truemoderators_change_post_ownership:client: truedefault: false