2020-09-28 11:09:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module InviteMembersHelper
|
2020-10-14 14:08:47 -04:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2021-01-19 13:11:04 -05:00
|
|
|
def can_invite_members_for_project?(project)
|
2021-08-18 20:11:16 -04:00
|
|
|
# do not use the can_admin_project_member? helper here due to structure of the view and how membership_locked?
|
|
|
|
# is leveraged for inviting groups
|
2022-03-08 01:14:50 -05:00
|
|
|
can?(current_user, :admin_project_member, project)
|
2021-01-19 13:11:04 -05:00
|
|
|
end
|
|
|
|
|
2021-04-22 05:09:45 -04:00
|
|
|
def invite_accepted_notice(member)
|
|
|
|
case member.source
|
|
|
|
when Project
|
|
|
|
_("You have been granted %{member_human_access} access to project %{name}.") %
|
|
|
|
{ member_human_access: member.human_access, name: member.source.name }
|
|
|
|
when Group
|
|
|
|
_("You have been granted %{member_human_access} access to group %{name}.") %
|
|
|
|
{ member_human_access: member.human_access, name: member.source.name }
|
|
|
|
end
|
|
|
|
end
|
2021-06-14 11:09:48 -04:00
|
|
|
|
2022-02-11 16:12:17 -05:00
|
|
|
def common_invite_group_modal_data(source, member_class, is_project)
|
|
|
|
{
|
|
|
|
id: source.id,
|
2022-04-29 20:09:38 -04:00
|
|
|
root_id: source.root_ancestor.id,
|
2022-02-11 16:12:17 -05:00
|
|
|
name: source.name,
|
|
|
|
default_access_level: Gitlab::Access::GUEST,
|
|
|
|
invalid_groups: source.related_group_ids,
|
|
|
|
help_link: help_page_url('user/permissions'),
|
|
|
|
is_project: is_project,
|
2022-06-16 05:09:15 -04:00
|
|
|
access_levels: member_class.permissible_access_level_roles(current_user, source).to_json
|
2022-04-29 20:09:38 -04:00
|
|
|
}.merge(group_select_data(source))
|
2022-02-11 16:12:17 -05:00
|
|
|
end
|
|
|
|
|
2022-03-30 08:09:14 -04:00
|
|
|
# Overridden in EE
|
2021-08-02 11:08:56 -04:00
|
|
|
def common_invite_modal_dataset(source)
|
|
|
|
dataset = {
|
|
|
|
id: source.id,
|
2022-03-23 14:08:47 -04:00
|
|
|
root_id: source.root_ancestor&.id,
|
2021-08-02 11:08:56 -04:00
|
|
|
name: source.name,
|
2022-02-11 16:12:17 -05:00
|
|
|
default_access_level: Gitlab::Access::GUEST
|
2021-08-02 11:08:56 -04:00
|
|
|
}
|
|
|
|
|
2021-11-18 10:10:19 -05:00
|
|
|
if show_invite_members_for_task?(source)
|
2021-10-25 08:10:19 -04:00
|
|
|
dataset.merge!(
|
|
|
|
tasks_to_be_done_options: tasks_to_be_done_options.to_json,
|
|
|
|
projects: projects_for_source(source).to_json,
|
|
|
|
new_project_path: source.is_a?(Group) ? new_project_path(namespace_id: source.id) : ''
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2021-08-02 11:08:56 -04:00
|
|
|
dataset
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-04-29 20:09:38 -04:00
|
|
|
def group_select_data(source)
|
2022-05-09 11:07:50 -04:00
|
|
|
if source.root_ancestor.prevent_sharing_groups_outside_hierarchy
|
2022-04-29 20:09:38 -04:00
|
|
|
{ groups_filter: 'descendant_groups', parent_id: source.root_ancestor.id }
|
|
|
|
else
|
|
|
|
{}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-12 05:09:05 -04:00
|
|
|
# Overridden in EE
|
|
|
|
def users_filter_data(group)
|
|
|
|
{}
|
|
|
|
end
|
2021-10-25 08:10:19 -04:00
|
|
|
|
2021-11-18 10:10:19 -05:00
|
|
|
def show_invite_members_for_task?(source)
|
|
|
|
return unless current_user
|
2021-10-25 08:10:19 -04:00
|
|
|
|
2022-03-02 07:15:38 -05:00
|
|
|
invite_for_help_continuous_onboarding = source.is_a?(Project) && experiment(:invite_for_help_continuous_onboarding, namespace: source.namespace).assigned.name == 'candidate'
|
2021-11-23 19:12:33 -05:00
|
|
|
params[:open_modal] == 'invite_members_for_task' || invite_for_help_continuous_onboarding
|
2021-10-25 08:10:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def tasks_to_be_done_options
|
|
|
|
::MemberTask::TASKS.keys.map { |task| { value: task, text: localized_tasks_to_be_done_choices[task] } }
|
|
|
|
end
|
|
|
|
|
|
|
|
def projects_for_source(source)
|
|
|
|
projects = source.is_a?(Project) ? [source] : source.projects
|
|
|
|
projects.map { |project| { id: project.id, title: project.title } }
|
|
|
|
end
|
2020-09-28 11:09:44 -04:00
|
|
|
end
|
2022-02-17 07:12:30 -05:00
|
|
|
|
|
|
|
InviteMembersHelper.prepend_mod_with('InviteMembersHelper')
|