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

87 lines
2.3 KiB
Ruby
Raw Normal View History

2015-09-11 14:41:01 +05:30
class Groups::MilestonesController < Groups::ApplicationController
2017-08-17 22:00:37 +05:30
include MilestoneActions
2015-11-26 14:37:03 +05:30
2016-06-02 11:05:42 +05:30
before_action :group_projects
2017-08-17 22:00:37 +05:30
before_action :milestone, only: [:show, :update, :merge_requests, :participants, :labels]
2016-06-02 11:05:42 +05:30
before_action :authorize_admin_milestones!, only: [:new, :create, :update]
2014-09-02 18:07:02 +05:30
def index
2016-06-02 11:05:42 +05:30
respond_to do |format|
format.html do
2017-08-17 22:00:37 +05:30
@milestone_states = GlobalMilestone.states_count(@projects)
2016-06-02 11:05:42 +05:30
@milestones = Kaminari.paginate_array(milestones).page(params[:page])
end
end
2014-09-02 18:07:02 +05:30
end
2015-11-26 14:37:03 +05:30
def new
@milestone = Milestone.new
2014-09-02 18:07:02 +05:30
end
2015-11-26 14:37:03 +05:30
def create
2016-06-02 11:05:42 +05:30
project_ids = params[:milestone][:project_ids].reject(&:blank?)
2015-11-26 14:37:03 +05:30
title = milestone_params[:title]
2014-09-02 18:07:02 +05:30
2016-06-02 11:05:42 +05:30
if create_milestones(project_ids)
redirect_to milestone_path(title)
else
render_new_with_error(project_ids.empty?)
2014-09-02 18:07:02 +05:30
end
2015-11-26 14:37:03 +05:30
end
def show
end
def update
@milestone.milestones.each do |milestone|
Milestones::UpdateService.new(milestone.project, current_user, milestone_params).execute(milestone)
2014-09-02 18:07:02 +05:30
end
2015-11-26 14:37:03 +05:30
redirect_back_or_default(default: milestone_path(@milestone.title))
2014-09-02 18:07:02 +05:30
end
private
2016-06-02 11:05:42 +05:30
def create_milestones(project_ids)
return false unless project_ids.present?
ActiveRecord::Base.transaction do
@projects.where(id: project_ids).each do |project|
Milestones::CreateService.new(project, current_user, milestone_params).execute
end
end
true
rescue ActiveRecord::ActiveRecordError => e
flash.now[:alert] = "An error occurred while creating the milestone: #{e.message}"
false
end
def render_new_with_error(empty_project_ids)
@milestone = Milestone.new(milestone_params)
2017-08-17 22:00:37 +05:30
@milestone.errors.add(:base, "Please select at least one project.") if empty_project_ids
2016-06-02 11:05:42 +05:30
render :new
end
def authorize_admin_milestones!
2015-11-26 14:37:03 +05:30
return render_404 unless can?(current_user, :admin_milestones, group)
2014-09-02 18:07:02 +05:30
end
2015-11-26 14:37:03 +05:30
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
2015-11-26 14:37:03 +05:30
def milestone_path(title)
2015-12-23 02:04:40 +05:30
group_milestone_path(@group, title.to_slug.to_s, title: title)
2014-09-02 18:07:02 +05:30
end
2017-08-17 22:00:37 +05:30
def milestones
@milestones = GroupMilestone.build_collection(@group, @projects, params)
end
def milestone
@milestone = GroupMilestone.build(@group, @projects, params[:title])
render_404 unless @milestone
end
2014-09-02 18:07:02 +05:30
end