2013-06-23 12:47:22 -04:00
|
|
|
class Projects::MilestonesController < Projects::ApplicationController
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :module_enabled
|
|
|
|
before_action :milestone, only: [:edit, :update, :destroy, :show, :sort_issues, :sort_merge_requests]
|
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
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :authorize_admin_milestone!, except: [:index, :show]
|
2012-04-08 17:28:58 -04:00
|
|
|
|
|
|
|
respond_to :html
|
|
|
|
|
|
|
|
def index
|
2016-01-23 17:31:46 -05:00
|
|
|
@milestones =
|
|
|
|
case params[:state]
|
|
|
|
when 'all' then @project.milestones.reorder(due_date: :desc, title: :asc)
|
|
|
|
when 'closed' then @project.milestones.closed.reorder(due_date: :desc, title: :asc)
|
|
|
|
else @project.milestones.active.reorder(due_date: :asc, title: :asc)
|
|
|
|
end
|
2012-04-08 17:28:58 -04:00
|
|
|
|
2012-12-14 00:34:05 -05:00
|
|
|
@milestones = @milestones.includes(:project)
|
2016-03-16 14:08:35 -04:00
|
|
|
respond_to do |format|
|
2016-03-17 05:09:06 -04:00
|
|
|
format.html do
|
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
|
|
|
|
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
|
|
|
|
|
|
|
if @milestone.save
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to namespace_project_milestone_path(@project.namespace,
|
|
|
|
@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?
|
2015-02-26 19:03:42 -05:00
|
|
|
redirect_to namespace_project_milestone_path(@project.namespace,
|
|
|
|
@project, @milestone)
|
2012-04-08 17:28:58 -04:00
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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|
|
2015-01-24 13:02:58 -05:00
|
|
|
format.html { redirect_to namespace_project_milestones_path }
|
2012-08-10 18:07:50 -04:00
|
|
|
format.js { render nothing: true }
|
2012-04-08 17:28:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-11 07:09:45 -04:00
|
|
|
def sort_issues
|
2015-10-15 12:10:35 -04:00
|
|
|
@milestone.sort_issues(params['sortable_issue'].map(&:to_i))
|
2014-06-11 07:09:45 -04:00
|
|
|
|
|
|
|
render json: { saved: true }
|
|
|
|
end
|
|
|
|
|
2014-06-11 10:11:52 -04:00
|
|
|
def sort_merge_requests
|
|
|
|
@merge_requests = @milestone.merge_requests.where(id: params['sortable_merge_request'])
|
|
|
|
@merge_requests.each do |merge_request|
|
|
|
|
merge_request.position = params['sortable_merge_request'].index(merge_request.id.to_s) + 1
|
|
|
|
merge_request.save
|
|
|
|
end
|
|
|
|
|
|
|
|
render json: { saved: true }
|
|
|
|
end
|
|
|
|
|
2012-04-08 17:28:58 -04:00
|
|
|
protected
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def module_enabled
|
2014-11-20 11:18:16 -05:00
|
|
|
unless @project.issues_enabled || @project.merge_requests_enabled
|
|
|
|
return render_404
|
|
|
|
end
|
2012-04-08 17:28:58 -04:00
|
|
|
end
|
2014-06-26 11:51:11 -04:00
|
|
|
|
|
|
|
def milestone_params
|
|
|
|
params.require(:milestone).permit(:title, :description, :due_date, :state_event)
|
|
|
|
end
|
2012-04-08 17:28:58 -04:00
|
|
|
end
|