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-04-29 08:09:58 -04:00
|
|
|
Feature.enabled?(:invite_members_group_modal, project.group) && can_manage_project_members?(project)
|
2021-01-19 13:11:04 -05:00
|
|
|
end
|
|
|
|
|
2021-05-06 08:10:38 -04:00
|
|
|
def can_invite_group_for_project?(project)
|
|
|
|
Feature.enabled?(:invite_members_group_modal, project.group) && project.allowed_to_share_with_group?
|
|
|
|
end
|
|
|
|
|
2020-10-14 14:08:47 -04:00
|
|
|
def directly_invite_members?
|
|
|
|
strong_memoize(:directly_invite_members) do
|
2021-03-09 07:08:52 -05:00
|
|
|
can_import_members?
|
2020-10-14 14:08:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-26 11:08:40 -04:00
|
|
|
def invite_group_members?(group)
|
|
|
|
experiment_enabled?(:invite_members_empty_group_version_a) && Ability.allowed?(current_user, :admin_group_member, group)
|
|
|
|
end
|
2020-12-22 16:10:06 -05:00
|
|
|
|
|
|
|
def dropdown_invite_members_link(form_model)
|
|
|
|
link_to invite_members_url(form_model),
|
|
|
|
data: {
|
|
|
|
'track-event': 'click_link',
|
2021-01-19 13:11:04 -05:00
|
|
|
'track-label': tracking_label,
|
|
|
|
'track-property': experiment_tracking_category_and_group(:invite_members_new_dropdown)
|
2020-12-22 16:10:06 -05:00
|
|
|
} do
|
|
|
|
invite_member_link_content
|
|
|
|
end
|
|
|
|
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
|
|
|
|
|
2020-12-22 16:10:06 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def invite_members_url(form_model)
|
|
|
|
case form_model
|
|
|
|
when Project
|
|
|
|
project_project_members_path(form_model)
|
|
|
|
when Group
|
|
|
|
group_group_members_path(form_model)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def invite_member_link_content
|
|
|
|
text = s_('InviteMember|Invite members')
|
|
|
|
|
|
|
|
return text unless experiment_enabled?(:invite_members_new_dropdown)
|
|
|
|
|
|
|
|
"#{text} #{emoji_icon('shaking_hands', 'aria-hidden': true, class: 'gl-font-base gl-vertical-align-baseline')}".html_safe
|
|
|
|
end
|
2020-09-28 11:09:44 -04:00
|
|
|
end
|