2013-06-23 12:47:22 -04:00
|
|
|
class Projects::MilestonesController < Projects::ApplicationController
|
2018-06-01 03:52:55 -04:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
2017-04-25 10:25:20 -04:00
|
|
|
include MilestoneActions
|
|
|
|
|
2017-06-20 07:13:04 -04:00
|
|
|
before_action :check_issuables_available!
|
2017-10-31 11:03:52 -04:00
|
|
|
before_action :milestone, only: [:edit, :update, :destroy, :show, :merge_requests, :participants, :labels, :promote]
|
2012-04-08 17:28:58 -04:00
|
|
|
|
|
|
|
# Allow read any milestone
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :authorize_read_milestone!
|
2012-04-08 17:28:58 -04:00
|
|
|
|
|
|
|
# Allow admin milestone
|
2017-10-31 11:03:52 -04:00
|
|
|
before_action :authorize_admin_milestone!, except: [:index, :show, :merge_requests, :participants, :labels, :promote]
|
2012-04-08 17:28:58 -04:00
|
|
|
|
|
|
|
respond_to :html
|
|
|
|
|
|
|
|
def index
|
2017-03-23 20:39:12 -04:00
|
|
|
@sort = params[:sort] || 'due_date_asc'
|
2018-04-04 05:19:47 -04:00
|
|
|
@milestones = milestones.sort_by_attribute(@sort)
|
2017-03-23 20:39:12 -04:00
|
|
|
|
2016-03-16 14:08:35 -04:00
|
|
|
respond_to do |format|
|
2016-03-17 05:09:06 -04:00
|
|
|
format.html do
|
2017-04-24 11:58:15 -04:00
|
|
|
@project_namespace = @project.namespace.becomes(Namespace)
|
2017-07-07 11:08:49 -04: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 17:37:54 -04:00
|
|
|
@milestones = @milestones.page(params[:page])
|
2016-03-17 05:09:06 -04:00
|
|
|
end
|
2016-03-16 14:08:35 -04:00
|
|
|
format.json do
|
2016-03-24 11:20:35 -04:00
|
|
|
render json: @milestones.to_json(methods: :name)
|
2016-03-16 14:08:35 -04:00
|
|
|
end
|
|
|
|
end
|
2012-04-08 17:28:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@milestone = @project.milestones.new
|
|
|
|
respond_with(@milestone)
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
respond_with(@milestone)
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2017-07-06 02:41:43 -04:00
|
|
|
@project_namespace = @project.namespace.becomes(Namespace)
|
2017-06-17 02:40:12 -04:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
end
|
2012-04-08 17:28:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2014-06-26 11:51:11 -04:00
|
|
|
@milestone = Milestones::CreateService.new(project, current_user, milestone_params).execute
|
2012-04-08 17:28:58 -04:00
|
|
|
|
2017-07-07 11:08:49 -04:00
|
|
|
if @milestone.valid?
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to project_milestone_path(@project, @milestone)
|
2012-04-08 17:28:58 -04:00
|
|
|
else
|
|
|
|
render "new"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2014-06-26 11:51:11 -04:00
|
|
|
@milestone = Milestones::UpdateService.new(project, current_user, milestone_params).execute(milestone)
|
2012-04-08 17:28:58 -04:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
2012-10-09 15:09:46 -04:00
|
|
|
format.html do
|
2012-04-08 17:28:58 -04:00
|
|
|
if @milestone.valid?
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to project_milestone_path(@project, @milestone)
|
2012-04-08 17:28:58 -04:00
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-31 11:03:52 -04:00
|
|
|
def promote
|
2018-03-13 12:36:13 -04:00
|
|
|
promoted_milestone = Milestones::PromoteService.new(project, current_user).execute(milestone)
|
2018-03-01 17:09:25 -05:00
|
|
|
|
2018-03-22 16:02:22 -04:00
|
|
|
flash[:notice] = "#{milestone.title} promoted to <a href=\"#{group_milestone_path(project.group, promoted_milestone.iid)}\">group milestone</a>.".html_safe
|
2018-03-01 17:09:25 -05: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 11:03:52 -04:00
|
|
|
rescue Milestones::PromoteService::PromoteMilestoneError => error
|
|
|
|
redirect_to milestone, alert: error.message
|
|
|
|
end
|
|
|
|
|
2012-04-08 17:28:58 -04:00
|
|
|
def destroy
|
2015-07-14 18:20:38 -04:00
|
|
|
return access_denied! unless can?(current_user, :admin_milestone, @project)
|
|
|
|
|
2015-08-31 00:51:34 -04:00
|
|
|
Milestones::DestroyService.new(project, current_user).execute(milestone)
|
2012-04-08 17:28:58 -04:00
|
|
|
|
|
|
|
respond_to do |format|
|
2018-01-04 08:15:27 -05:00
|
|
|
format.html { redirect_to namespace_project_milestones_path, status: 303 }
|
2016-03-15 21:16:25 -04:00
|
|
|
format.js { head :ok }
|
2012-04-08 17:28:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2017-07-07 11:08:49 -04:00
|
|
|
def milestones
|
2018-06-01 03:52:55 -04:00
|
|
|
strong_memoize(:milestones) do
|
2017-07-07 11:08:49 -04:00
|
|
|
MilestonesFinder.new(search_params).execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-04-08 17:28:58 -04:00
|
|
|
def milestone
|
2014-01-19 13:55:59 -05:00
|
|
|
@milestone ||= @project.milestones.find_by!(iid: params[:id])
|
2012-04-08 17:28:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_admin_milestone!
|
|
|
|
return render_404 unless can?(current_user, :admin_milestone, @project)
|
|
|
|
end
|
|
|
|
|
2014-06-26 11:51:11 -04: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 11:51:11 -04:00
|
|
|
end
|
2018-01-05 12:53:31 -05:00
|
|
|
|
|
|
|
def search_params
|
2018-06-01 03:52:55 -04:00
|
|
|
if request.format.json? && @project.group && can?(current_user, :read_group, @project.group)
|
2018-06-14 12:39:21 -04:00
|
|
|
groups = @project.group.self_and_ancestors_ids
|
2018-01-05 12:53:31 -05:00
|
|
|
end
|
|
|
|
|
2018-06-14 12:39:21 -04:00
|
|
|
params.permit(:state).merge(project_ids: @project.id, group_ids: groups)
|
2018-01-05 12:53:31 -05:00
|
|
|
end
|
2012-04-08 17:28:58 -04:00
|
|
|
end
|