diff options
author | Claire <claire.github-309c@sitedethib.com> | 2022-03-02 19:11:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-02 19:11:17 +0100 |
commit | d9e30efa5ecc87bc9be7b2e28baaf34bd01032f5 (patch) | |
tree | a2bb52cd8418feb062b908dfaf98d00a3c0ccbbe /app/models | |
parent | 0b8fe020b599341d78cc03431eb156485c70ebea (diff) | |
parent | 78781793d5ab370829d7eaee4b8d21994f84763c (diff) |
Merge pull request #1709 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account_warning.rb | 15 | ||||
-rw-r--r-- | app/models/admin/status_batch_action.rb | 34 | ||||
-rw-r--r-- | app/models/status.rb | 4 |
3 files changed, 46 insertions, 7 deletions
diff --git a/app/models/account_warning.rb b/app/models/account_warning.rb index 05d01942d..6067b54b7 100644 --- a/app/models/account_warning.rb +++ b/app/models/account_warning.rb @@ -17,12 +17,13 @@ class AccountWarning < ApplicationRecord enum action: { - none: 0, - disable: 1_000, - delete_statuses: 1_500, - sensitive: 2_000, - silence: 3_000, - suspend: 4_000, + none: 0, + disable: 1_000, + mark_statuses_as_sensitive: 1_250, + delete_statuses: 1_500, + sensitive: 2_000, + silence: 3_000, + suspend: 4_000, }, _suffix: :action belongs_to :account, inverse_of: :account_warnings @@ -33,7 +34,7 @@ class AccountWarning < ApplicationRecord 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)) } + scope :recent, -> { where('account_warnings.created_at >= ?', 3.months.ago) } def statuses Status.with_discarded.where(id: status_ids || []) diff --git a/app/models/admin/status_batch_action.rb b/app/models/admin/status_batch_action.rb index 40f60f379..4d91b9805 100644 --- a/app/models/admin/status_batch_action.rb +++ b/app/models/admin/status_batch_action.rb @@ -30,6 +30,8 @@ class Admin::StatusBatchAction case type when 'delete' handle_delete! + when 'mark_as_sensitive' + handle_mark_as_sensitive! when 'report' handle_report! when 'remove_from_report' @@ -65,6 +67,38 @@ class Admin::StatusBatchAction RemovalWorker.push_bulk(status_ids) { |status_id| [status_id, { 'preserve' => target_account.local?, 'immediate' => !target_account.local? }] } end + def handle_mark_as_sensitive! + # Can't use a transaction here because UpdateStatusService queues + # Sidekiq jobs + statuses.includes(:media_attachments, :preview_cards).find_each do |status| + next unless status.with_media? || status.with_preview_card? + + authorize(status, :update?) + + if target_account.local? + UpdateStatusService.new.call(status, current_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 + + @warning = target_account.strikes.create!( + action: :mark_statuses_as_sensitive, + account: current_account, + report: report, + status_ids: status_ids + ) + end + + UserMailer.warning(target_account.user, @warning).deliver_later! if warnable? + end + def handle_report! @report = Report.new(report_params) unless with_report? @report.status_ids = (@report.status_ids + status_ids.map(&:to_i)).uniq diff --git a/app/models/status.rb b/app/models/status.rb index 2fe4eedb5..06141f410 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -238,6 +238,10 @@ class Status < ApplicationRecord media_attachments.any? end + def with_preview_card? + preview_cards.any? + end + def non_sensitive_with_media? !sensitive? && with_media? end |