Module: API::Helpers::MembersHelpers

Extended by:
Grape::API::Helpers
Included in:
BadgesHelpers
Defined in:
lib/api/helpers/members_helpers.rb

Instance Method Summary collapse

Instance Method Details

#authorize_admin_source!(source_type, source) ⇒ Object


17
18
19
# File 'lib/api/helpers/members_helpers.rb', line 17

def authorize_admin_source!(source_type, source)
  authorize! :"admin_#{source_type}", source
end

#create_member(current_user, user, source, params) ⇒ Object


44
45
46
# File 'lib/api/helpers/members_helpers.rb', line 44

def create_member(current_user, user, source, params)
  source.add_user(user, params[:access_level], current_user: current_user, expires_at: params[:expires_at])
end

#find_all_members(source) ⇒ Object

rubocop: enable CodeReuse/ActiveRecord


31
32
33
34
# File 'lib/api/helpers/members_helpers.rb', line 31

def find_all_members(source)
  members = source.is_a?(Project) ? find_all_members_for_project(source) : find_all_members_for_group(source)
  members.non_invite.non_request
end

#find_all_members_for_group(group) ⇒ Object


40
41
42
# File 'lib/api/helpers/members_helpers.rb', line 40

def find_all_members_for_group(group)
  GroupMembersFinder.new(group).execute
end

#find_all_members_for_project(project) ⇒ Object


36
37
38
# File 'lib/api/helpers/members_helpers.rb', line 36

def find_all_members_for_project(project)
  MembersFinder.new(project, current_user).execute(include_relations: [:inherited, :direct, :invited_groups_members])
end

#find_source(source_type, id) ⇒ Object


13
14
15
# File 'lib/api/helpers/members_helpers.rb', line 13

def find_source(source_type, id)
  public_send("find_#{source_type}!", id) # rubocop:disable GitlabSecurity/PublicSend
end

#present_members(members) ⇒ Object


48
49
50
# File 'lib/api/helpers/members_helpers.rb', line 48

def present_members(members)
  present members, with: Entities::Member, current_user: current_user, show_seat_info: params[:show_seat_info]
end

#retrieve_members(source, params:, deep: false) ⇒ Object

rubocop: disable CodeReuse/ActiveRecord


22
23
24
25
26
27
28
# File 'lib/api/helpers/members_helpers.rb', line 22

def retrieve_members(source, params:, deep: false)
  members = deep ? find_all_members(source) : source.members.where.not(user_id: nil)
  members = members.includes(:user)
  members = members.references(:user).merge(User.search(params[:query])) if params[:query].present?
  members = members.where(user_id: params[:user_ids]) if params[:user_ids].present?
  members
end