mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 15:28:37 +08:00
Server side implementation for bulk editing categories
This commit is contained in:
@ -6,9 +6,34 @@ class TopicsBulkAction
|
||||
@operation = operation
|
||||
end
|
||||
|
||||
def perform!
|
||||
[]
|
||||
def self.operations
|
||||
%w(change_category)
|
||||
end
|
||||
|
||||
def perform!
|
||||
raise Discourse::InvalidParameters.new(:operation) unless TopicsBulkAction.operations.include?(@operation[:type])
|
||||
send(@operation[:type])
|
||||
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])
|
||||
end
|
||||
end
|
||||
changed_ids
|
||||
end
|
||||
|
||||
def guardian
|
||||
@guardian ||= Guardian.new(@user)
|
||||
end
|
||||
|
||||
def topics
|
||||
@topics ||= Topic.where(id: @topic_ids)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user