Merge commit '4d2a148ccbedc818c98fd712a0b44869c1019321' into glitch-soc/merge-upstream
This commit is contained in:
commit
e3cb4dea42
85 files changed
+1684
-841
No files matched your search
@@ -1,11 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Admin::AccountAction
|
||||
include ActiveModel::Model
|
||||
include ActiveModel::Attributes
|
||||
include AccountableConcern
|
||||
include Authorization
|
||||
|
||||
class Admin::AccountAction < Admin::BaseAction
|
||||
TYPES = %w(
|
||||
none
|
||||
disable
|
||||
@@ -15,49 +10,13 @@ class Admin::AccountAction
|
||||
).freeze
|
||||
|
||||
attr_accessor :target_account,
|
||||
:current_account,
|
||||
:type,
|
||||
:text,
|
||||
:report_id,
|
||||
:warning_preset_id
|
||||
|
||||
attr_reader :warning
|
||||
|
||||
attribute :include_statuses, :boolean, default: true
|
||||
attribute :send_email_notification, :boolean, default: true
|
||||
|
||||
alias send_email_notification? send_email_notification
|
||||
alias include_statuses? include_statuses
|
||||
|
||||
validates :type, :target_account, :current_account, presence: true
|
||||
validates :type, inclusion: { in: TYPES }
|
||||
|
||||
def save
|
||||
return false unless valid?
|
||||
|
||||
ApplicationRecord.transaction do
|
||||
process_action!
|
||||
process_strike!
|
||||
process_reports!
|
||||
end
|
||||
|
||||
process_notification!
|
||||
process_queue!
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def save!
|
||||
raise ActiveRecord::RecordInvalid, self unless save
|
||||
end
|
||||
|
||||
def report
|
||||
@report ||= Report.find(report_id) if report_id.present?
|
||||
end
|
||||
|
||||
def with_report?
|
||||
!report.nil?
|
||||
end
|
||||
validates :target_account, presence: true
|
||||
|
||||
class << self
|
||||
def types_for_account(account)
|
||||
@@ -84,6 +43,17 @@ class Admin::AccountAction
|
||||
private
|
||||
|
||||
def process_action!
|
||||
ApplicationRecord.transaction do
|
||||
handle_type!
|
||||
process_strike!
|
||||
process_reports!
|
||||
end
|
||||
|
||||
process_notification!
|
||||
process_queue!
|
||||
end
|
||||
|
||||
def handle_type!
|
||||
case type
|
||||
when 'disable'
|
||||
handle_disable!
|
||||
@@ -96,20 +66,6 @@ class Admin::AccountAction
|
||||
end
|
||||
end
|
||||
|
||||
def process_strike!
|
||||
@warning = target_account.strikes.create!(
|
||||
account: current_account,
|
||||
report: report,
|
||||
action: type,
|
||||
text: text_for_warning,
|
||||
status_ids: status_ids
|
||||
)
|
||||
|
||||
# A log entry is only interesting if the warning contains
|
||||
# custom text from someone. Otherwise it's just noise.
|
||||
log_action(:create, @warning) if @warning.text.present? && type == 'none'
|
||||
end
|
||||
|
||||
def process_reports!
|
||||
# If we're doing "mark as resolved" on a single report,
|
||||
# then we want to keep other reports open in case they
|
||||
@@ -161,17 +117,6 @@ class Admin::AccountAction
|
||||
queue_suspension_worker! if type == 'suspend'
|
||||
end
|
||||
|
||||
def process_notification!
|
||||
return unless warnable?
|
||||
|
||||
UserMailer.warning(target_account.user, warning).deliver_later!
|
||||
LocalNotificationWorker.perform_async(target_account.id, warning.id, 'AccountWarning', 'moderation_warning')
|
||||
end
|
||||
|
||||
def warnable?
|
||||
send_email_notification? && target_account.local?
|
||||
end
|
||||
|
||||
def status_ids
|
||||
report.status_ids if with_report? && include_statuses?
|
||||
end
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Admin::BaseAction
|
||||
include ActiveModel::Model
|
||||
include ActiveModel::Attributes
|
||||
include AccountableConcern
|
||||
include Authorization
|
||||
|
||||
attr_accessor :current_account,
|
||||
:type,
|
||||
:text,
|
||||
:report_id
|
||||
|
||||
attr_reader :warning
|
||||
|
||||
attribute :send_email_notification, :boolean, default: true
|
||||
|
||||
alias send_email_notification? send_email_notification
|
||||
|
||||
validates :type, :current_account, presence: true
|
||||
validates :type, inclusion: { in: ->(a) { a.class::TYPES } }
|
||||
|
||||
def save
|
||||
return false unless valid?
|
||||
|
||||
process_action!
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def save!
|
||||
raise ActiveRecord::RecordInvalid, self unless save
|
||||
end
|
||||
|
||||
def report
|
||||
@report ||= Report.find(report_id) if report_id.present?
|
||||
end
|
||||
|
||||
def with_report?
|
||||
!report.nil?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def process_strike!(action = type)
|
||||
@warning = target_account.strikes.create!(
|
||||
account: current_account,
|
||||
report: report,
|
||||
action:,
|
||||
text: text_for_warning,
|
||||
status_ids: status_ids
|
||||
)
|
||||
end
|
||||
|
||||
def process_notification!
|
||||
return unless warnable?
|
||||
|
||||
UserMailer.warning(target_account.user, warning).deliver_later!
|
||||
LocalNotificationWorker.perform_async(target_account.id, warning.id, 'AccountWarning', 'moderation_warning')
|
||||
end
|
||||
|
||||
def warnable?
|
||||
send_email_notification? && target_account.local?
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,120 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Admin::ModerationAction < Admin::BaseAction
|
||||
TYPES = %w(
|
||||
delete
|
||||
mark_as_sensitive
|
||||
).freeze
|
||||
|
||||
validates :report_id, presence: true
|
||||
|
||||
private
|
||||
|
||||
def status_ids
|
||||
report.status_ids
|
||||
end
|
||||
|
||||
def statuses
|
||||
@statuses ||= Status.with_discarded.where(id: status_ids).reorder(nil)
|
||||
end
|
||||
|
||||
def collections
|
||||
report.collections
|
||||
end
|
||||
|
||||
def process_action!
|
||||
case type
|
||||
when 'delete'
|
||||
handle_delete!
|
||||
when 'mark_as_sensitive'
|
||||
handle_mark_as_sensitive!
|
||||
end
|
||||
end
|
||||
|
||||
def handle_delete!
|
||||
statuses.each { |status| authorize([:admin, status], :destroy?) }
|
||||
collections.each { |collection| authorize([:admin, collection], :destroy?) }
|
||||
|
||||
ApplicationRecord.transaction do
|
||||
delete_statuses!
|
||||
delete_collections!
|
||||
|
||||
resolve_report!
|
||||
process_strike!(:delete_statuses)
|
||||
|
||||
create_tombstones! unless target_account.local?
|
||||
end
|
||||
|
||||
process_notification!
|
||||
|
||||
RemovalWorker.push_bulk(status_ids) { |status_id| [status_id, { 'preserve' => target_account.local?, 'immediate' => !target_account.local? }] }
|
||||
end
|
||||
|
||||
def handle_mark_as_sensitive!
|
||||
collections.each { |collection| authorize([:admin, collection], :update?) }
|
||||
|
||||
# Can't use a transaction here because UpdateStatusService queues
|
||||
# Sidekiq jobs
|
||||
mark_statuses_as_sensitive!
|
||||
mark_collections_as_sensitive!
|
||||
|
||||
resolve_report!
|
||||
process_strike!(:mark_statuses_as_sensitive)
|
||||
process_notification!
|
||||
end
|
||||
|
||||
def delete_statuses!
|
||||
statuses.each do |status|
|
||||
status.discard_with_reblogs
|
||||
log_action(:destroy, status)
|
||||
end
|
||||
end
|
||||
|
||||
def delete_collections!
|
||||
collections.each do |collection|
|
||||
collection.destroy!
|
||||
log_action(:destroy, collection)
|
||||
end
|
||||
end
|
||||
|
||||
def create_tombstones!
|
||||
(statuses + collections).each { |record| Tombstone.find_or_create_by(uri: record.uri, account: target_account, by_moderator: true) }
|
||||
end
|
||||
|
||||
def mark_statuses_as_sensitive!
|
||||
representative_account = Account.representative
|
||||
|
||||
statuses.includes(:media_attachments, preview_cards_status: :preview_card).find_each do |status|
|
||||
next if status.discarded? || !(status.with_media? || status.with_preview_card?)
|
||||
|
||||
authorize([:admin, status], :update?)
|
||||
|
||||
if target_account.local?
|
||||
UpdateStatusService.new.call(status, representative_account.id, sensitive: true)
|
||||
else
|
||||
status.update(sensitive: true)
|
||||
end
|
||||
|
||||
log_action(:update, status)
|
||||
end
|
||||
end
|
||||
|
||||
def mark_collections_as_sensitive!
|
||||
collections.each do |collection|
|
||||
UpdateCollectionService.new.call(collection, sensitive: true)
|
||||
|
||||
log_action(:update, collection)
|
||||
end
|
||||
end
|
||||
|
||||
def resolve_report!
|
||||
report.resolve!(current_account)
|
||||
log_action(:resolve, report)
|
||||
end
|
||||
|
||||
def target_account
|
||||
report.target_account
|
||||
end
|
||||
|
||||
def text_for_warning = text
|
||||
end
|
||||
@@ -1,20 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Admin::StatusBatchAction
|
||||
include ActiveModel::Model
|
||||
include ActiveModel::Attributes
|
||||
include AccountableConcern
|
||||
include Authorization
|
||||
class Admin::StatusBatchAction < Admin::BaseAction
|
||||
TYPES = %w(
|
||||
report
|
||||
remove_from_report
|
||||
).freeze
|
||||
|
||||
attr_accessor :current_account, :type,
|
||||
:status_ids, :report_id,
|
||||
:text
|
||||
|
||||
attribute :send_email_notification, :boolean
|
||||
|
||||
def save!
|
||||
process_action!
|
||||
end
|
||||
attr_accessor :status_ids
|
||||
|
||||
private
|
||||
|
||||
@@ -26,10 +18,6 @@ class Admin::StatusBatchAction
|
||||
return if status_ids.empty?
|
||||
|
||||
case type
|
||||
when 'delete'
|
||||
handle_delete!
|
||||
when 'mark_as_sensitive'
|
||||
handle_mark_as_sensitive!
|
||||
when 'report'
|
||||
handle_report!
|
||||
when 'remove_from_report'
|
||||
@@ -37,71 +25,6 @@ class Admin::StatusBatchAction
|
||||
end
|
||||
end
|
||||
|
||||
def handle_delete!
|
||||
statuses.each { |status| authorize([:admin, status], :destroy?) }
|
||||
|
||||
ApplicationRecord.transaction do
|
||||
statuses.each do |status|
|
||||
status.discard_with_reblogs
|
||||
log_action(:destroy, status)
|
||||
end
|
||||
|
||||
if with_report?
|
||||
report.resolve!(current_account)
|
||||
log_action(:resolve, report)
|
||||
end
|
||||
|
||||
@warning = target_account.strikes.create!(
|
||||
action: :delete_statuses,
|
||||
account: current_account,
|
||||
report: report,
|
||||
status_ids: status_ids,
|
||||
text: text
|
||||
)
|
||||
|
||||
statuses.each { |status| Tombstone.find_or_create_by(uri: status.uri, account: status.account, by_moderator: true) } unless target_account.local?
|
||||
end
|
||||
|
||||
process_notification!
|
||||
|
||||
RemovalWorker.push_bulk(status_ids) { |status_id| [status_id, { 'preserve' => target_account.local?, 'immediate' => !target_account.local? }] }
|
||||
end
|
||||
|
||||
def handle_mark_as_sensitive!
|
||||
representative_account = Account.representative
|
||||
|
||||
# Can't use a transaction here because UpdateStatusService queues
|
||||
# Sidekiq jobs
|
||||
statuses.includes(:media_attachments, preview_cards_status: :preview_card).find_each do |status|
|
||||
next if status.discarded? || !(status.with_media? || status.with_preview_card?)
|
||||
|
||||
authorize([:admin, status], :update?)
|
||||
|
||||
if target_account.local?
|
||||
UpdateStatusService.new.call(status, representative_account.id, sensitive: true)
|
||||
else
|
||||
status.update(sensitive: true)
|
||||
end
|
||||
|
||||
log_action(:update, status)
|
||||
|
||||
if with_report?
|
||||
report.resolve!(current_account)
|
||||
log_action(:resolve, report)
|
||||
end
|
||||
end
|
||||
|
||||
@warning = target_account.strikes.create!(
|
||||
action: :mark_statuses_as_sensitive,
|
||||
account: current_account,
|
||||
report: report,
|
||||
status_ids: status_ids,
|
||||
text: text
|
||||
)
|
||||
|
||||
process_notification!
|
||||
end
|
||||
|
||||
def handle_report!
|
||||
@report = Report.new(report_params) unless with_report?
|
||||
@report.status_ids = (@report.status_ids + allowed_status_ids).uniq
|
||||
@@ -117,25 +40,6 @@ class Admin::StatusBatchAction
|
||||
report.save!
|
||||
end
|
||||
|
||||
def report
|
||||
@report ||= Report.find(report_id) if report_id.present?
|
||||
end
|
||||
|
||||
def with_report?
|
||||
!report.nil?
|
||||
end
|
||||
|
||||
def process_notification!
|
||||
return unless warnable?
|
||||
|
||||
UserMailer.warning(target_account.user, @warning).deliver_later!
|
||||
LocalNotificationWorker.perform_async(target_account.id, @warning.id, 'AccountWarning', 'moderation_warning')
|
||||
end
|
||||
|
||||
def warnable?
|
||||
send_email_notification && target_account.local?
|
||||
end
|
||||
|
||||
def target_account
|
||||
@target_account ||= statuses.first.account
|
||||
end
|
||||
|
||||
@@ -69,6 +69,14 @@ class Collection < ApplicationRecord
|
||||
:featured_collection
|
||||
end
|
||||
|
||||
def to_log_human_identifier
|
||||
account.acct
|
||||
end
|
||||
|
||||
def to_log_permalink
|
||||
ActivityPub::TagManager.instance.uri_for(self)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def tag_is_usable
|
||||
|
||||
Reference in new issue
Block a user