From d86d4752cbb68acad381f0b30a6702f04d8726db Mon Sep 17 00:00:00 2001 From: Kane York Date: Thu, 10 Sep 2015 14:04:21 -0700 Subject: [PATCH 1/3] FIX: Don't allow editing seeded category security settings --- .../components/edit-category-security.js.es6 | 16 ++++++++++++---- .../components/edit-category-security.hbs | 9 ++++++++- app/serializers/category_serializer.rb | 6 ++++++ config/locales/client.en.yml | 1 + config/site_settings.yml | 8 +++----- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/discourse/components/edit-category-security.js.es6 b/app/assets/javascripts/discourse/components/edit-category-security.js.es6 index 593a604e7ad..60c3f4ddc1a 100644 --- a/app/assets/javascripts/discourse/components/edit-category-security.js.es6 +++ b/app/assets/javascripts/discourse/components/edit-category-security.js.es6 @@ -7,16 +7,24 @@ export default buildCategoryPanel('security', { actions: { editPermissions() { - this.set('editingPermissions', true); + if (!this.get('category.is_special')) { + this.set('editingPermissions', true); + } }, addPermission(group, id) { - this.get('category').addPermission({group_name: group + "", - permission: Discourse.PermissionType.create({id})}); + if (!this.get('category.is_special')) { + this.get('category').addPermission({ + group_name: group + "", + permission: Discourse.PermissionType.create({id}) + }); + } }, removePermission(permission) { - this.get('category').removePermission(permission); + if (!this.get('category.is_special')) { + this.get('category').removePermission(permission); + } }, } }); diff --git a/app/assets/javascripts/discourse/templates/components/edit-category-security.hbs b/app/assets/javascripts/discourse/templates/components/edit-category-security.hbs index 02361e3cf7b..d5468a49663 100644 --- a/app/assets/javascripts/discourse/templates/components/edit-category-security.hbs +++ b/app/assets/javascripts/discourse/templates/components/edit-category-security.hbs @@ -1,4 +1,9 @@
+ {{#if category.is_special}} +

{{i18n 'category.special_warning'}}

+ {{else}} + + {{/if}}
diff --git a/app/serializers/category_serializer.rb b/app/serializers/category_serializer.rb index 1bf08f89fcb..1f8ee5bf882 100644 --- a/app/serializers/category_serializer.rb +++ b/app/serializers/category_serializer.rb @@ -11,6 +11,7 @@ class CategorySerializer < BasicCategorySerializer :suppress_from_homepage, :can_delete, :cannot_delete_reason, + :is_special, :allow_badges, :custom_fields @@ -37,6 +38,11 @@ class CategorySerializer < BasicCategorySerializer true end + def is_special + [SiteSetting.lounge_category_id, SiteSetting.meta_category_id, SiteSetting.staff_category_id, SiteSetting.uncategorized_category_id] + .include? object.id + end + def include_can_delete? scope && scope.can_delete?(object) end diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 7799a825451..bbc1833f034 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1539,6 +1539,7 @@ en: change_in_category_topic: "Edit Description" already_used: 'This color has been used by another category' security: "Security" + special_warning: "Warning: This category is a pre-seeded category and the security settings cannot be edited. If you do not wish to use this category, delete it instead of repurposing it." images: "Images" auto_close_label: "Auto-close topics after:" auto_close_units: "hours" diff --git a/config/site_settings.yml b/config/site_settings.yml index 754e067b827..c6ec2546701 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -418,9 +418,6 @@ posting: newuser_max_attachments: client: true default: 0 - uncategorized_category_id: - default: -1 - hidden: true post_excerpt_maxlength: 300 display_name_on_posts: client: true @@ -922,14 +919,15 @@ uncategorized: lounge_category_id: default: -1 hidden: true - meta_category_id: default: -1 hidden: true - staff_category_id: default: -1 hidden: true + uncategorized_category_id: + default: -1 + hidden: true performance_report_topic_id: default: -1 From a9d10f454bf32eaf3c427f3bdb0446987d2e5880 Mon Sep 17 00:00:00 2001 From: Kane York Date: Thu, 10 Sep 2015 14:12:08 -0700 Subject: [PATCH 2/3] Oop --- .../discourse/templates/components/edit-category-security.hbs | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/assets/javascripts/discourse/templates/components/edit-category-security.hbs b/app/assets/javascripts/discourse/templates/components/edit-category-security.hbs index d5468a49663..1b323792a9e 100644 --- a/app/assets/javascripts/discourse/templates/components/edit-category-security.hbs +++ b/app/assets/javascripts/discourse/templates/components/edit-category-security.hbs @@ -1,8 +1,6 @@
{{#if category.is_special}}

{{i18n 'category.special_warning'}}

- {{else}} - {{/if}}
    {{#each category.permissions as |p|}} From b706c59ab9d12a7b776327bebc8ad40a882cc490 Mon Sep 17 00:00:00 2001 From: Kane York Date: Fri, 11 Sep 2015 09:14:45 -0700 Subject: [PATCH 3/3] Use the json boolean trick --- app/serializers/category_serializer.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/serializers/category_serializer.rb b/app/serializers/category_serializer.rb index 1f8ee5bf882..6138f1d1bd4 100644 --- a/app/serializers/category_serializer.rb +++ b/app/serializers/category_serializer.rb @@ -38,11 +38,15 @@ class CategorySerializer < BasicCategorySerializer true end - def is_special + def include_is_special? [SiteSetting.lounge_category_id, SiteSetting.meta_category_id, SiteSetting.staff_category_id, SiteSetting.uncategorized_category_id] .include? object.id end + def is_special + true + end + def include_can_delete? scope && scope.can_delete?(object) end