pundit: convert tags to pundit.

This commit is contained in:
evazion
2020-03-17 17:35:59 -05:00
parent 4cd0b2cbfe
commit 4bb036aff1
6 changed files with 27 additions and 31 deletions

View File

@@ -210,7 +210,7 @@ class Tag < ApplicationRecord
# next few lines if the category is changed.
tag.update_category_cache
if tag.editable_by?(creator)
if Pundit.policy!([creator, nil], tag).can_change_category?
tag.update(category: category_id)
end
end
@@ -382,13 +382,6 @@ class Tag < ApplicationRecord
cosplay_tags.grep(/\A(.+)_\(cosplay\)\Z/) { "#{TagAlias.to_aliased([$1]).first}_(cosplay)" } + other_tags
end
def editable_by?(user)
return true if user.is_admin?
return true if !is_locked? && user.is_builder? && post_count < 1_000
return true if !is_locked? && user.is_member? && post_count < 50
return false
end
def posts
Post.tag_match(name)
end