debian-mirror-gitlab/app/controllers/projects/milestones_controller.rb

109 lines
2.8 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
class Projects::MilestonesController < Projects::ApplicationController
2017-08-17 22:00:37 +05:30
include MilestoneActions
2017-09-10 17:25:29 +05:30
before_action :check_issuables_available!
before_action :milestone, only: [:edit, :update, :destroy, :show, :merge_requests, :participants, :labels]
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
2017-08-17 22:00:37 +05:30
before_action :authorize_admin_milestone!, except: [:index, :show, :merge_requests, :participants, :labels]
2014-09-02 18:07:02 +05:30
respond_to :html
def index
2017-08-17 22:00:37 +05:30
@sort = params[:sort] || 'due_date_asc'
2017-09-10 17:25:29 +05:30
@milestones = milestones.sort(@sort)
2017-08-17 22:00:37 +05:30
2016-06-02 11:05:42 +05:30
respond_to do |format|
format.html do
2017-08-17 22:00:37 +05:30
@project_namespace = @project.namespace.becomes(Namespace)
2017-09-10 17:25:29 +05:30
# 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-06-02 11:05:42 +05:30
@milestones = @milestones.page(params[:page])
end
format.json do
render json: @milestones.to_json(methods: :name)
end
end
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
2017-09-10 17:25:29 +05:30
@project_namespace = @project.namespace.becomes(Namespace)
2014-09-02 18:07:02 +05:30
end
def create
@milestone = Milestones::CreateService.new(project, current_user, milestone_params).execute
2017-09-10 17:25:29 +05:30
if @milestone.valid?
redirect_to project_milestone_path(@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?
2017-09-10 17:25:29 +05:30
redirect_to project_milestone_path(@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|
2017-09-10 17:25:29 +05:30
format.html { redirect_to namespace_project_milestones_path, status: 302 }
2016-06-02 11:05:42 +05:30
format.js { head :ok }
2014-09-02 18:07:02 +05:30
end
end
2017-09-10 17:25:29 +05:30
protected
2014-09-02 18:07:02 +05:30
2017-09-10 17:25:29 +05:30
def milestones
@milestones ||= begin
if @project.group && can?(current_user, :read_group, @project.group)
group = @project.group
end
2014-09-02 18:07:02 +05:30
2017-09-10 17:25:29 +05:30
search_params = params.merge(project_ids: @project.id, group_ids: group&.id)
2014-09-02 18:07:02 +05:30
2017-09-10 17:25:29 +05:30
MilestonesFinder.new(search_params).execute
end
2014-09-02 18:07:02 +05:30
end
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 milestone_params
2017-08-17 22:00:37 +05:30
params.require(:milestone).permit(:title, :description, :start_date, :due_date, :state_event)
2014-09-02 18:07:02 +05:30
end
end