Files
danbooru/app/policies/comment_policy.rb
evazion ee638f976f Add /user_actions page.
Add a /user_actions page. This page shows you a global timeline of
(almost) all activity on the site, including uploads, comments, votes,
edits, forum posts, and so on.

The main things it doesn't include are post edits, pool edits, and
favorites (posts and pools live in a separate database, and favorites
don't have the timestamps we need for ordering).

This page is useful for moderation purposes because it lets you see a
history of almost all of a user's activity on a single page.

Currently this page is mod-only. In the future it will be open to all
users, so you can view the history of your own site activity, or the
activity of others.
2022-09-16 05:39:25 -05:00

48 lines
1.0 KiB
Ruby

# frozen_string_literal: true
class CommentPolicy < ApplicationPolicy
def create?
unbanned?
end
def update?
unbanned? && (user.is_moderator? || (record.updater_id == user.id && !record.is_deleted?))
end
def reportable?
unbanned? && record.creator_id != user.id && !record.creator.is_moderator? && !record.is_deleted? && record.created_at.after?(1.year.ago)
end
def can_sticky_comment?
user.is_moderator?
end
def can_see_deleted?
user.is_moderator?
end
def can_see_creator?
!record.is_deleted? || can_see_deleted?
end
def reply?
!record.is_deleted?
end
def permitted_attributes_for_create
[:body, :post_id, :do_not_bump_post, (:is_sticky if can_sticky_comment?)].compact
end
def permitted_attributes_for_update
[:body, :is_deleted, (:is_sticky if can_sticky_comment?)].compact
end
def api_attributes
attributes = super
attributes -= [:creator_id, :updater_id, :body] if record.is_deleted? && !can_see_deleted?
attributes
end
alias_method :undelete?, :update?
end