pundit: convert moderation reports to pundit.
This commit is contained in:
@@ -3,6 +3,10 @@ class CommentPolicy < ApplicationPolicy
|
||||
unbanned? && (user.is_moderator? || record.updater_id == user.id)
|
||||
end
|
||||
|
||||
def reportable?
|
||||
unbanned? && record.creator_id != user.id && !record.creator.is_moderator?
|
||||
end
|
||||
|
||||
def can_sticky_comment?
|
||||
user.is_moderator?
|
||||
end
|
||||
|
||||
@@ -19,6 +19,10 @@ class DmailPolicy < ApplicationPolicy
|
||||
user.is_member? && (record.owner_id == user.id || record.valid_key?(request.params[:key]))
|
||||
end
|
||||
|
||||
def reportable?
|
||||
unbanned? && record.owner_id == user.id && record.is_recipient? && !record.is_automated? && !record.from.is_moderator?
|
||||
end
|
||||
|
||||
def permitted_attributes_for_create
|
||||
[:title, :body, :to_name, :to_id]
|
||||
end
|
||||
|
||||
@@ -19,6 +19,10 @@ class ForumPostPolicy < ApplicationPolicy
|
||||
unbanned? && show? && user.is_moderator?
|
||||
end
|
||||
|
||||
def reportable?
|
||||
unbanned? && show? && record.creator_id != user.id && !record.creator.is_moderator?
|
||||
end
|
||||
|
||||
def show_deleted?
|
||||
!record.is_deleted? || user.is_moderator?
|
||||
end
|
||||
|
||||
13
app/policies/moderation_report_policy.rb
Normal file
13
app/policies/moderation_report_policy.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class ModerationReportPolicy < ApplicationPolicy
|
||||
def index?
|
||||
user.is_moderator?
|
||||
end
|
||||
|
||||
def create?
|
||||
unbanned? && policy(record.model).reportable?
|
||||
end
|
||||
|
||||
def permitted_attributes
|
||||
[:model_type, :model_id, :reason]
|
||||
end
|
||||
end
|
||||
@@ -15,6 +15,10 @@ class UserPolicy < ApplicationPolicy
|
||||
user.is_member?
|
||||
end
|
||||
|
||||
def reportable?
|
||||
false
|
||||
end
|
||||
|
||||
def fix_counts?
|
||||
user.is_member?
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user