Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Don't allow editing seeded category security settings #3749

Merged
merged 3 commits into from Sep 11, 2015
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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 + "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why group + ""? Is that to avoid calling toString()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, looks like I triggered a format there. Same code as before.

permission: Discourse.PermissionType.create({id})
});
}
},

removePermission(permission) {
this.get('category').removePermission(permission);
if (!this.get('category.is_special')) {
this.get('category').removePermission(permission);
}
},
}
});
@@ -1,4 +1,7 @@
<section class='field'>
{{#if category.is_special}}
<p class="warning">{{i18n 'category.special_warning'}}</p>
{{/if}}
<ul class='permission-list'>
{{#each category.permissions as |p|}}
<li>
Expand All @@ -16,6 +19,8 @@
{{view 'select' class="permission-selector" optionValuePath="content.id" optionLabelPath="content.description" content=category.availablePermissions value=selectedPermission}}
<button {{action "addPermission" selectedGroup selectedPermission}} class="btn btn-small">{{i18n 'category.add_permission'}}</button>
{{else}}
<button {{action "editPermissions"}} class="btn btn-small">{{i18n 'category.edit_permissions'}}</button>
{{#unless category.is_special}}
<button {{action "editPermissions"}} class="btn btn-small">{{i18n 'category.edit_permissions'}}</button>
{{/unless}}
{{/if}}
</section>
6 changes: 6 additions & 0 deletions app/serializers/category_serializer.rb
Expand Up @@ -11,6 +11,7 @@ class CategorySerializer < BasicCategorySerializer
:suppress_from_homepage,
:can_delete,
:cannot_delete_reason,
:is_special,
:allow_badges,
:custom_fields

Expand All @@ -37,6 +38,11 @@ def can_delete
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I prefer to do to keep JSON size down is have boolean values return true always, then use include_is_special? with the logic. That way the attribute will not be present unless true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

b706c59


def include_can_delete?
scope && scope.can_delete?(object)
end
Expand Down
1 change: 1 addition & 0 deletions config/locales/client.en.yml
Expand Up @@ -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"
Expand Down
8 changes: 3 additions & 5 deletions config/site_settings.yml
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down