debian-mirror-gitlab/app/helpers/invite_members_helper.rb

91 lines
3 KiB
Ruby
Raw Normal View History

2021-01-03 14:25:43 +05:30
# frozen_string_literal: true
module InviteMembersHelper
include Gitlab::Utils::StrongMemoize
2021-06-08 01:23:25 +05:30
def can_invite_members_for_project?(project)
2021-10-27 15:23:28 +05:30
# 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-05-07 20:08:51 +05:30
can?(current_user, :admin_project_member, project)
2021-01-03 14:25:43 +05:30
end
2021-06-08 01:23:25 +05:30
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-09-04 01:27:46 +05:30
def group_select_data(group)
2022-04-04 11:22:00 +05:30
# This should only be used for groups to load the invite group modal.
# For instance the invite groups modal should not call this from a project scope
# this is only to be called in scope of a group context as noted in this thread
# https://gitlab.com/gitlab-org/gitlab/-/merge_requests/79036#note_821465513
# the group sharing in projects disabling is explained there as well
2021-09-04 01:27:46 +05:30
if group.root_ancestor.namespace_settings.prevent_sharing_groups_outside_hierarchy
{ groups_filter: 'descendant_groups', parent_id: group.root_ancestor.id }
else
{}
2021-03-08 18:12:59 +05:30
end
end
2021-10-27 15:23:28 +05:30
2022-04-04 11:22:00 +05:30
def common_invite_group_modal_data(source, member_class, is_project)
{
id: source.id,
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,
access_levels: member_class.access_level_roles.to_json
}
end
2021-10-27 15:23:28 +05:30
def common_invite_modal_dataset(source)
dataset = {
id: source.id,
name: source.name,
default_access_level: Gitlab::Access::GUEST
}
2022-01-26 12:08:38 +05:30
if show_invite_members_for_task?(source)
2021-12-11 22:18:48 +05:30
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-10-27 15:23:28 +05:30
dataset
end
private
# Overridden in EE
def users_filter_data(group)
{}
end
2021-12-11 22:18:48 +05:30
2022-01-26 12:08:38 +05:30
def show_invite_members_for_task?(source)
return unless current_user
2021-12-11 22:18:48 +05:30
2022-05-07 20:08:51 +05:30
invite_for_help_continuous_onboarding = source.is_a?(Project) && experiment(:invite_for_help_continuous_onboarding, namespace: source.namespace).assigned.name == 'candidate'
2022-01-26 12:08:38 +05:30
params[:open_modal] == 'invite_members_for_task' || invite_for_help_continuous_onboarding
2021-12-11 22:18:48 +05:30
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
2021-01-03 14:25:43 +05:30
end
2022-04-04 11:22:00 +05:30
InviteMembersHelper.prepend_mod_with('InviteMembersHelper')