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
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
feature_category :subgroups
|
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@group = Group.new(group_params)
|
2015-04-26 12:48:37 +05:30
|
|
|
@group.name = @group.path.dup unless @group.name
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
if @group.save
|
|
|
|
@group.add_owner(current_user)
|
2021-01-03 14:25:43 +05:30
|
|
|
@group.create_namespace_settings
|
2019-07-07 11:18:12 +05:30
|
|
|
redirect_to [:admin, @group], notice: _('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
|
2018-11-18 11:00:15 +05:30
|
|
|
if @group.update(group_params)
|
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
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def members_update
|
2017-09-10 17:25:29 +05:30
|
|
|
member_params = params.permit(:user_ids, :access_level, :expires_at)
|
2018-03-27 19:54:05 +05:30
|
|
|
result = Members::CreateService.new(current_user, member_params.merge(limit: -1)).execute(@group)
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
if result[:status] == :success
|
2019-07-07 11:18:12 +05:30
|
|
|
redirect_to [:admin, @group], notice: _('Users were successfully added.')
|
2017-08-17 22:00:37 +05:30
|
|
|
else
|
2017-09-10 17:25:29 +05:30
|
|
|
redirect_to [:admin, @group], alert: result[:message]
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
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,
|
2019-12-26 22:10:19 +05:30
|
|
|
status: :found,
|
2019-07-07 11:18:12 +05:30
|
|
|
alert: _('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,
|
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,
|
2019-10-12 21:52:04 +05:30
|
|
|
:project_creation_level,
|
|
|
|
:subgroup_creation_level
|
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
|
|
|
|
|
|
|
Admin::GroupsController.prepend_if_ee('EE::Admin::GroupsController')
|