0
0
Fork 0

Add appeals (#17364)

* Add appeals

* Add ability to reject appeals and ability to browse pending appeals in admin UI

* Add strikes to account page in settings

* Various fixes and improvements

- Add separate notification setting for appeals, separate from reports
- Fix style of links in report/strike header
- Change approving an appeal to not restore statuses (due to federation complexities)
- Change style of successfully appealed strikes on account settings page
- Change account settings page to only show unappealed or recently appealed strikes

* Change appealed_at to overruled_at

* Fix missing method error
This commit is contained in:
Eugen Rochko 2022-02-14 21:27:53 +01:00 committed by GitHub
parent 5be705e1e0
commit 564efd0651
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
60 changed files with 1212 additions and 93 deletions

View file

@ -270,6 +270,10 @@ class Account < ApplicationRecord
true
end
def previous_strikes_count
strikes.where(overruled_at: nil).count
end
def keypair
@keypair ||= OpenSSL::PKey::RSA.new(private_key || public_key)
end

View file

@ -24,6 +24,8 @@ class AccountFilter
scope = Account.includes(:account_stat, user: [:ips, :invite_request]).without_instance_actor.reorder(nil)
params.each do |key, value|
next if key.to_s == 'page'
scope.merge!(scope_for(key, value.to_s.strip)) if value.present?
end

View file

@ -12,6 +12,7 @@
# updated_at :datetime not null
# report_id :bigint(8)
# status_ids :string is an Array
# overruled_at :datetime
#
class AccountWarning < ApplicationRecord
@ -28,12 +29,17 @@ class AccountWarning < ApplicationRecord
belongs_to :target_account, class_name: 'Account', inverse_of: :strikes
belongs_to :report, optional: true
has_one :appeal, dependent: :destroy
has_one :appeal, dependent: :destroy, inverse_of: :strike
scope :latest, -> { order(id: :desc) }
scope :custom, -> { where.not(text: '') }
scope :active, -> { where(overruled_at: nil).or(where('account_warnings.overruled_at >= ?', 30.days.ago)) }
def statuses
Status.with_discarded.where(id: status_ids || [])
end
def overruled?
overruled_at.present?
end
end

View file

@ -8,6 +8,8 @@ class Admin::ActionLogFilter
).freeze
ACTION_TYPE_MAP = {
approve_appeal: { target_type: 'Appeal', action: 'approve' }.freeze,
reject_appeal: { target_type: 'Appeal', action: 'reject' }.freeze,
assigned_to_self_report: { target_type: 'Report', action: 'assigned_to_self' }.freeze,
change_email_user: { target_type: 'User', action: 'change_email' }.freeze,
confirm_user: { target_type: 'User', action: 'confirm' }.freeze,

View file

@ -0,0 +1,49 @@
# frozen_string_literal: true
class Admin::AppealFilter
KEYS = %i(
status
).freeze
attr_reader :params
def initialize(params)
@params = params
end
def results
scope = Appeal.order(id: :desc)
params.each do |key, value|
next if %w(page).include?(key.to_s)
scope.merge!(scope_for(key, value.to_s.strip)) if value.present?
end
scope
end
private
def scope_for(key, value)
case key.to_s
when 'status'
status_scope(value)
else
raise "Unknown filter: #{key}"
end
end
def status_scope(value)
case value
when 'approved'
Appeal.approved
when 'rejected'
Appeal.rejected
when 'pending'
Appeal.pending
else
raise "Unknown status: #{value}"
end
end
end

58
app/models/appeal.rb Normal file
View file

@ -0,0 +1,58 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: appeals
#
# id :bigint(8) not null, primary key
# account_id :bigint(8) not null
# account_warning_id :bigint(8) not null
# text :text default(""), not null
# approved_at :datetime
# approved_by_account_id :bigint(8)
# rejected_at :datetime
# rejected_by_account_id :bigint(8)
# created_at :datetime not null
# updated_at :datetime not null
#
class Appeal < ApplicationRecord
belongs_to :account
belongs_to :strike, class_name: 'AccountWarning', foreign_key: 'account_warning_id'
belongs_to :approved_by_account, class_name: 'Account', optional: true
belongs_to :rejected_by_account, class_name: 'Account', optional: true
validates :text, presence: true, length: { maximum: 2_000 }
validates :account_warning_id, uniqueness: true
validate :validate_time_frame, on: :create
scope :approved, -> { where.not(approved_at: nil) }
scope :rejected, -> { where.not(rejected_at: nil) }
scope :pending, -> { where(approved_at: nil, rejected_at: nil) }
def pending?
!approved? && !rejected?
end
def approved?
approved_at.present?
end
def rejected?
rejected_at.present?
end
def approve!(current_account)
update!(approved_at: Time.now.utc, approved_by_account: current_account)
end
def reject!(current_account)
update!(rejected_at: Time.now.utc, rejected_by_account: current_account)
end
private
def validate_time_frame
errors.add(:base, I18n.t('strikes.errors.too_late')) if Time.now.utc > (strike.created_at + 20.days)
end
end

View file

@ -265,6 +265,10 @@ class User < ApplicationRecord
settings.notification_emails['pending_account']
end
def allows_appeal_emails?
settings.notification_emails['appeal']
end
def allows_trending_tag_emails?
settings.notification_emails['trending_tag']
end