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

126 lines
3.2 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
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
2021-01-03 14:25:43 +05:30
before_action :milestone, only: [:edit, :show, :update, :issues, :merge_requests, :participants, :labels, :destroy]
2018-11-20 20:47:30 +05:30
before_action :authorize_admin_milestones!, only: [:edit, :new, :create, :update, :destroy]
2014-09-02 18:07:02 +05:30
2021-12-11 22:18:48 +05:30
feature_category :team_planning
2022-07-16 23:28:13 +05:30
urgency :low
2021-01-03 14:25:43 +05:30
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
2020-06-23 00:09:42 +05:30
@milestone_states = Milestone.states_count(group_projects_with_access.without_order, [group])
@milestones = milestones.page(params[:page])
2016-06-02 11:05:42 +05:30
end
2017-09-10 17:25:29 +05:30
format.json do
2021-09-30 23:02:18 +05:30
render json: milestones.to_json(only: [:id, :title, :due_date], methods: :name)
2017-09-10 17:25:29 +05:30
end
2016-06-02 11:05:42 +05:30
end
2014-09-02 18:07:02 +05:30
end
2015-11-26 14:37:03 +05:30
def new
2021-06-08 01:23:25 +05:30
@noteable = @milestone = Milestone.new
2014-09-02 18:07:02 +05:30
end
2015-11-26 14:37:03 +05:30
def create
2017-09-10 17:25:29 +05:30
@milestone = Milestones::CreateService.new(group, current_user, milestone_params).execute
2014-09-02 18:07:02 +05:30
2017-09-10 17:25:29 +05:30
if @milestone.persisted?
2020-06-23 00:09:42 +05:30
redirect_to milestone_path(@milestone)
2016-06-02 11:05:42 +05:30
else
2017-09-10 17:25:29 +05:30
render "new"
2014-09-02 18:07:02 +05:30
end
2015-11-26 14:37:03 +05:30
end
def show
end
2017-09-10 17:25:29 +05:30
def edit
2014-09-02 18:07:02 +05:30
end
2017-09-10 17:25:29 +05:30
def update
2020-06-23 00:09:42 +05:30
Milestones::UpdateService.new(@milestone.parent, current_user, milestone_params).execute(@milestone)
2016-06-02 11:05:42 +05:30
2020-06-23 00:09:42 +05:30
redirect_to milestone_path(@milestone)
2023-07-09 08:55:56 +05:30
rescue ActiveRecord::StaleObjectError
respond_to do |format|
format.html do
@conflict = true
render :edit
end
format.json do
render json: {
errors: [
format(
_("Someone edited this %{model_name} at the same time you did. Please refresh your browser and make sure your changes will not unintentionally remove theirs."), # rubocop:disable Layout/LineLength
model_name: _('milestone')
)
]
}, status: :conflict
end
end
2016-06-02 11:05:42 +05:30
end
2018-11-20 20:47:30 +05:30
def destroy
Milestones::DestroyService.new(group, current_user).execute(@milestone)
respond_to do |format|
format.html { redirect_to group_milestones_path(group), status: :see_other }
format.js { head :ok }
end
end
2017-09-10 17:25:29 +05:30
private
2016-06-02 11:05:42 +05:30
def authorize_admin_milestones!
2018-11-20 20:47:30 +05:30
return render_404 unless can?(current_user, :admin_milestone, group)
2014-09-02 18:07:02 +05:30
end
2015-11-26 14:37:03 +05:30
def milestone_params
2023-07-09 08:55:56 +05:30
params.require(:milestone)
.permit(
:description,
:due_date,
:lock_version,
:start_date,
:state_event,
:title
)
2014-09-02 18:07:02 +05:30
end
2020-06-23 00:09:42 +05:30
def milestones
MilestonesFinder.new(search_params).execute
2019-02-15 15:39:39 +05:30
end
2020-06-23 00:09:42 +05:30
def milestone
2021-06-08 01:23:25 +05:30
@noteable = @milestone ||= group.milestones.find_by_iid(params[:id])
2020-06-23 00:09:42 +05:30
render_404 unless @milestone
2014-09-02 18:07:02 +05:30
end
2017-08-17 22:00:37 +05:30
2020-06-23 00:09:42 +05:30
def search_params
groups = request.format.json? ? group_ids(include_ancestors: true) : group_ids
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
@sort = params[:sort] || 'due_date_asc'
2020-06-23 00:09:42 +05:30
params.permit(:state, :search_title).merge(sort: @sort, group_ids: groups, project_ids: group_projects_with_access)
2019-09-30 23:59:55 +05:30
end
def group_projects_with_access
2020-03-13 15:44:24 +05:30
group_projects_with_subgroups.with_issues_or_mrs_available_for_user(current_user)
end
def group_ids(include_ancestors: false)
if include_ancestors
group.self_and_hierarchy.public_or_visible_to_user(current_user).select(:id)
else
group.self_and_descendants.public_or_visible_to_user(current_user).select(:id)
end
2018-11-08 19:23:39 +05:30
end
2014-09-02 18:07:02 +05:30
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
Groups::MilestonesController.prepend_mod_with('Groups::MilestonesController')