Server side implementation for bulk editing categories

This commit is contained in:
Robin Ward
2014-01-30 11:43:01 -05:00
parent b315a5c28f
commit 7564d9a20c
3 changed files with 71 additions and 3 deletions

View File

@ -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