mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Bulk close operation
This commit is contained in:
@@ -4,27 +4,36 @@ class TopicsBulkAction
|
||||
@user = user
|
||||
@topic_ids = topic_ids
|
||||
@operation = operation
|
||||
@changed_ids = []
|
||||
end
|
||||
|
||||
def self.operations
|
||||
%w(change_category)
|
||||
%w(change_category close)
|
||||
end
|
||||
|
||||
def perform!
|
||||
raise Discourse::InvalidParameters.new(:operation) unless TopicsBulkAction.operations.include?(@operation[:type])
|
||||
send(@operation[:type])
|
||||
@changed_ids
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def change_category
|
||||
changed_ids = []
|
||||
topics.each do |t|
|
||||
if guardian.can_edit?(t)
|
||||
changed_ids << t.id if t.change_category(@operation[:category_name])
|
||||
@changed_ids << t.id if t.change_category(@operation[:category_name])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def close
|
||||
topics.each do |t|
|
||||
if guardian.can_moderate?(t)
|
||||
t.update_status('closed', true, @user)
|
||||
@changed_ids << t.id
|
||||
end
|
||||
end
|
||||
changed_ids
|
||||
end
|
||||
|
||||
def guardian
|
||||
|
||||
Reference in New Issue
Block a user