2018-09-29 18:34:47 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-03 22:20:34 -04:00
|
|
|
# rubocop:disable GitlabSecurity/PublicSend
|
|
|
|
|
2016-06-23 11:14:31 -04:00
|
|
|
module API
|
|
|
|
module Helpers
|
|
|
|
module MembersHelpers
|
2019-12-26 13:07:46 -05:00
|
|
|
extend Grape::API::Helpers
|
|
|
|
|
|
|
|
params :optional_filter_params_ee do
|
|
|
|
end
|
|
|
|
|
2016-06-23 11:14:31 -04:00
|
|
|
def find_source(source_type, id)
|
2017-08-03 22:20:34 -04:00
|
|
|
public_send("find_#{source_type}!", id) # rubocop:disable GitlabSecurity/PublicSend
|
2016-06-23 11:14:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_admin_source!(source_type, source)
|
|
|
|
authorize! :"admin_#{source_type}", source
|
|
|
|
end
|
2018-07-25 17:45:42 -04:00
|
|
|
|
2019-11-22 01:06:20 -05:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
def retrieve_members(source, params:, deep: false)
|
2020-11-02 10:08:52 -05:00
|
|
|
members = deep ? find_all_members(source) : source_members(source).where.not(user_id: nil)
|
2019-11-22 01:06:20 -05:00
|
|
|
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
|
2020-11-02 10:08:52 -05:00
|
|
|
|
2020-11-16 10:09:23 -05:00
|
|
|
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
|
|
|
|
|
2020-11-02 10:08:52 -05:00
|
|
|
def source_members(source)
|
|
|
|
source.members
|
|
|
|
end
|
2019-11-22 01:06:20 -05:00
|
|
|
# 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-07-25 17:45:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def find_all_members_for_project(project)
|
2019-12-13 10:08:02 -05:00
|
|
|
MembersFinder.new(project, current_user).execute(include_relations: [:inherited, :direct, :invited_groups_members])
|
2018-07-25 17:45:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def find_all_members_for_group(group)
|
2019-01-29 13:10:37 -05:00
|
|
|
GroupMembersFinder.new(group).execute
|
2018-07-25 17:45:42 -04:00
|
|
|
end
|
2019-11-22 01:06:20 -05:00
|
|
|
|
2020-01-14 16:07:45 -05:00
|
|
|
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
|
|
|
|
|
2019-11-22 01:06:20 -05:00
|
|
|
def present_members(members)
|
2020-01-22 13:08:47 -05:00
|
|
|
present members, with: Entities::Member, current_user: current_user, show_seat_info: params[:show_seat_info]
|
2019-11-22 01:06:20 -05:00
|
|
|
end
|
2020-11-16 10:09:23 -05:00
|
|
|
|
|
|
|
def present_member_invitations(invitations)
|
|
|
|
present invitations, with: Entities::Invitation, current_user: current_user
|
|
|
|
end
|
2016-06-23 11:14:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-26 13:07:46 -05:00
|
|
|
|
|
|
|
API::Helpers::MembersHelpers.prepend_if_ee('EE::API::Helpers::MembersHelpers')
|