2018-09-26 03:45:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-06-23 16:47:22 +00:00
|
|
|
class Projects::MilestonesController < Projects::ApplicationController
|
2018-06-01 07:52:55 +00:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
2017-04-25 14:25:20 +00:00
|
|
|
include MilestoneActions
|
|
|
|
|
2017-06-20 11:13:04 +00:00
|
|
|
before_action :check_issuables_available!
|
2020-09-18 18:10:26 +00:00
|
|
|
before_action :milestone, only: [:edit, :update, :destroy, :show, :issues, :merge_requests, :participants, :labels, :promote]
|
2012-04-08 21:28:58 +00:00
|
|
|
|
|
|
|
# Allow read any milestone
|
2015-04-16 12:03:37 +00:00
|
|
|
before_action :authorize_read_milestone!
|
2012-04-08 21:28:58 +00:00
|
|
|
|
|
|
|
# Allow admin milestone
|
2020-09-18 18:10:26 +00:00
|
|
|
before_action :authorize_admin_milestone!, except: [:index, :show, :issues, :merge_requests, :participants, :labels]
|
2018-11-28 18:38:24 +00:00
|
|
|
|
|
|
|
# Allow to promote milestone
|
|
|
|
before_action :authorize_promote_milestone!, only: :promote
|
2012-04-08 21:28:58 +00:00
|
|
|
|
|
|
|
respond_to :html
|
|
|
|
|
2020-10-08 18:08:32 +00:00
|
|
|
feature_category :issue_tracking
|
|
|
|
|
2012-04-08 21:28:58 +00:00
|
|
|
def index
|
2017-03-24 00:39:12 +00:00
|
|
|
@sort = params[:sort] || 'due_date_asc'
|
2018-04-04 09:19:47 +00:00
|
|
|
@milestones = milestones.sort_by_attribute(@sort)
|
2017-03-24 00:39:12 +00:00
|
|
|
|
2016-03-16 18:08:35 +00:00
|
|
|
respond_to do |format|
|
2016-03-17 09:09:06 +00:00
|
|
|
format.html do
|
2017-07-07 15:08:49 +00:00
|
|
|
# We need to show group milestones in the JSON response
|
|
|
|
# so that people can filter by and assign group milestones,
|
|
|
|
# but we don't need to show them on the project milestones page itself.
|
|
|
|
@milestones = @milestones.for_projects
|
2016-03-19 21:37:54 +00:00
|
|
|
@milestones = @milestones.page(params[:page])
|
2016-03-17 09:09:06 +00:00
|
|
|
end
|
2016-03-16 18:08:35 +00:00
|
|
|
format.json do
|
2020-05-28 12:08:10 +00:00
|
|
|
render json: @milestones.to_json(only: [:id, :title], methods: :name)
|
2016-03-16 18:08:35 +00:00
|
|
|
end
|
|
|
|
end
|
2012-04-08 21:28:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2021-05-06 12:10:38 +00:00
|
|
|
@noteable = @milestone = @project.milestones.new
|
2012-04-08 21:28:58 +00:00
|
|
|
respond_with(@milestone)
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
respond_with(@milestone)
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2017-06-17 06:40:12 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
end
|
2012-04-08 21:28:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2014-06-26 15:51:11 +00:00
|
|
|
@milestone = Milestones::CreateService.new(project, current_user, milestone_params).execute
|
2012-04-08 21:28:58 +00:00
|
|
|
|
2017-07-07 15:08:49 +00:00
|
|
|
if @milestone.valid?
|
2017-06-29 17:06:35 +00:00
|
|
|
redirect_to project_milestone_path(@project, @milestone)
|
2012-04-08 21:28:58 +00:00
|
|
|
else
|
|
|
|
render "new"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2014-06-26 15:51:11 +00:00
|
|
|
@milestone = Milestones::UpdateService.new(project, current_user, milestone_params).execute(milestone)
|
2012-04-08 21:28:58 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
2012-10-09 19:09:46 +00:00
|
|
|
format.html do
|
2012-04-08 21:28:58 +00:00
|
|
|
if @milestone.valid?
|
2017-06-29 17:06:35 +00:00
|
|
|
redirect_to project_milestone_path(@project, @milestone)
|
2012-04-08 21:28:58 +00:00
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-31 15:03:52 +00:00
|
|
|
def promote
|
2018-03-13 16:36:13 +00:00
|
|
|
promoted_milestone = Milestones::PromoteService.new(project, current_user).execute(milestone)
|
2018-11-28 18:38:24 +00:00
|
|
|
flash[:notice] = flash_notice_for(promoted_milestone, project_group)
|
2018-07-16 10:49:01 +00:00
|
|
|
|
2018-03-01 22:09:25 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
redirect_to project_milestones_path(project)
|
|
|
|
end
|
|
|
|
format.json do
|
|
|
|
render json: { url: project_milestones_path(project) }
|
|
|
|
end
|
|
|
|
end
|
2017-10-31 15:03:52 +00:00
|
|
|
rescue Milestones::PromoteService::PromoteMilestoneError => error
|
|
|
|
redirect_to milestone, alert: error.message
|
|
|
|
end
|
|
|
|
|
2018-07-16 10:49:01 +00:00
|
|
|
def flash_notice_for(milestone, group)
|
2018-09-26 03:45:43 +00:00
|
|
|
''.html_safe + "#{milestone.title} promoted to " + view_context.link_to('<u>group milestone</u>'.html_safe, group_milestone_path(group, milestone.iid)) + '.'
|
2018-07-16 10:49:01 +00:00
|
|
|
end
|
|
|
|
|
2012-04-08 21:28:58 +00:00
|
|
|
def destroy
|
2015-07-14 22:20:38 +00:00
|
|
|
return access_denied! unless can?(current_user, :admin_milestone, @project)
|
|
|
|
|
2015-08-31 04:51:34 +00:00
|
|
|
Milestones::DestroyService.new(project, current_user).execute(milestone)
|
2012-04-08 21:28:58 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
2018-07-02 10:43:06 +00:00
|
|
|
format.html { redirect_to namespace_project_milestones_path, status: :see_other }
|
2016-03-16 01:16:25 +00:00
|
|
|
format.js { head :ok }
|
2012-04-08 21:28:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2018-11-28 18:38:24 +00:00
|
|
|
def project_group
|
|
|
|
strong_memoize(:project_group) do
|
|
|
|
project.group
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-07 15:08:49 +00:00
|
|
|
def milestones
|
2018-06-01 07:52:55 +00:00
|
|
|
strong_memoize(:milestones) do
|
2017-07-07 15:08:49 +00:00
|
|
|
MilestonesFinder.new(search_params).execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2012-04-08 21:28:58 +00:00
|
|
|
def milestone
|
2021-05-06 12:10:38 +00:00
|
|
|
@noteable = @milestone ||= @project.milestones.find_by!(iid: params[:id])
|
2012-04-08 21:28:58 +00:00
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2012-04-08 21:28:58 +00:00
|
|
|
|
|
|
|
def authorize_admin_milestone!
|
|
|
|
return render_404 unless can?(current_user, :admin_milestone, @project)
|
|
|
|
end
|
|
|
|
|
2018-11-28 18:38:24 +00:00
|
|
|
def authorize_promote_milestone!
|
|
|
|
return render_404 unless can?(current_user, :admin_milestone, project_group)
|
|
|
|
end
|
|
|
|
|
2014-06-26 15:51:11 +00:00
|
|
|
def milestone_params
|
2016-11-15 17:48:30 +00:00
|
|
|
params.require(:milestone).permit(:title, :description, :start_date, :due_date, :state_event)
|
2014-06-26 15:51:11 +00:00
|
|
|
end
|
2018-01-05 17:53:31 +00:00
|
|
|
|
|
|
|
def search_params
|
2018-11-28 18:38:24 +00:00
|
|
|
if request.format.json? && project_group && can?(current_user, :read_group, project_group)
|
2019-01-11 14:58:18 +00:00
|
|
|
groups = project_group.self_and_ancestors.select(:id)
|
2018-01-05 17:53:31 +00:00
|
|
|
end
|
|
|
|
|
2019-01-17 14:35:23 +00:00
|
|
|
params.permit(:state, :search_title).merge(project_ids: @project.id, group_ids: groups)
|
2018-01-05 17:53:31 +00:00
|
|
|
end
|
2012-04-08 21:28:58 +00:00
|
|
|
end
|