2019-05-17 08:43:03 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Groups::GroupMembersHelper
|
2020-09-11 20:08:44 -04:00
|
|
|
include AvatarsHelper
|
|
|
|
|
|
|
|
AVATAR_SIZE = 40
|
|
|
|
|
2019-05-17 08:43:03 -04:00
|
|
|
def group_member_select_options
|
2019-09-13 09:26:31 -04:00
|
|
|
{ multiple: true, class: 'input-clamp qa-member-select-field ', scope: :all, email_user: true }
|
2019-05-17 08:43:03 -04:00
|
|
|
end
|
2020-01-13 10:07:53 -05:00
|
|
|
|
|
|
|
def render_invite_member_for_group(group, default_access_level)
|
2020-10-01 05:09:54 -04:00
|
|
|
render 'shared/members/invite_member', submit_url: group_group_members_path(group), access_levels: group.access_level_roles, default_access_level: default_access_level
|
2020-01-13 10:07:53 -05:00
|
|
|
end
|
2020-09-11 20:08:44 -04:00
|
|
|
|
|
|
|
def linked_groups_data_json(group_links)
|
2020-09-21 11:09:44 -04:00
|
|
|
GroupGroupLinkSerializer.new.represent(group_links, { current_user: current_user }).to_json
|
2020-09-11 20:08:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def members_data_json(group, members)
|
|
|
|
members_data(group, members).to_json
|
|
|
|
end
|
|
|
|
|
2020-10-12 05:08:38 -04:00
|
|
|
# Overridden in `ee/app/helpers/ee/groups/group_members_helper.rb`
|
|
|
|
def group_members_list_data_attributes(group, members)
|
|
|
|
{
|
|
|
|
members: members_data_json(group, members),
|
|
|
|
member_path: group_group_member_path(group, ':id'),
|
|
|
|
group_id: group.id
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def linked_groups_list_data_attributes(group)
|
|
|
|
{
|
|
|
|
members: linked_groups_data_json(group.shared_with_group_links),
|
2020-10-16 11:08:46 -04:00
|
|
|
member_path: group_group_link_path(group, ':id'),
|
2020-10-12 05:08:38 -04:00
|
|
|
group_id: group.id
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-09-11 20:08:44 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def members_data(group, members)
|
|
|
|
members.map do |member|
|
|
|
|
user = member.user
|
|
|
|
source = member.source
|
|
|
|
|
|
|
|
data = {
|
|
|
|
id: member.id,
|
|
|
|
created_at: member.created_at,
|
|
|
|
expires_at: member.expires_at&.to_time,
|
|
|
|
requested_at: member.requested_at,
|
|
|
|
can_update: member.can_update?,
|
|
|
|
can_remove: member.can_remove?,
|
|
|
|
access_level: {
|
|
|
|
string_value: member.human_access,
|
|
|
|
integer_value: member.access_level
|
|
|
|
},
|
|
|
|
source: {
|
|
|
|
id: source.id,
|
|
|
|
name: source.full_name,
|
|
|
|
web_url: Gitlab::UrlBuilder.build(source)
|
2020-10-07 02:09:03 -04:00
|
|
|
},
|
|
|
|
valid_roles: member.valid_level_roles
|
2020-09-11 20:08:44 -04:00
|
|
|
}.merge(member_created_by_data(member.created_by))
|
|
|
|
|
2020-09-21 11:09:44 -04:00
|
|
|
if member.invite?
|
2020-09-11 20:08:44 -04:00
|
|
|
data[:invite] = member_invite_data(member)
|
2020-09-21 11:09:44 -04:00
|
|
|
elsif user.present?
|
|
|
|
data[:user] = member_user_data(user)
|
2020-09-11 20:08:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
data
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def member_created_by_data(created_by)
|
|
|
|
return {} unless created_by.present?
|
|
|
|
|
|
|
|
{
|
|
|
|
created_by: {
|
|
|
|
name: created_by.name,
|
|
|
|
web_url: Gitlab::UrlBuilder.build(created_by)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def member_user_data(user)
|
|
|
|
{
|
|
|
|
id: user.id,
|
|
|
|
name: user.name,
|
|
|
|
username: user.username,
|
|
|
|
web_url: Gitlab::UrlBuilder.build(user),
|
|
|
|
avatar_url: avatar_icon_for_user(user, AVATAR_SIZE),
|
|
|
|
blocked: user.blocked?,
|
|
|
|
two_factor_enabled: user.two_factor_enabled?
|
2020-09-21 11:09:44 -04:00
|
|
|
}.merge(member_user_status_data(user.status))
|
|
|
|
end
|
|
|
|
|
|
|
|
def member_user_status_data(status)
|
|
|
|
return {} unless status.present?
|
|
|
|
|
|
|
|
{
|
|
|
|
status: {
|
|
|
|
emoji: status.emoji,
|
|
|
|
message_html: status.message_html
|
|
|
|
}
|
2020-09-11 20:08:44 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def member_invite_data(member)
|
|
|
|
{
|
|
|
|
email: member.invite_email,
|
|
|
|
avatar_url: avatar_icon_for_email(member.invite_email, AVATAR_SIZE),
|
|
|
|
can_resend: member.can_resend_invite?
|
|
|
|
}
|
|
|
|
end
|
2019-05-17 08:43:03 -04:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
Groups::GroupMembersHelper.prepend_if_ee('EE::Groups::GroupMembersHelper')
|