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

88 lines
2.3 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
class Admin::GroupsController < Admin::ApplicationController
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
2015-04-26 12:48:37 +05:30
@groups = @groups.sort(@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
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])
2016-06-02 11:05:42 +05:30
@members = @group.members.order("access_level DESC").page(params[:members_page])
2016-11-03 12:29:30 +05:30
@requesters = 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
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)
2017-08-17 22:00:37 +05:30
redirect_to [:admin, @group], notice: "Group '#{@group.name}' was successfully created."
2014-09-02 18:07:02 +05:30
else
render "new"
end
end
def update
if @group.update_attributes(group_params)
redirect_to [:admin, @group], notice: 'Group was successfully updated.'
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)
result = Members::CreateService.new(@group, current_user, member_params.merge(limit: -1)).execute
2014-09-02 18:07:02 +05:30
2017-09-10 17:25:29 +05:30
if result[:status] == :success
2017-08-17 22:00:37 +05:30
redirect_to [:admin, @group], notice: 'Users were successfully added.'
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,
alert: "Group '#{@group.name}' was scheduled for deletion."
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
2017-08-17 22:00:37 +05:30
params.require(:group).permit(group_params_ce)
end
def group_params_ce
[
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,
:two_factor_grace_period
]
2014-09-02 18:07:02 +05:30
end
end