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
|
|
|
|
2021-08-11 14:10:52 -04:00
|
|
|
def group_members_app_data(group, members:, invited:, access_requests:)
|
2021-05-19 20:10:36 -04:00
|
|
|
{
|
|
|
|
user: group_members_list_data(group, members, { param_name: :page, params: { invited_members_page: nil, search_invited: nil } }),
|
|
|
|
group: group_group_links_list_data(group),
|
|
|
|
invite: group_members_list_data(group, invited.nil? ? [] : invited, { param_name: :invited_members_page, params: { page: nil } }),
|
|
|
|
access_request: group_members_list_data(group, access_requests.nil? ? [] : access_requests),
|
|
|
|
source_id: group.id,
|
|
|
|
can_manage_members: can?(current_user, :admin_group_member, group)
|
2021-08-11 14:10:52 -04:00
|
|
|
}
|
2021-05-11 14:10:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def group_members_serialized(group, members)
|
|
|
|
MemberSerializer.new.represent(members, { current_user: current_user, group: group, source: group })
|
|
|
|
end
|
|
|
|
|
|
|
|
def group_group_links_serialized(group_links)
|
|
|
|
GroupLink::GroupGroupLinkSerializer.new.represent(group_links, { current_user: current_user })
|
2020-09-11 20:08:44 -04:00
|
|
|
end
|
|
|
|
|
2020-10-12 05:08:38 -04:00
|
|
|
# Overridden in `ee/app/helpers/ee/groups/group_members_helper.rb`
|
2021-05-19 20:10:36 -04:00
|
|
|
def group_members_list_data(group, members, pagination = {})
|
2020-10-12 05:08:38 -04:00
|
|
|
{
|
2021-05-11 14:10:36 -04:00
|
|
|
members: group_members_serialized(group, members),
|
|
|
|
pagination: members_pagination_data(members, pagination),
|
2021-05-19 20:10:36 -04:00
|
|
|
member_path: group_group_member_path(group, ':id')
|
2020-10-12 05:08:38 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-05-11 14:10:36 -04:00
|
|
|
def group_group_links_list_data(group)
|
2021-04-22 08:09:49 -04:00
|
|
|
group_links = group.shared_with_group_links
|
|
|
|
|
2020-10-12 05:08:38 -04:00
|
|
|
{
|
2021-05-11 14:10:36 -04:00
|
|
|
members: group_group_links_serialized(group_links),
|
|
|
|
pagination: members_pagination_data(group_links),
|
2021-05-19 20:10:36 -04:00
|
|
|
member_path: group_group_link_path(group, ':id')
|
2020-10-12 05:08:38 -04:00
|
|
|
}
|
|
|
|
end
|
2019-05-17 08:43:03 -04:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Groups::GroupMembersHelper.prepend_mod_with('Groups::GroupMembersHelper')
|