2015-04-30 13:06:18 -04:00
|
|
|
class Groups::MilestonesController < Groups::ApplicationController
|
2016-03-20 16:03:53 -04:00
|
|
|
before_action :group_projects
|
2015-11-13 13:20:48 -05:00
|
|
|
before_action :milestone, only: [:show, :update]
|
2016-03-20 16:03:53 -04:00
|
|
|
before_action :authorize_admin_milestones!, only: [:new, :create, :update]
|
2015-11-13 10:07:27 -05:00
|
|
|
|
2015-11-13 13:20:48 -05:00
|
|
|
def index
|
2016-03-23 04:09:58 -04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
@milestones = Kaminari.paginate_array(milestones).page(params[:page])
|
|
|
|
end
|
|
|
|
end
|
2014-06-25 05:15:27 -04:00
|
|
|
end
|
2014-06-25 10:19:03 -04:00
|
|
|
|
2015-11-13 10:07:27 -05:00
|
|
|
def new
|
2015-11-13 13:20:48 -05:00
|
|
|
@milestone = Milestone.new
|
2015-11-13 10:07:27 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2016-03-31 15:11:49 -04:00
|
|
|
project_ids = params[:milestone][:project_ids].reject(&:blank?)
|
2015-11-13 10:07:27 -05:00
|
|
|
title = milestone_params[:title]
|
|
|
|
|
2016-04-05 10:51:19 -04:00
|
|
|
if create_milestones(project_ids)
|
2016-04-01 14:50:17 -04:00
|
|
|
redirect_to milestone_path(title)
|
2016-03-31 15:11:49 -04:00
|
|
|
else
|
2016-04-04 16:04:35 -04:00
|
|
|
render_new_with_error(project_ids.empty?)
|
2015-11-13 10:07:27 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-26 08:19:29 -04:00
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
2014-06-26 07:32:35 -04:00
|
|
|
def update
|
2015-11-13 13:20:48 -05:00
|
|
|
@milestone.milestones.each do |milestone|
|
|
|
|
Milestones::UpdateService.new(milestone.project, current_user, milestone_params).execute(milestone)
|
2014-06-26 07:32:35 -04:00
|
|
|
end
|
|
|
|
|
2015-11-13 13:20:48 -05:00
|
|
|
redirect_back_or_default(default: milestone_path(@milestone.title))
|
2014-06-26 07:32:35 -04:00
|
|
|
end
|
|
|
|
|
2014-06-26 05:58:40 -04:00
|
|
|
private
|
|
|
|
|
2016-04-05 10:51:19 -04:00
|
|
|
def create_milestones(project_ids)
|
2016-04-04 16:04:35 -04:00
|
|
|
return false unless project_ids.present?
|
2016-04-01 14:50:17 -04:00
|
|
|
|
2016-04-04 16:04:35 -04:00
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
@projects.where(id: project_ids).each do |project|
|
|
|
|
Milestones::CreateService.new(project, current_user, milestone_params).execute
|
2016-03-31 15:11:49 -04:00
|
|
|
end
|
2016-04-04 16:04:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
true
|
2016-04-05 10:51:19 -04:00
|
|
|
rescue ActiveRecord::ActiveRecordError => e
|
2016-04-04 16:04:35 -04:00
|
|
|
flash.now[:alert] = "An error occurred while creating the milestone: #{e.message}"
|
|
|
|
false
|
2016-03-31 15:11:49 -04:00
|
|
|
end
|
|
|
|
|
2016-04-04 16:04:35 -04:00
|
|
|
def render_new_with_error(empty_project_ids)
|
2016-03-31 15:11:49 -04:00
|
|
|
@milestone = Milestone.new(milestone_params)
|
2016-11-05 03:50:07 -04:00
|
|
|
@milestone.errors.add(:base, "Please select at least one project.") if empty_project_ids
|
2016-03-31 15:11:49 -04:00
|
|
|
render :new
|
|
|
|
end
|
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
def authorize_admin_milestones!
|
2015-11-16 10:14:19 -05:00
|
|
|
return render_404 unless can?(current_user, :admin_milestones, group)
|
2014-06-26 08:19:29 -04:00
|
|
|
end
|
|
|
|
|
2015-11-13 13:20:48 -05:00
|
|
|
def milestone_params
|
2016-11-15 12:48:30 -05:00
|
|
|
params.require(:milestone).permit(:title, :description, :start_date, :due_date, :state_event)
|
2014-06-26 05:58:40 -04:00
|
|
|
end
|
2014-06-30 05:38:03 -04:00
|
|
|
|
2015-11-13 13:20:48 -05:00
|
|
|
def milestone_path(title)
|
Fix Error 500 when creating global milestones with Unicode characters
Two issues:
1. The constraints in the resources were incorrect. Here's what it was before:
```
group_milestone GET /groups/:group_id/milestones/:id(.:format) groups/milestones#show {:id=>/[a-zA-Z.0-9_\-]+(?<!\.atom)/, :group_id=>/[a-zA-Z.0-9_\-]+(?<!\.atom)/}
```
In this case, id is actually the title of the milestone, which can be anything at the moment.
After:
```
group_milestone GET /groups/:group_id/milestones/:id(.:format) groups/milestones#show {:id=>/[^\/]+/, :group_id=>/[a-zA-Z.0-9_\-]+(?<!\.atom)/}
```
2. `parameterize` would strip all Unicode characters, leaving a blank string. Rails would report something like:
ActionView::Template::Error (No route matches {:action=>"show", :controller=>"groups/milestones", :group_id=>#<Group id: 48, name: "ops-dev", path: "ops-dev", owner_id: nil, created_at: "2015-11-15 08:55:30", updated_at: "2015-12-02 06:23:26", type: "Group", description: "", avatar: "sha1.c71e73d51af1865c1bbbf6208e10044d46c9bb93.png", public: false>, :id=>"", :title=>"肯定不是中文的问题"} missing required keys: [:id]):
This change uses the babosa library to create a better slug, which surprisingly
isn't actually used by the global milestone controllers. Instead, they use the
title passed as a query string for some reason.
Closes https://github.com/gitlabhq/gitlabhq/issues/9881
Fix constraints
2015-12-04 02:33:52 -05:00
|
|
|
group_milestone_path(@group, title.to_slug.to_s, title: title)
|
2014-06-30 05:38:03 -04:00
|
|
|
end
|
2017-01-06 07:47:18 -05:00
|
|
|
|
|
|
|
def milestones
|
|
|
|
@milestones = GroupMilestone.build_collection(@group, @projects, params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def milestone
|
|
|
|
@milestone = GroupMilestone.build(@group, @projects, params[:title])
|
|
|
|
render_404 unless @milestone
|
|
|
|
end
|
2014-06-25 05:15:27 -04:00
|
|
|
end
|