diff --git a/app/policies/account_warning_policy.rb b/app/policies/account_warning_policy.rb index 4f8df7420e..89df267a5b 100644 --- a/app/policies/account_warning_policy.rb +++ b/app/policies/account_warning_policy.rb @@ -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 diff --git a/app/policies/admin/status_policy.rb b/app/policies/admin/status_policy.rb index e9379c25ec..c4ba5c2606 100644 --- a/app/policies/admin/status_policy.rb +++ b/app/policies/admin/status_policy.rb @@ -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 diff --git a/app/policies/backup_policy.rb b/app/policies/backup_policy.rb index 7a4c5b4347..591b99c8bc 100644 --- a/app/policies/backup_policy.rb +++ b/app/policies/backup_policy.rb @@ -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 diff --git a/app/policies/poll_policy.rb b/app/policies/poll_policy.rb index 9d69eb5bb8..4d585b6d94 100644 --- a/app/policies/poll_policy.rb +++ b/app/policies/poll_policy.rb @@ -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 diff --git a/app/policies/user_role_policy.rb b/app/policies/user_role_policy.rb index 6144a0ec4a..44b5589581 100644 --- a/app/policies/user_role_policy.rb +++ b/app/policies/user_role_policy.rb @@ -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