Merge pull request #1744 from verg/prevent_delete_uncategorized

Prevent deleting 'uncategorized' category
This commit is contained in:
Sam 2014-01-01 16:09:49 -08:00
commit 126433cf65
5 changed files with 16 additions and 3 deletions

View File

@ -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() {

View File

@ -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({

View File

@ -338,6 +338,10 @@ SQL
[read_restricted, mapped]
end
def uncatgorized?
id == SiteSetting.uncategorized_category_id
end
end
# == Schema Information

View File

@ -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)

View File

@ -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