2018-09-23 15:44:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-30 13:06:18 -04:00
|
|
|
class Groups::MilestonesController < Groups::ApplicationController
|
2017-04-25 10:25:20 -04:00
|
|
|
include MilestoneActions
|
|
|
|
|
2018-08-06 15:02:52 -04:00
|
|
|
before_action :milestone, only: [:edit, :show, :update, :merge_requests, :participants, :labels, :destroy]
|
|
|
|
before_action :authorize_admin_milestones!, only: [:edit, :new, :create, :update, :destroy]
|
2020-04-21 11:21:10 -04:00
|
|
|
before_action do
|
|
|
|
push_frontend_feature_flag(:burnup_charts)
|
|
|
|
end
|
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
|
2019-09-13 06:48:06 -04:00
|
|
|
@milestone_states = Milestone.states_count(group_projects_with_access, [group])
|
2016-03-23 04:09:58 -04:00
|
|
|
@milestones = Kaminari.paginate_array(milestones).page(params[:page])
|
|
|
|
end
|
2017-06-22 19:31:25 -04:00
|
|
|
format.json do
|
2018-04-04 17:43:33 -04:00
|
|
|
render json: milestones.map { |m| m.for_display.slice(:id, :title, :name) }
|
2017-06-22 19:31:25 -04:00
|
|
|
end
|
2016-03-23 04:09:58 -04:00
|
|
|
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
|
2017-07-07 11:08:49 -04:00
|
|
|
@milestone = Milestones::CreateService.new(group, current_user, milestone_params).execute
|
2015-11-13 10:07:27 -05:00
|
|
|
|
2017-07-07 11:08:49 -04:00
|
|
|
if @milestone.persisted?
|
|
|
|
redirect_to milestone_path
|
2016-03-31 15:11:49 -04:00
|
|
|
else
|
2017-07-07 11:08:49 -04:00
|
|
|
render "new"
|
2015-11-13 10:07:27 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-26 08:19:29 -04:00
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
2017-07-07 11:08:49 -04:00
|
|
|
def edit
|
2017-08-24 12:31:20 -04:00
|
|
|
render_404 if @milestone.legacy_group_milestone?
|
2014-06-26 07:32:35 -04:00
|
|
|
end
|
|
|
|
|
2017-07-07 11:08:49 -04:00
|
|
|
def update
|
|
|
|
# Keep this compatible with legacy group milestones where we have to update
|
|
|
|
# all projects milestones states at once.
|
2018-12-20 06:14:33 -05:00
|
|
|
milestones, update_params = get_milestones_for_update
|
2017-07-07 11:08:49 -04:00
|
|
|
milestones.each do |milestone|
|
2019-10-17 08:07:33 -04:00
|
|
|
Milestones::UpdateService.new(milestone.resource_parent, current_user, update_params).execute(milestone)
|
2016-04-04 16:04:35 -04:00
|
|
|
end
|
|
|
|
|
2017-07-07 11:08:49 -04:00
|
|
|
redirect_to milestone_path
|
2016-03-31 15:11:49 -04:00
|
|
|
end
|
|
|
|
|
2018-08-06 15:02:52 -04:00
|
|
|
def destroy
|
|
|
|
return render_404 if @milestone.legacy_group_milestone?
|
|
|
|
|
|
|
|
Milestones::DestroyService.new(group, current_user).execute(@milestone)
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to group_milestones_path(group), status: :see_other }
|
|
|
|
format.js { head :ok }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-07 11:08:49 -04:00
|
|
|
private
|
2016-03-31 15:11:49 -04:00
|
|
|
|
2018-12-20 06:14:33 -05:00
|
|
|
def get_milestones_for_update
|
|
|
|
if @milestone.legacy_group_milestone?
|
|
|
|
[@milestone.milestones, legacy_milestone_params]
|
|
|
|
else
|
|
|
|
[[@milestone], milestone_params]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
def authorize_admin_milestones!
|
2018-08-06 15:02:52 -04:00
|
|
|
return render_404 unless can?(current_user, :admin_milestone, 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
|
|
|
|
2018-12-20 06:14:33 -05:00
|
|
|
def legacy_milestone_params
|
|
|
|
params.require(:milestone).permit(:state_event)
|
|
|
|
end
|
|
|
|
|
2017-07-07 11:08:49 -04:00
|
|
|
def milestone_path
|
2017-08-24 12:31:20 -04:00
|
|
|
if @milestone.legacy_group_milestone?
|
2017-07-07 11:08:49 -04:00
|
|
|
group_milestone_path(group, @milestone.safe_title, title: @milestone.title)
|
|
|
|
else
|
|
|
|
group_milestone_path(group, @milestone.iid)
|
|
|
|
end
|
2014-06-30 05:38:03 -04:00
|
|
|
end
|
2017-01-06 07:47:18 -05:00
|
|
|
|
|
|
|
def milestones
|
2017-07-07 11:08:49 -04:00
|
|
|
milestones = MilestonesFinder.new(search_params).execute
|
|
|
|
|
2017-11-06 12:51:24 -05:00
|
|
|
@sort = params[:sort] || 'due_date_asc'
|
|
|
|
MilestoneArray.sort(milestones + legacy_milestones, @sort)
|
2017-01-06 07:47:18 -05:00
|
|
|
end
|
|
|
|
|
2018-05-21 23:10:47 -04:00
|
|
|
def legacy_milestones
|
2019-09-13 06:48:06 -04:00
|
|
|
GroupMilestone.build_collection(group, group_projects_with_access, params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def group_projects_with_access
|
2020-01-29 04:08:49 -05:00
|
|
|
group_projects_with_subgroups.with_issues_or_mrs_available_for_user(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def group_ids(include_ancestors: false)
|
|
|
|
if include_ancestors
|
|
|
|
group.self_and_hierarchy.public_or_visible_to_user(current_user).select(:id)
|
|
|
|
else
|
|
|
|
group.self_and_descendants.public_or_visible_to_user(current_user).select(:id)
|
|
|
|
end
|
2018-05-21 23:10:47 -04:00
|
|
|
end
|
|
|
|
|
2017-01-06 07:47:18 -05:00
|
|
|
def milestone
|
2017-07-07 11:08:49 -04:00
|
|
|
@milestone =
|
|
|
|
if params[:title]
|
2019-09-13 06:48:06 -04:00
|
|
|
GroupMilestone.build(group, group_projects_with_access, params[:title])
|
2017-07-07 11:08:49 -04:00
|
|
|
else
|
|
|
|
group.milestones.find_by_iid(params[:id])
|
|
|
|
end
|
|
|
|
|
2017-01-06 07:47:18 -05:00
|
|
|
render_404 unless @milestone
|
|
|
|
end
|
2018-01-05 12:53:31 -05:00
|
|
|
|
|
|
|
def search_params
|
2020-01-29 04:08:49 -05:00
|
|
|
groups = request.format.json? ? group_ids(include_ancestors: true) : group_ids
|
2020-01-16 07:08:32 -05:00
|
|
|
|
|
|
|
params.permit(:state, :search_title).merge(group_ids: groups)
|
2018-01-05 12:53:31 -05:00
|
|
|
end
|
2014-06-25 05:15:27 -04:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
Groups::MilestonesController.prepend_if_ee('EE::Groups::MilestonesController')
|