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
|
|
|
|
|
|
|
def index
|
2017-08-17 22:00:37 +05:30
|
|
|
@groups = Group.with_statistics.with_route
|
2018-05-09 12:01:36 +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
|
2017-08-17 22:00:37 +05:30
|
|
|
@group = Group.with_statistics.joins(:route).group('routes.path').find_by_full_path(params[:id])
|
2018-03-17 18:26:18 +05:30
|
|
|
@members = present_members(
|
|
|
|
@group.members.order("access_level DESC").page(params[:members_page]))
|
|
|
|
@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)
|
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,
|
|
|
|
status: 302,
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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,
|
|
|
|
:project_creation_level
|
2017-08-17 22:00:37 +05:30
|
|
|
]
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|