2013-05-14 07:34:34 -04:00
|
|
|
module Issues
|
|
|
|
class BulkUpdateContext < BaseContext
|
|
|
|
def execute
|
|
|
|
update_data = params[:update]
|
|
|
|
|
|
|
|
issues_ids = update_data[:issues_ids].split(",")
|
|
|
|
milestone_id = update_data[:milestone_id]
|
|
|
|
assignee_id = update_data[:assignee_id]
|
|
|
|
status = update_data[:status]
|
|
|
|
|
2013-05-16 06:32:16 -04:00
|
|
|
new_state = nil
|
|
|
|
|
|
|
|
if status.present?
|
|
|
|
if status == 'closed'
|
|
|
|
new_state = :close
|
|
|
|
else
|
|
|
|
new_state = :reopen
|
|
|
|
end
|
2013-05-15 10:10:39 -04:00
|
|
|
end
|
|
|
|
|
2013-05-14 07:34:34 -04:00
|
|
|
opts = {}
|
|
|
|
opts[:milestone_id] = milestone_id if milestone_id.present?
|
|
|
|
opts[:assignee_id] = assignee_id if assignee_id.present?
|
|
|
|
|
|
|
|
issues = Issue.where(id: issues_ids).all
|
|
|
|
issues = issues.select { |issue| can?(current_user, :modify_issue, issue) }
|
|
|
|
|
|
|
|
issues.each do |issue|
|
|
|
|
issue.update_attributes(opts)
|
2013-05-16 06:32:16 -04:00
|
|
|
issue.send new_state if new_state
|
2013-05-14 07:34:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
{
|
|
|
|
count: issues.count,
|
|
|
|
success: !issues.count.zero?
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|