Commit d32c19b2 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fix bulk issue status update

parent 72d5a566
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]
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)
if status.present?
if status == 'closed'
issue.close
else
issue.reopen
end
end
end
{
count: issues.count,
success: !issues.count.zero?
}
end
end
end
module Issues
class ListContext < BaseContext
include IssuesHelper
attr_accessor :issues
def execute
@issues = case params[:status]
when issues_filter[:all] then @project.issues
when issues_filter[:closed] then @project.issues.closed
when issues_filter[:to_me] then @project.issues.assigned(current_user)
when issues_filter[:by_me] then @project.issues.authored(current_user)
else @project.issues.opened
end
@issues = @issues.tagged_with(params[:label_name]) if params[:label_name].present?
@issues = @issues.includes(:author, :project)
# Filter by specific assignee_id (or lack thereof)?
if params[:assignee_id].present?
@issues = @issues.where(assignee_id: (params[:assignee_id] == '0' ? nil : params[:assignee_id]))
end
# Filter by specific milestone_id (or lack thereof)?
if params[:milestone_id].present?
@issues = @issues.where(milestone_id: (params[:milestone_id] == '0' ? nil : params[:milestone_id]))
end
@issues
end
end
end
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
class IssuesListContext < BaseContext
include IssuesHelper
attr_accessor :issues
def execute
@issues = case params[:status]
when issues_filter[:all] then @project.issues
when issues_filter[:closed] then @project.issues.closed
when issues_filter[:to_me] then @project.issues.assigned(current_user)
when issues_filter[:by_me] then @project.issues.authored(current_user)
else @project.issues.opened
end
@issues = @issues.tagged_with(params[:label_name]) if params[:label_name].present?
@issues = @issues.includes(:author, :project)
# Filter by specific assignee_id (or lack thereof)?
if params[:assignee_id].present?
@issues = @issues.where(assignee_id: (params[:assignee_id] == '0' ? nil : params[:assignee_id]))
end
# Filter by specific milestone_id (or lack thereof)?
if params[:milestone_id].present?
@issues = @issues.where(milestone_id: (params[:milestone_id] == '0' ? nil : params[:milestone_id]))
end
@issues
end
end
......@@ -86,7 +86,7 @@ class IssuesController < ProjectResourceController
end
def bulk_update
result = IssuesBulkUpdateContext.new(project, current_user, params).execute
result = Issues::BulkUpdateContext.new(project, current_user, params).execute
redirect_to :back, notice: "#{result[:count]} issues updated"
end
......@@ -109,6 +109,6 @@ class IssuesController < ProjectResourceController
end
def issues_filtered
@issues = IssuesListContext.new(project, current_user, params).execute
@issues = Issues::ListContext.new(project, current_user, params).execute
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment