2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
class Groups::GroupMembersController < Groups::ApplicationController
|
2016-06-16 23:09:34 +05:30
|
|
|
include MembershipActions
|
2018-03-17 18:26:18 +05:30
|
|
|
include MembersPresentation
|
2017-08-17 22:00:37 +05:30
|
|
|
include SortingHelper
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
MEMBER_PER_PAGE_LIMIT = 50
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
def self.admin_not_required_endpoints
|
|
|
|
%i[index leave request_access]
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
# Authorize
|
2018-11-08 19:23:39 +05:30
|
|
|
before_action :authorize_admin_group_member!, except: admin_not_required_endpoints
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
skip_before_action :check_two_factor_requirement, only: :leave
|
2018-03-27 19:54:05 +05:30
|
|
|
skip_cross_project_access_check :index, :create, :update, :destroy, :request_access,
|
|
|
|
:approve_access_request, :leave, :resend_invite,
|
|
|
|
:override
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
feature_category :authentication_and_authorization
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def index
|
2017-08-17 22:00:37 +05:30
|
|
|
@sort = params[:sort].presence || sort_value_name
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
@project = @group.projects.find(params[:project_id]) if params[:project_id]
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
@members = GroupMembersFinder
|
|
|
|
.new(@group, current_user, params: filter_params)
|
|
|
|
.execute(include_relations: requested_relations)
|
2019-10-12 21:52:04 +05:30
|
|
|
|
|
|
|
if can_manage_members
|
2020-03-13 15:44:24 +05:30
|
|
|
@skip_groups = @group.related_group_ids
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
@invited_members = @members.invite
|
|
|
|
@invited_members = @invited_members.search_invite_email(params[:search_invited]) if params[:search_invited].present?
|
|
|
|
@invited_members = present_invited_members(@invited_members)
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
@members = present_group_members(@members.non_invite)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
@requesters = present_members(
|
2020-05-24 23:13:21 +05:30
|
|
|
AccessRequestsFinder.new(@group).execute(current_user)
|
|
|
|
)
|
2015-11-26 14:37:03 +05:30
|
|
|
|
|
|
|
@group_member = @group.group_members.new
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
# MembershipActions concern
|
|
|
|
alias_method :membershipable, :group
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
def can_manage_members
|
|
|
|
can?(current_user, :admin_group_member, @group)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
def present_invited_members(invited_members)
|
|
|
|
present_members(invited_members
|
|
|
|
.page(params[:invited_members_page])
|
|
|
|
.per(MEMBER_PER_PAGE_LIMIT))
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
def present_group_members(members)
|
|
|
|
present_members(members
|
|
|
|
.page(params[:page])
|
|
|
|
.per(MEMBER_PER_PAGE_LIMIT))
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
def filter_params
|
|
|
|
params.permit(:two_factor, :search).merge(sort: @sort)
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
def membershipable_members
|
|
|
|
group.members
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
Groups::GroupMembersController.prepend_if_ee('EE::Groups::GroupMembersController')
|