2013-01-20 06:20:50 -05:00
|
|
|
class Admin::GroupsController < Admin::ApplicationController
|
2017-12-05 09:03:16 -05:00
|
|
|
include MembersPresentation
|
|
|
|
|
2016-11-22 11:58:10 -05:00
|
|
|
before_action :group, only: [:edit, :update, :destroy, :project_update, :members_update]
|
2012-10-02 12:01:40 -04:00
|
|
|
|
|
|
|
def index
|
2017-02-04 13:26:11 -05:00
|
|
|
@groups = Group.with_statistics.with_route
|
2015-02-05 22:15:05 -05:00
|
|
|
@groups = @groups.sort(@sort = params[:sort])
|
2012-10-02 12:01:40 -04:00
|
|
|
@groups = @groups.search(params[:name]) if params[:name].present?
|
2016-03-19 17:37:54 -04:00
|
|
|
@groups = @groups.page(params[:page])
|
2012-10-02 12:01:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2016-12-28 06:10:34 -05:00
|
|
|
@group = Group.with_statistics.joins(:route).group('routes.path').find_by_full_path(params[:id])
|
2017-12-05 09:03:16 -05:00
|
|
|
@members = present_members(
|
|
|
|
@group.members.order("access_level DESC").page(params[:members_page]))
|
|
|
|
@requesters = present_members(
|
|
|
|
AccessRequestsFinder.new(@group).execute(current_user))
|
2016-11-22 11:58:10 -05:00
|
|
|
@projects = @group.projects.with_statistics.page(params[:projects_page])
|
2012-10-02 12:01:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@group = Group.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2014-06-26 09:57:10 -04:00
|
|
|
@group = Group.new(group_params)
|
2014-12-22 06:55:32 -05:00
|
|
|
@group.name = @group.path.dup unless @group.name
|
2012-10-02 12:01:40 -04:00
|
|
|
|
|
|
|
if @group.save
|
2013-09-26 07:49:22 -04:00
|
|
|
@group.add_owner(current_user)
|
2017-04-25 08:43:21 -04:00
|
|
|
redirect_to [:admin, @group], notice: "Group '#{@group.name}' was successfully created."
|
2012-10-02 12:01:40 -04:00
|
|
|
else
|
2013-06-22 08:08:11 -04:00
|
|
|
render "new"
|
2012-10-02 12:01:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2014-06-26 09:57:10 -04:00
|
|
|
if @group.update_attributes(group_params)
|
2012-10-02 12:01:40 -04:00
|
|
|
redirect_to [:admin, @group], notice: 'Group was successfully updated.'
|
|
|
|
else
|
2013-06-22 08:08:11 -04:00
|
|
|
render "edit"
|
2012-10-02 12:01:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-13 11:22:03 -04:00
|
|
|
def members_update
|
2017-06-06 10:55:12 -04:00
|
|
|
member_params = params.permit(:user_ids, :access_level, :expires_at)
|
|
|
|
result = Members::CreateService.new(@group, current_user, member_params.merge(limit: -1)).execute
|
2013-06-10 08:58:51 -04:00
|
|
|
|
2017-06-06 10:55:12 -04:00
|
|
|
if result[:status] == :success
|
2017-04-20 11:20:30 -04:00
|
|
|
redirect_to [:admin, @group], notice: 'Users were successfully added.'
|
|
|
|
else
|
2017-06-06 10:55:12 -04:00
|
|
|
redirect_to [:admin, @group], alert: result[:message]
|
2017-04-20 11:20:30 -04:00
|
|
|
end
|
2012-12-25 17:52:20 -05:00
|
|
|
end
|
|
|
|
|
2012-10-02 12:01:40 -04:00
|
|
|
def destroy
|
2016-08-13 08:45:31 -04:00
|
|
|
Groups::DestroyService.new(@group, current_user).async_execute
|
2012-10-02 12:01:40 -04:00
|
|
|
|
2017-06-06 18:45:16 -04:00
|
|
|
redirect_to admin_groups_path,
|
|
|
|
status: 302,
|
|
|
|
alert: "Group '#{@group.name}' was scheduled for deletion."
|
2012-10-02 12:01:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def group
|
2016-10-31 07:00:53 -04:00
|
|
|
@group ||= Group.find_by_full_path(params[:id])
|
2012-10-02 12:01:40 -04:00
|
|
|
end
|
2014-06-26 09:57:10 -04:00
|
|
|
|
|
|
|
def group_params
|
2017-01-10 08:43:06 -05:00
|
|
|
params.require(:group).permit(group_params_ce)
|
|
|
|
end
|
|
|
|
|
|
|
|
def group_params_ce
|
|
|
|
[
|
2016-09-06 12:48:00 -04:00
|
|
|
:avatar,
|
2016-09-01 19:49:48 -04:00
|
|
|
:description,
|
2016-09-06 12:48:00 -04:00
|
|
|
:lfs_enabled,
|
|
|
|
:name,
|
2016-09-01 19:49:48 -04:00
|
|
|
:path,
|
|
|
|
:request_access_enabled,
|
2017-01-24 16:09:58 -05:00
|
|
|
:visibility_level,
|
|
|
|
:require_two_factor_authentication,
|
|
|
|
:two_factor_grace_period
|
2017-01-10 08:43:06 -05:00
|
|
|
]
|
2014-06-26 09:57:10 -04:00
|
|
|
end
|
2012-10-02 12:01:40 -04:00
|
|
|
end
|