gitlab-org--gitlab-foss/app/controllers/projects/milestones_controller.rb

113 lines
2.9 KiB
Ruby
Raw Normal View History

class Projects::MilestonesController < Projects::ApplicationController
2012-04-08 17:28:58 -04:00
before_filter :module_enabled
before_filter :milestone, only: [:edit, :update, :destroy, :show, :sort_issues, :sort_merge_requests]
2012-04-08 17:28:58 -04:00
# Allow read any milestone
before_filter :authorize_read_milestone!
# Allow admin milestone
before_filter :authorize_admin_milestone!, except: [:index, :show]
2012-04-08 17:28:58 -04:00
respond_to :html
def index
@milestones = case params[:f]
2013-02-18 04:10:09 -05:00
when 'all'; @project.milestones.order("state, due_date DESC")
2012-12-14 00:34:05 -05:00
when 'closed'; @project.milestones.closed.order("due_date DESC")
else @project.milestones.active.order("due_date ASC")
2012-04-08 17:28:58 -04:00
end
2012-12-14 00:34:05 -05:00
@milestones = @milestones.includes(:project)
2012-04-08 17:28:58 -04:00
@milestones = @milestones.page(params[:page]).per(20)
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
2012-04-08 17:28:58 -04:00
end
def create
@milestone = Milestones::CreateService.new(project, current_user, milestone_params).execute
2012-04-08 17:28:58 -04:00
if @milestone.save
redirect_to project_milestone_path(@project, @milestone)
else
render "new"
end
end
def update
@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
format.html do
2012-04-08 17:28:58 -04:00
if @milestone.valid?
redirect_to [@project, @milestone]
else
render :edit
end
end
end
end
def destroy
return access_denied! unless can?(current_user, :admin_milestone, @milestone)
@milestone.destroy
respond_to do |format|
format.html { redirect_to project_milestones_path }
format.js { render nothing: true }
2012-04-08 17:28:58 -04:00
end
end
def sort_issues
@issues = @milestone.issues.where(id: params['sortable_issue'])
@issues.each do |issue|
issue.position = params['sortable_issue'].index(issue.id.to_s) + 1
issue.save
end
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
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
return render_404 unless @project.issues_enabled
end
def milestone_params
params.require(:milestone).permit(:title, :description, :due_date, :state_event)
end
2012-04-08 17:28:58 -04:00
end