debian-mirror-gitlab/app/controllers/admin/groups_controller.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

113 lines
3 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
class Admin::GroupsController < Admin::ApplicationController
2018-03-17 18:26:18 +05:30
include MembersPresentation
2017-08-17 22:00:37 +05:30
before_action :group, only: [:edit, :update, :destroy, :project_update, :members_update]
2014-09-02 18:07:02 +05:30
2023-06-20 00:43:36 +05:30
feature_category :subgroups, [:create, :destroy, :edit, :index, :members_update, :new, :show, :update]
2021-01-03 14:25:43 +05:30
2014-09-02 18:07:02 +05:30
def index
2020-03-13 15:44:24 +05:30
@groups = groups.sort_by_attribute(@sort = params[:sort])
2014-09-02 18:07:02 +05:30
@groups = @groups.search(params[:name]) if params[:name].present?
2016-06-02 11:05:42 +05:30
@groups = @groups.page(params[:page])
2014-09-02 18:07:02 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2014-09-02 18:07:02 +05:30
def show
2019-12-04 20:38:33 +05:30
# Group.with_statistics doesn't behave nicely when including other relations.
# Group.find_by_full_path includes the routes relation to avoid a common N+1
# (at the expense of this action: there are two queries here to find and retrieve
# the Group with statistics).
@group = Group.with_statistics.find(group&.id)
2018-03-17 18:26:18 +05:30
@members = present_members(
2020-11-24 15:15:51 +05:30
group_members.order("access_level DESC").page(params[:members_page]))
2018-03-17 18:26:18 +05:30
@requesters = present_members(
AccessRequestsFinder.new(@group).execute(current_user))
2017-08-17 22:00:37 +05:30
@projects = @group.projects.with_statistics.page(params[:projects_page])
2014-09-02 18:07:02 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2014-09-02 18:07:02 +05:30
def new
@group = Group.new
2021-04-29 21:17:54 +05:30
@group.build_admin_note
2014-09-02 18:07:02 +05:30
end
def edit
2021-04-29 21:17:54 +05:30
@group.build_admin_note unless @group.admin_note
2014-09-02 18:07:02 +05:30
end
def create
2023-01-13 00:05:48 +05:30
@group = ::Groups::CreateService.new(current_user, group_params).execute
2014-09-02 18:07:02 +05:30
2023-01-13 00:05:48 +05:30
if @group.persisted?
2023-03-17 16:20:25 +05:30
redirect_to [:admin, @group], notice: format(_('Group %{group_name} was successfully created.'), group_name: @group.name)
2014-09-02 18:07:02 +05:30
else
render "new"
end
end
def update
2021-04-29 21:17:54 +05:30
@group.build_admin_note unless @group.admin_note
2018-11-18 11:00:15 +05:30
if @group.update(group_params)
2023-03-04 22:38:38 +05:30
unless Gitlab::Utils.to_boolean(group_params['runner_registration_enabled'])
Ci::Runners::ResetRegistrationTokenService.new(@group, current_user).execute
end
2019-07-07 11:18:12 +05:30
redirect_to [:admin, @group], notice: _('Group was successfully updated.')
2014-09-02 18:07:02 +05:30
else
render "edit"
end
end
def destroy
2017-08-17 22:00:37 +05:30
Groups::DestroyService.new(@group, current_user).async_execute
2014-09-02 18:07:02 +05:30
2017-09-10 17:25:29 +05:30
redirect_to admin_groups_path,
2023-05-27 22:25:52 +05:30
status: :found,
alert: format(_('Group %{group_name} was scheduled for deletion.'), group_name: @group.name)
2014-09-02 18:07:02 +05:30
end
private
2020-03-13 15:44:24 +05:30
def groups
Group.with_statistics.with_route
end
2014-09-02 18:07:02 +05:30
def group
2017-08-17 22:00:37 +05:30
@group ||= Group.find_by_full_path(params[:id])
2014-09-02 18:07:02 +05:30
end
2020-11-24 15:15:51 +05:30
def group_members
@group.members
end
2014-09-02 18:07:02 +05:30
def group_params
2018-11-08 19:23:39 +05:30
params.require(:group).permit(allowed_group_params)
2017-08-17 22:00:37 +05:30
end
2018-11-08 19:23:39 +05:30
def allowed_group_params
2017-08-17 22:00:37 +05:30
[
2016-09-29 09:46:39 +05:30
:avatar,
:description,
:lfs_enabled,
:name,
:path,
:request_access_enabled,
2023-03-04 22:38:38 +05:30
:runner_registration_enabled,
2017-08-17 22:00:37 +05:30
:visibility_level,
:require_two_factor_authentication,
2019-07-07 11:18:12 +05:30
:two_factor_grace_period,
2022-07-23 23:45:48 +05:30
:enabled_git_access_protocol,
2019-10-12 21:52:04 +05:30
:project_creation_level,
2021-04-29 21:17:54 +05:30
:subgroup_creation_level,
admin_note_attributes: [
:note
]
2017-08-17 22:00:37 +05:30
]
2014-09-02 18:07:02 +05:30
end
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
Admin::GroupsController.prepend_mod_with('Admin::GroupsController')