This commit is contained in:
Matt Jankowski 2024-10-17 10:09:29 +00:00 committed by GitHub
commit 31a12f4a22
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 40 additions and 6 deletions

View File

@ -6,11 +6,15 @@ class AccountWarningPolicy < ApplicationPolicy
end
def appeal?
target? && record.created_at >= Appeal::MAX_STRIKE_AGE.ago
target? && eligible_for_appeal?
end
private
def eligible_for_appeal?
record.created_at >= Appeal::MAX_STRIKE_AGE.ago
end
def target?
record.target_account_id == current_account&.id
end

View File

@ -12,7 +12,7 @@ class Admin::StatusPolicy < ApplicationPolicy
end
def show?
role.can?(:manage_reports, :manage_users) && (record.public_visibility? || record.unlisted_visibility? || record.reported? || viewable_through_normal_policy?)
role.can?(:manage_reports, :manage_users) && eligible_to_show?
end
def destroy?
@ -29,6 +29,10 @@ class Admin::StatusPolicy < ApplicationPolicy
private
def eligible_to_show?
record.distributable? || record.reported? || viewable_through_normal_policy?
end
def viewable_through_normal_policy?
StatusPolicy.new(current_account, record, @preloaded_relations).show?
end

View File

@ -4,6 +4,16 @@ class BackupPolicy < ApplicationPolicy
MIN_AGE = 6.days
def create?
user_signed_in? && current_user.backups.where(created_at: MIN_AGE.ago..).count.zero?
user_signed_in? && eligible_for_backup?
end
private
def eligible_for_backup?
current_user
.backups
.where(created_at: MIN_AGE.ago..)
.count
.zero?
end
end

View File

@ -2,6 +2,16 @@
class PollPolicy < ApplicationPolicy
def vote?
StatusPolicy.new(current_account, record.status).show? && !current_account.blocking?(record.account) && !record.account.blocking?(current_account)
viewable_through_normal_policy? && accounts_not_blocking?
end
private
def viewable_through_normal_policy?
StatusPolicy.new(current_account, record.status).show?
end
def accounts_not_blocking?
!current_account.blocking?(record.account) && !record.account.blocking?(current_account)
end
end

View File

@ -10,10 +10,16 @@ class UserRolePolicy < ApplicationPolicy
end
def update?
role.can?(:manage_roles) && (role.overrides?(record) || role.id == record.id)
role.can?(:manage_roles) && (role.overrides?(record) || self_editing?)
end
def destroy?
!record.everyone? && role.can?(:manage_roles) && role.overrides?(record) && role.id != record.id
!record.everyone? && role.can?(:manage_roles) && role.overrides?(record) && !self_editing?
end
private
def self_editing?
role.id == record.id
end
end