Tags: don't allow deprecation of tags without wiki

This commit is contained in:
nonamethanks
2022-04-09 16:26:13 +02:00
parent a4659b4d09
commit 11281d6f58
4 changed files with 68 additions and 40 deletions

View File

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

View File

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