debian-mirror-gitlab/lib/api/helpers/members_helpers.rb

69 lines
2.3 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
module API
module Helpers
module MembersHelpers
2020-03-13 15:44:24 +05:30
extend Grape::API::Helpers
params :optional_filter_params_ee do
end
2016-09-13 17:45:13 +05:30
def find_source(source_type, id)
2018-03-17 18:26:18 +05:30
public_send("find_#{source_type}!", id) # rubocop:disable GitlabSecurity/PublicSend
2016-09-13 17:45:13 +05:30
end
def authorize_admin_source!(source_type, source)
authorize! :"admin_#{source_type}", source
end
2018-11-18 11:00:15 +05:30
2020-01-01 13:55:28 +05:30
# rubocop: disable CodeReuse/ActiveRecord
def retrieve_members(source, params:, deep: false)
2021-06-08 01:23:25 +05:30
members = deep ? find_all_members(source) : source_members(source).connected_to_user
2020-01-01 13:55:28 +05:30
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
2021-01-29 00:20:46 +05:30
def retrieve_member_invitations(source, query = nil)
members = source_members(source).where.not(invite_token: nil)
members = members.includes(:user)
members = members.where(invite_email: query) if query.present?
members
end
def source_members(source)
source.members
end
2020-01-01 13:55:28 +05:30
# rubocop: enable CodeReuse/ActiveRecord
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
2018-11-18 11:00:15 +05:30
end
def find_all_members_for_project(project)
2021-02-22 17:27:13 +05:30
MembersFinder.new(project, current_user).execute(include_relations: [:inherited, :direct, :invited_groups])
2018-11-18 11:00:15 +05:30
end
def find_all_members_for_group(group)
2019-09-04 21:01:54 +05:30
GroupMembersFinder.new(group).execute
2018-11-18 11:00:15 +05:30
end
2020-01-01 13:55:28 +05:30
2020-03-13 15:44:24 +05:30
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
2020-01-01 13:55:28 +05:30
def present_members(members)
2020-03-13 15:44:24 +05:30
present members, with: Entities::Member, current_user: current_user, show_seat_info: params[:show_seat_info]
2020-01-01 13:55:28 +05:30
end
2021-01-29 00:20:46 +05:30
def present_member_invitations(invitations)
present invitations, with: Entities::Invitation, current_user: current_user
end
2016-09-13 17:45:13 +05:30
end
end
end
2020-03-13 15:44:24 +05:30
2021-06-08 01:23:25 +05:30
API::Helpers::MembersHelpers.prepend_mod_with('API::Helpers::MembersHelpers')