2019-09-04 21:01:54 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Groups::GroupMembersHelper
|
2020-11-24 15:15:51 +05:30
|
|
|
include AvatarsHelper
|
|
|
|
|
|
|
|
AVATAR_SIZE = 40
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
def group_member_select_options
|
2019-12-04 20:38:33 +05:30
|
|
|
{ multiple: true, class: 'input-clamp qa-member-select-field ', scope: :all, email_user: true }
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
def group_members_app_data(group, members:, invited:, access_requests:, include_relations:, search:)
|
2021-09-04 01:27:46 +05:30
|
|
|
{
|
|
|
|
user: group_members_list_data(group, members, { param_name: :page, params: { invited_members_page: nil, search_invited: nil } }),
|
2022-06-21 17:19:12 +05:30
|
|
|
group: group_group_links_list_data(group, include_relations, search),
|
2021-09-04 01:27:46 +05:30
|
|
|
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-10-27 15:23:28 +05:30
|
|
|
}
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def group_members_serialized(group, members)
|
|
|
|
MemberSerializer.new.represent(members, { current_user: current_user, group: group, source: group })
|
|
|
|
end
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
def group_group_links_serialized(group, group_links)
|
|
|
|
GroupLink::GroupGroupLinkSerializer.new.represent(group_links, { current_user: current_user, source: group })
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
# Overridden in `ee/app/helpers/ee/groups/group_members_helper.rb`
|
2021-09-04 01:27:46 +05:30
|
|
|
def group_members_list_data(group, members, pagination = {})
|
2021-01-03 14:25:43 +05:30
|
|
|
{
|
2021-06-08 01:23:25 +05:30
|
|
|
members: group_members_serialized(group, members),
|
|
|
|
pagination: members_pagination_data(members, pagination),
|
2021-09-04 01:27:46 +05:30
|
|
|
member_path: group_group_member_path(group, ':id')
|
2021-01-03 14:25:43 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
def group_group_links(group, include_relations)
|
|
|
|
group_links = case include_relations
|
|
|
|
when [:direct]
|
|
|
|
group.shared_with_group_links
|
|
|
|
when [:inherited]
|
|
|
|
group.shared_with_group_links.of_ancestors
|
|
|
|
else
|
|
|
|
group.shared_with_group_links.of_ancestors_and_self
|
|
|
|
end
|
|
|
|
|
|
|
|
group_links.distinct_on_shared_with_group_id_with_group_access
|
|
|
|
end
|
|
|
|
|
|
|
|
def group_group_links_list_data(group, include_relations, search)
|
|
|
|
if ::Feature.enabled?(:group_member_inherited_group, group, default_enabled: :yaml)
|
|
|
|
group_links = group_group_links(group, include_relations)
|
|
|
|
group_links = group_links.search(search) if search
|
|
|
|
else
|
|
|
|
group_links = group.shared_with_group_links
|
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
{
|
2022-06-21 17:19:12 +05:30
|
|
|
members: group_group_links_serialized(group, group_links),
|
2021-06-08 01:23:25 +05:30
|
|
|
pagination: members_pagination_data(group_links),
|
2021-09-04 01:27:46 +05:30
|
|
|
member_path: group_group_link_path(group, ':id')
|
2021-01-03 14:25:43 +05:30
|
|
|
}
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
Groups::GroupMembersHelper.prepend_mod_with('Groups::GroupMembersHelper')
|