Files
danbooru/app/policies/bulk_update_request_policy.rb
nonamethanks 5932d8d3a3 BURs: don't allow edits to approved scripts
Also fix bad formatting for non-admins in BUR index
2022-06-01 14:07:30 +02:00

36 lines
779 B
Ruby

# frozen_string_literal: true
class BulkUpdateRequestPolicy < ApplicationPolicy
def create?
unbanned? && (record.forum_topic.blank? || policy(record.forum_topic).reply?)
end
def update?
unbanned? && !record.is_approved? && (user.is_admin? || record.user_id == user.id)
end
def approve?
unbanned? && !record.is_approved? && (user.is_admin? || (user.is_builder? && record.is_tag_move_allowed?))
end
def destroy?
record.is_pending? && update?
end
def can_update_forum?
user.is_admin?
end
def permitted_attributes_for_create
[:script, :title, :reason, :forum_topic_id]
end
def permitted_attributes_for_update
if can_update_forum?
[:script, :forum_topic_id, :forum_post_id]
else
[:script]
end
end
end