mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 23:07:28 +08:00
Prevent deleting 'uncategorized' category
This commit is contained in:
@ -53,7 +53,7 @@ Discourse.EditCategoryController = Discourse.ObjectController.extend(Discourse.M
|
|||||||
}.property('saving', 'name', 'color', 'deleting'),
|
}.property('saving', 'name', 'color', 'deleting'),
|
||||||
|
|
||||||
deleteVisible: function() {
|
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'),
|
}.property('id', 'topic_count'),
|
||||||
|
|
||||||
deleteDisabled: function() {
|
deleteDisabled: function() {
|
||||||
|
@ -168,8 +168,11 @@ Discourse.Category = Discourse.Model.extend({
|
|||||||
if (stats.length === 2) return false;
|
if (stats.length === 2) return false;
|
||||||
}, this);
|
}, this);
|
||||||
return stats;
|
return stats;
|
||||||
}
|
},
|
||||||
|
|
||||||
|
isUncategorizedCategory: function() {
|
||||||
|
return this.get('id') === Discourse.Site.currentProp("uncategorized_category_id");
|
||||||
|
}.property('id')
|
||||||
});
|
});
|
||||||
|
|
||||||
Discourse.Category.reopenClass({
|
Discourse.Category.reopenClass({
|
||||||
|
@ -338,6 +338,10 @@ SQL
|
|||||||
|
|
||||||
[read_restricted, mapped]
|
[read_restricted, mapped]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def uncatgorized?
|
||||||
|
id == SiteSetting.uncategorized_category_id
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# == Schema Information
|
# == Schema Information
|
||||||
|
@ -320,7 +320,7 @@ class Guardian
|
|||||||
end
|
end
|
||||||
|
|
||||||
def can_delete_category?(category)
|
def can_delete_category?(category)
|
||||||
is_staff? && category.topic_count == 0
|
is_staff? && category.topic_count == 0 && !category.uncatgorized?
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_delete_topic?(topic)
|
def can_delete_topic?(topic)
|
||||||
|
@ -800,6 +800,12 @@ describe Guardian do
|
|||||||
Guardian.new(moderator).can_delete?(category).should be_false
|
Guardian.new(moderator).can_delete?(category).should be_false
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context 'can_suspend?' do
|
context 'can_suspend?' do
|
||||||
|
Reference in New Issue
Block a user