Feature: Bulk Issues update
This commit is contained in:
parent
d63706d72c
commit
00b280c3f9
10 changed files with 144 additions and 32 deletions
|
@ -4,5 +4,17 @@ class BaseContext
|
|||
def initialize(project, user, params)
|
||||
@project, @current_user, @params = project, user, params.dup
|
||||
end
|
||||
|
||||
def abilities
|
||||
@abilities ||= begin
|
||||
abilities = Six.new
|
||||
abilities << Ability
|
||||
abilities
|
||||
end
|
||||
end
|
||||
|
||||
def can?(object, action, subject)
|
||||
abilities.allowed?(object, action, subject)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
24
app/contexts/issues_bulk_update_context.rb
Normal file
24
app/contexts/issues_bulk_update_context.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
class IssuesBulkUpdateContext < 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]
|
||||
|
||||
opts = {}
|
||||
opts[:milestone_id] = milestone_id if milestone_id.present?
|
||||
opts[:assignee_id] = assignee_id if assignee_id.present?
|
||||
opts[:closed] = (status == "closed") if status.present?
|
||||
|
||||
issues = Issue.where(:id => issues_ids).all
|
||||
issues = issues.select { |issue| can?(current_user, :modify_issue, issue) }
|
||||
issues.each { |issue| issue.update_attributes(opts) }
|
||||
{
|
||||
:count => issues.count,
|
||||
:success => !issues.count.zero?
|
||||
}
|
||||
end
|
||||
end
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue