mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Merge pull request #1744 from verg/prevent_delete_uncategorized
Prevent deleting 'uncategorized' category
This commit is contained in:
commit
126433cf65
5 changed files with 16 additions and 3 deletions
|
@ -53,7 +53,7 @@ Discourse.EditCategoryController = Discourse.ObjectController.extend(Discourse.M
|
|||
}.property('saving', 'name', 'color', 'deleting'),
|
||||
|
||||
deleteVisible: function() {
|
||||
return (this.get('id') && this.get('topic_count') === 0);
|
||||
return (this.get('id') && this.get('topic_count') === 0 && !this.get("isUncategorizedCategory"));
|
||||
}.property('id', 'topic_count'),
|
||||
|
||||
deleteDisabled: function() {
|
||||
|
|
|
@ -168,8 +168,11 @@ Discourse.Category = Discourse.Model.extend({
|
|||
if (stats.length === 2) return false;
|
||||
}, this);
|
||||
return stats;
|
||||
}
|
||||
},
|
||||
|
||||
isUncategorizedCategory: function() {
|
||||
return this.get('id') === Discourse.Site.currentProp("uncategorized_category_id");
|
||||
}.property('id')
|
||||
});
|
||||
|
||||
Discourse.Category.reopenClass({
|
||||
|
|
|
@ -338,6 +338,10 @@ SQL
|
|||
|
||||
[read_restricted, mapped]
|
||||
end
|
||||
|
||||
def uncatgorized?
|
||||
id == SiteSetting.uncategorized_category_id
|
||||
end
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
|
|
@ -320,7 +320,7 @@ class Guardian
|
|||
end
|
||||
|
||||
def can_delete_category?(category)
|
||||
is_staff? && category.topic_count == 0
|
||||
is_staff? && category.topic_count == 0 && !category.uncatgorized?
|
||||
end
|
||||
|
||||
def can_delete_topic?(topic)
|
||||
|
|
|
@ -800,6 +800,12 @@ describe Guardian do
|
|||
Guardian.new(moderator).can_delete?(category).should be_false
|
||||
end
|
||||
|
||||
it "can't be deleted if it is the Uncategorizied Category" do
|
||||
uncategorized_cat_id = SiteSetting.uncategorized_category_id
|
||||
uncategorized_category = Category.find(uncategorized_cat_id)
|
||||
Guardian.new(admin).can_delete?(uncategorized_category).should be_false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'can_suspend?' do
|
||||
|
|
Loading…
Reference in a new issue