2015-09-11 14:41:01 +05:30
|
|
|
class Groups::MilestonesController < Groups::ApplicationController
|
2017-08-17 22:00:37 +05:30
|
|
|
include MilestoneActions
|
2015-11-26 14:37:03 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
before_action :group_projects
|
2017-09-10 17:25:29 +05:30
|
|
|
before_action :milestone, only: [:edit, :show, :update, :merge_requests, :participants, :labels]
|
|
|
|
before_action :authorize_admin_milestones!, only: [:edit, :new, :create, :update]
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
def index
|
2016-06-02 11:05:42 +05:30
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2017-09-10 17:25:29 +05:30
|
|
|
@milestone_states = GlobalMilestone.states_count(group_projects, group)
|
2016-06-02 11:05:42 +05:30
|
|
|
@milestones = Kaminari.paginate_array(milestones).page(params[:page])
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
format.json do
|
2018-05-09 12:01:36 +05:30
|
|
|
render json: milestones.map { |m| m.for_display.slice(:id, :title, :name) }
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2015-11-26 14:37:03 +05:30
|
|
|
def new
|
|
|
|
@milestone = Milestone.new
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2015-11-26 14:37:03 +05:30
|
|
|
def create
|
2017-09-10 17:25:29 +05:30
|
|
|
@milestone = Milestones::CreateService.new(group, current_user, milestone_params).execute
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
if @milestone.persisted?
|
|
|
|
redirect_to milestone_path
|
2016-06-02 11:05:42 +05:30
|
|
|
else
|
2017-09-10 17:25:29 +05:30
|
|
|
render "new"
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def edit
|
2018-03-17 18:26:18 +05:30
|
|
|
render_404 if @milestone.legacy_group_milestone?
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def update
|
|
|
|
# Keep this compatible with legacy group milestones where we have to update
|
|
|
|
# all projects milestones states at once.
|
2018-03-17 18:26:18 +05:30
|
|
|
if @milestone.legacy_group_milestone?
|
2017-09-10 17:25:29 +05:30
|
|
|
update_params = milestone_params.select { |key| key == "state_event" }
|
|
|
|
milestones = @milestone.milestones
|
|
|
|
else
|
|
|
|
update_params = milestone_params
|
|
|
|
milestones = [@milestone]
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
milestones.each do |milestone|
|
|
|
|
Milestones::UpdateService.new(milestone.parent, current_user, update_params).execute(milestone)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
redirect_to milestone_path
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
private
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
def authorize_admin_milestones!
|
2015-11-26 14:37:03 +05:30
|
|
|
return render_404 unless can?(current_user, :admin_milestones, group)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2015-11-26 14:37:03 +05:30
|
|
|
def milestone_params
|
2017-08-17 22:00:37 +05:30
|
|
|
params.require(:milestone).permit(:title, :description, :start_date, :due_date, :state_event)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def milestone_path
|
2018-03-17 18:26:18 +05:30
|
|
|
if @milestone.legacy_group_milestone?
|
2017-09-10 17:25:29 +05:30
|
|
|
group_milestone_path(group, @milestone.safe_title, title: @milestone.title)
|
|
|
|
else
|
|
|
|
group_milestone_path(group, @milestone.iid)
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
def milestones
|
2017-09-10 17:25:29 +05:30
|
|
|
milestones = MilestonesFinder.new(search_params).execute
|
|
|
|
legacy_milestones = GroupMilestone.build_collection(group, group_projects, params)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
@sort = params[:sort] || 'due_date_asc'
|
|
|
|
MilestoneArray.sort(milestones + legacy_milestones, @sort)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def milestone
|
2017-09-10 17:25:29 +05:30
|
|
|
@milestone =
|
|
|
|
if params[:title]
|
|
|
|
GroupMilestone.build(group, group_projects, params[:title])
|
|
|
|
else
|
|
|
|
group.milestones.find_by_iid(params[:id])
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
render_404 unless @milestone
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
def search_params
|
|
|
|
params.permit(:state).merge(group_ids: group.id)
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|