2018-09-14 05:42:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-01-20 11:20:50 +00:00
|
|
|
class Admin::GroupsController < Admin::ApplicationController
|
2017-12-05 14:03:16 +00:00
|
|
|
include MembersPresentation
|
|
|
|
|
2016-11-22 16:58:10 +00:00
|
|
|
before_action :group, only: [:edit, :update, :destroy, :project_update, :members_update]
|
2012-10-02 16:01:40 +00:00
|
|
|
|
2020-10-05 21:08:47 +00:00
|
|
|
feature_category :subgroups
|
|
|
|
|
2012-10-02 16:01:40 +00:00
|
|
|
def index
|
2020-01-24 15:09:00 +00:00
|
|
|
@groups = groups.sort_by_attribute(@sort = params[:sort])
|
2012-10-02 16:01:40 +00:00
|
|
|
@groups = @groups.search(params[:name]) if params[:name].present?
|
2016-03-19 21:37:54 +00:00
|
|
|
@groups = @groups.page(params[:page])
|
2012-10-02 16:01:40 +00:00
|
|
|
end
|
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2012-10-02 16:01:40 +00:00
|
|
|
def show
|
2019-08-27 17:15:28 +00:00
|
|
|
# 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)
|
2017-12-05 14:03:16 +00:00
|
|
|
@members = present_members(
|
2020-09-10 18:08:54 +00:00
|
|
|
group_members.order("access_level DESC").page(params[:members_page]))
|
2017-12-05 14:03:16 +00:00
|
|
|
@requesters = present_members(
|
|
|
|
AccessRequestsFinder.new(@group).execute(current_user))
|
2016-11-22 16:58:10 +00:00
|
|
|
@projects = @group.projects.with_statistics.page(params[:projects_page])
|
2012-10-02 16:01:40 +00:00
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2012-10-02 16:01:40 +00:00
|
|
|
|
|
|
|
def new
|
|
|
|
@group = Group.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2014-06-26 13:57:10 +00:00
|
|
|
@group = Group.new(group_params)
|
2014-12-22 11:55:32 +00:00
|
|
|
@group.name = @group.path.dup unless @group.name
|
2012-10-02 16:01:40 +00:00
|
|
|
|
|
|
|
if @group.save
|
2013-09-26 11:49:22 +00:00
|
|
|
@group.add_owner(current_user)
|
2020-11-10 15:09:14 +00:00
|
|
|
@group.create_namespace_settings
|
2019-03-21 13:31:05 +00:00
|
|
|
redirect_to [:admin, @group], notice: _('Group %{group_name} was successfully created.') % { group_name: @group.name }
|
2012-10-02 16:01:40 +00:00
|
|
|
else
|
2013-06-22 12:08:11 +00:00
|
|
|
render "new"
|
2012-10-02 16:01:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2018-07-02 10:43:06 +00:00
|
|
|
if @group.update(group_params)
|
2019-03-21 13:31:05 +00:00
|
|
|
redirect_to [:admin, @group], notice: _('Group was successfully updated.')
|
2012-10-02 16:01:40 +00:00
|
|
|
else
|
2013-06-22 12:08:11 +00:00
|
|
|
render "edit"
|
2012-10-02 16:01:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-13 15:22:03 +00:00
|
|
|
def members_update
|
2017-06-06 14:55:12 +00:00
|
|
|
member_params = params.permit(:user_ids, :access_level, :expires_at)
|
2018-02-16 14:10:22 +00:00
|
|
|
result = Members::CreateService.new(current_user, member_params.merge(limit: -1)).execute(@group)
|
2013-06-10 12:58:51 +00:00
|
|
|
|
2017-06-06 14:55:12 +00:00
|
|
|
if result[:status] == :success
|
2019-03-21 13:31:05 +00:00
|
|
|
redirect_to [:admin, @group], notice: _('Users were successfully added.')
|
2017-04-20 15:20:30 +00:00
|
|
|
else
|
2017-06-06 14:55:12 +00:00
|
|
|
redirect_to [:admin, @group], alert: result[:message]
|
2017-04-20 15:20:30 +00:00
|
|
|
end
|
2012-12-25 22:52:20 +00:00
|
|
|
end
|
|
|
|
|
2012-10-02 16:01:40 +00:00
|
|
|
def destroy
|
2016-08-13 12:45:31 +00:00
|
|
|
Groups::DestroyService.new(@group, current_user).async_execute
|
2012-10-02 16:01:40 +00:00
|
|
|
|
2017-06-06 22:45:16 +00:00
|
|
|
redirect_to admin_groups_path,
|
2019-11-17 12:06:19 +00:00
|
|
|
status: :found,
|
2019-03-21 13:31:05 +00:00
|
|
|
alert: _('Group %{group_name} was scheduled for deletion.') % { group_name: @group.name }
|
2012-10-02 16:01:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-01-24 15:09:00 +00:00
|
|
|
def groups
|
|
|
|
Group.with_statistics.with_route
|
|
|
|
end
|
|
|
|
|
2012-10-02 16:01:40 +00:00
|
|
|
def group
|
2016-10-31 11:00:53 +00:00
|
|
|
@group ||= Group.find_by_full_path(params[:id])
|
2012-10-02 16:01:40 +00:00
|
|
|
end
|
2014-06-26 13:57:10 +00:00
|
|
|
|
2020-09-10 18:08:54 +00:00
|
|
|
def group_members
|
|
|
|
@group.members
|
|
|
|
end
|
|
|
|
|
2014-06-26 13:57:10 +00:00
|
|
|
def group_params
|
2018-06-25 13:11:00 +00:00
|
|
|
params.require(:group).permit(allowed_group_params)
|
2017-01-10 13:43:06 +00:00
|
|
|
end
|
|
|
|
|
2018-06-25 13:11:00 +00:00
|
|
|
def allowed_group_params
|
2017-01-10 13:43:06 +00:00
|
|
|
[
|
2016-09-06 16:48:00 +00:00
|
|
|
:avatar,
|
2016-09-01 23:49:48 +00:00
|
|
|
:description,
|
2016-09-06 16:48:00 +00:00
|
|
|
:lfs_enabled,
|
|
|
|
:name,
|
2016-09-01 23:49:48 +00:00
|
|
|
:path,
|
|
|
|
:request_access_enabled,
|
2017-01-24 21:09:58 +00:00
|
|
|
:visibility_level,
|
|
|
|
:require_two_factor_authentication,
|
2019-04-05 18:49:46 +00:00
|
|
|
:two_factor_grace_period,
|
2019-06-27 20:45:58 +00:00
|
|
|
:project_creation_level,
|
|
|
|
:subgroup_creation_level
|
2017-01-10 13:43:06 +00:00
|
|
|
]
|
2014-06-26 13:57:10 +00:00
|
|
|
end
|
2012-10-02 16:01:40 +00:00
|
|
|
end
|
2019-09-13 13:26:31 +00:00
|
|
|
|
|
|
|
Admin::GroupsController.prepend_if_ee('EE::Admin::GroupsController')
|