blob: 96aaaa7d078b58e30c1a3d4663c750c4b3a41128 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# frozen_string_literal: true
class ApproveAppealService < BaseService
def call(appeal, current_account)
@appeal = appeal
@strike = appeal.strike
@current_account = current_account
ApplicationRecord.transaction do
undo_strike_action!
mark_strike_as_appealed!
end
queue_workers!
notify_target_account!
end
private
def target_account
@strike.target_account
end
def undo_strike_action!
case @strike.action
when 'disable'
undo_disable!
when 'delete_statuses'
undo_delete_statuses!
when 'mark_statuses_as_sensitive'
undo_mark_statuses_as_sensitive!
when 'sensitive'
undo_sensitive!
when 'silence'
undo_silence!
when 'suspend'
undo_suspend!
end
end
def mark_strike_as_appealed!
@appeal.approve!(@current_account)
@strike.touch(:overruled_at)
end
def undo_disable!
target_account.user.enable!
end
def undo_delete_statuses!
# Cannot be undone
end
def undo_mark_statuses_as_sensitive!
representative_account = Account.representative
@strike.statuses.includes(:media_attachments).each do |status|
UpdateStatusService.new.call(status, representative_account.id, sensitive: false) if status.with_media?
end
end
def undo_sensitive!
target_account.unsensitize!
end
def undo_silence!
target_account.unsilence!
end
def undo_suspend!
target_account.unsuspend!
end
def queue_workers!
case @strike.action
when 'suspend'
Admin::UnsuspensionWorker.perform_async(target_account.id)
end
end
def notify_target_account!
UserMailer.appeal_approved(target_account.user, @appeal).deliver_later
end
end
|