2014-09-02 18:07:02 +05:30
|
|
|
class Projects::MilestonesController < Projects::ApplicationController
|
2015-09-11 14:41:01 +05:30
|
|
|
before_action :module_enabled
|
|
|
|
before_action :milestone, only: [:edit, :update, :destroy, :show, :sort_issues, :sort_merge_requests]
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
# Allow read any milestone
|
2015-09-11 14:41:01 +05:30
|
|
|
before_action :authorize_read_milestone!
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
# Allow admin milestone
|
2015-09-11 14:41:01 +05:30
|
|
|
before_action :authorize_admin_milestone!, except: [:index, :show]
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
respond_to :html
|
|
|
|
|
|
|
|
def index
|
2015-04-26 12:48:37 +05:30
|
|
|
@milestones = case params[:state]
|
2014-09-02 18:07:02 +05:30
|
|
|
when 'all'; @project.milestones.order("state, due_date DESC")
|
|
|
|
when 'closed'; @project.milestones.closed.order("due_date DESC")
|
|
|
|
else @project.milestones.active.order("due_date ASC")
|
|
|
|
end
|
|
|
|
|
|
|
|
@milestones = @milestones.includes(:project)
|
2015-04-26 12:48:37 +05:30
|
|
|
@milestones = @milestones.page(params[:page]).per(PER_PAGE)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@milestone = @project.milestones.new
|
|
|
|
respond_with(@milestone)
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
respond_with(@milestone)
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@issues = @milestone.issues
|
|
|
|
@users = @milestone.participants.uniq
|
|
|
|
@merge_requests = @milestone.merge_requests
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@milestone = Milestones::CreateService.new(project, current_user, milestone_params).execute
|
|
|
|
|
|
|
|
if @milestone.save
|
2015-04-26 12:48:37 +05:30
|
|
|
redirect_to namespace_project_milestone_path(@project.namespace,
|
|
|
|
@project, @milestone)
|
2014-09-02 18:07:02 +05:30
|
|
|
else
|
|
|
|
render "new"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@milestone = Milestones::UpdateService.new(project, current_user, milestone_params).execute(milestone)
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
format.html do
|
|
|
|
if @milestone.valid?
|
2015-04-26 12:48:37 +05:30
|
|
|
redirect_to namespace_project_milestone_path(@project.namespace,
|
|
|
|
@project, @milestone)
|
2014-09-02 18:07:02 +05:30
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2015-09-11 14:41:01 +05:30
|
|
|
return access_denied! unless can?(current_user, :admin_milestone, @project)
|
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
Milestones::DestroyService.new(project, current_user).execute(milestone)
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
respond_to do |format|
|
2015-04-26 12:48:37 +05:30
|
|
|
format.html { redirect_to namespace_project_milestones_path }
|
2014-09-02 18:07:02 +05:30
|
|
|
format.js { render nothing: true }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def sort_issues
|
2015-11-26 14:37:03 +05:30
|
|
|
@milestone.sort_issues(params['sortable_issue'].map(&:to_i))
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
render json: { saved: true }
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def milestone
|
|
|
|
@milestone ||= @project.milestones.find_by!(iid: params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_admin_milestone!
|
|
|
|
return render_404 unless can?(current_user, :admin_milestone, @project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def module_enabled
|
2015-04-26 12:48:37 +05:30
|
|
|
unless @project.issues_enabled || @project.merge_requests_enabled
|
|
|
|
return render_404
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def milestone_params
|
|
|
|
params.require(:milestone).permit(:title, :description, :due_date, :state_event)
|
|
|
|
end
|
|
|
|
end
|