mastodon/app/models/admin/collection_batch_action.rb
Pia B. 07a05e1edf
Some checks failed
Check i18n / check-i18n (push) Waiting to run
Chromatic / Check for relevant changes (push) Waiting to run
Chromatic / Run Chromatic (push) Blocked by required conditions
CodeQL / Analyze (actions) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Crowdin / Upload translations / upload-translations (push) Waiting to run
Check formatting / lint (push) Waiting to run
CSS Linting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / test (3.4) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.4) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Blocked by required conditions
Haml Linting / lint (push) Has been cancelled
Ruby Linting / lint (push) Has been cancelled
Historical data migration test / test (14-alpine) (push) Has been cancelled
Historical data migration test / test (15-alpine) (push) Has been cancelled
Historical data migration test / test (16-alpine) (push) Has been cancelled
Historical data migration test / test (17-alpine) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (3.4, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Has been cancelled
Add batch remove for collections in reports (#39020)
2026-05-18 14:53:40 +00:00

55 lines
1.1 KiB
Ruby

# frozen_string_literal: true
class Admin::CollectionBatchAction < Admin::BaseAction
TYPES = %w(
report
remove_from_report
).freeze
attr_accessor :collection_ids
private
def process_action!
return unless collection_ids
case type
when 'report'
add_to_report!
when 'remove_from_report'
handle_remove_from_report!
end
end
def add_to_report!
@report = Report.new(report_params) unless with_report?
@report.collections = (@report.collections + selected_collections).uniq
@report.save!
@report_id = @report.id
end
def handle_remove_from_report!
return unless with_report?
@report.collections = (@report.collections - selected_collections)
@report.save!
end
def selected_collections
@report.target_account.collections.where(id: collection_ids)
end
def report_params
{ account: current_account, target_account: target_account }
end
def collection
@collection ||= Collection.where(id: collection_ids.first)
end
def target_account
@target_account ||= collection.first.account
end
end