Tags: don't allow deprecation of tags without wiki
This commit is contained in:
@@ -131,13 +131,19 @@ class BulkUpdateRequestProcessor
|
||||
|
||||
when :deprecate
|
||||
tag = Tag.find_by_name(args[0])
|
||||
if tag.is_deprecated?
|
||||
if tag.nil?
|
||||
errors.add(:base, "Can't deprecate #{args[0]} (tag doesn't exist)")
|
||||
elsif tag.is_deprecated?
|
||||
errors.add(:base, "Can't deprecate #{args[0]} (tag is already deprecated)")
|
||||
elsif tag.wiki_page.blank?
|
||||
errors.add(:base, "Can't deprecate #{args[0]} (tag must have a wiki page)")
|
||||
end
|
||||
|
||||
when :undeprecate
|
||||
tag = Tag.find_by_name(args[0])
|
||||
if !tag.is_deprecated?
|
||||
if tag.nil?
|
||||
errors.add(:base, "Can't undeprecate #{args[0]} (tag doesn't exist)")
|
||||
elsif !tag.is_deprecated?
|
||||
errors.add(:base, "Can't undeprecate #{args[0]} (tag is not deprecated)")
|
||||
end
|
||||
|
||||
|
||||
@@ -8,13 +8,14 @@ class TagPolicy < ApplicationPolicy
|
||||
end
|
||||
|
||||
def can_change_deprecated_status?
|
||||
return false if record.wiki_page.blank? && !record.is_deprecated?
|
||||
user.is_admin? || (record.post_count == 0 && !record.is_deprecated?)
|
||||
end
|
||||
|
||||
def permitted_attributes
|
||||
[
|
||||
(:category if can_change_category?),
|
||||
(:is_deprecated if can_change_deprecated_status?),
|
||||
].compact
|
||||
permitted = []
|
||||
permitted << :category if can_change_category?
|
||||
permitted << :is_deprecated if can_change_deprecated_status?
|
||||
permitted
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user