diff options
author | Felipe Artur <felipefac@gmail.com> | 2016-03-31 16:11:49 -0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2016-04-05 11:53:39 -0300 |
commit | 1ba9a91c6d3b98e1825e173fe281ba065d35890c (patch) | |
tree | c9c7abff27c62679bffeb45dc873e7aad7989aee /app/controllers/groups | |
parent | 59466a478038210113b21ffa40530799dcdeed40 (diff) | |
download | gitlab-ce-1ba9a91c6d3b98e1825e173fe281ba065d35890c.tar.gz |
Fix problem when creating milestones in groups without projects
Diffstat (limited to 'app/controllers/groups')
-rw-r--r-- | app/controllers/groups/milestones_controller.rb | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/app/controllers/groups/milestones_controller.rb b/app/controllers/groups/milestones_controller.rb index b23c3022fb5..2c05d9e0fe1 100644 --- a/app/controllers/groups/milestones_controller.rb +++ b/app/controllers/groups/milestones_controller.rb @@ -18,14 +18,14 @@ class Groups::MilestonesController < Groups::ApplicationController end def create - project_ids = params[:milestone][:project_ids] + project_ids = params[:milestone][:project_ids].reject(&:blank?) title = milestone_params[:title] - @projects.where(id: project_ids).each do |project| - Milestones::CreateService.new(project, current_user, milestone_params).execute + if project_ids.present? + create_milestones(project_ids, title) + else + render_new_with_error("Select a project(s).") end - - redirect_to milestone_path(title) end def show @@ -41,6 +41,24 @@ class Groups::MilestonesController < Groups::ApplicationController private + def create_milestones(project_ids, title) + begin + @projects.where(id: project_ids).each do |project| + ActiveRecord::Base.transaction { Milestones::CreateService.new(project, current_user, milestone_params).execute } + end + + redirect_to milestone_path(title) + rescue => e + render_new_with_error("Error creating milestones: #{e.message}") + end + end + + def render_new_with_error(error) + @milestone = Milestone.new(milestone_params) + flash[:alert] = error + render :new + end + def authorize_admin_milestones! return render_404 unless can?(current_user, :admin_milestones, group) end |