2021-01-06 09:10:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Projects::ProjectMembersHelper
|
|
|
|
def can_manage_project_members?(project)
|
|
|
|
can?(current_user, :admin_project_member, project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_groups?(group_links)
|
|
|
|
group_links.exists? || groups_tab_active?
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_invited_members?(project, invited_members)
|
|
|
|
can_manage_project_members?(project) && invited_members.exists?
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_access_requests?(project, requesters)
|
|
|
|
can_manage_project_members?(project) && requesters.exists?
|
|
|
|
end
|
|
|
|
|
|
|
|
def groups_tab_active?
|
|
|
|
params[:search_groups].present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def current_user_is_group_owner?(project)
|
|
|
|
return false if project.group.nil?
|
|
|
|
|
|
|
|
project.group.has_owner?(current_user)
|
|
|
|
end
|
2021-01-22 12:08:52 +00:00
|
|
|
|
2021-05-11 18:10:36 +00:00
|
|
|
def project_members_list_data_json(project, members, pagination = {})
|
|
|
|
project_members_list_data(project, members, pagination).to_json
|
2021-01-22 12:08:52 +00:00
|
|
|
end
|
|
|
|
|
2021-05-11 18:10:36 +00:00
|
|
|
def project_group_links_list_data_json(project, group_links)
|
|
|
|
project_group_links_list_data(project, group_links).to_json
|
2021-01-22 12:08:52 +00:00
|
|
|
end
|
|
|
|
|
2021-05-11 18:10:36 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def project_members_serialized(project, members)
|
|
|
|
MemberSerializer.new.represent(members, { current_user: current_user, group: project.group, source: project })
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_group_links_serialized(group_links)
|
|
|
|
GroupLink::ProjectGroupLinkSerializer.new.represent(group_links, { current_user: current_user })
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_members_list_data(project, members, pagination)
|
2021-01-22 12:08:52 +00:00
|
|
|
{
|
2021-05-11 18:10:36 +00:00
|
|
|
members: project_members_serialized(project, members),
|
|
|
|
pagination: members_pagination_data(members, pagination),
|
2021-01-22 12:08:52 +00:00
|
|
|
member_path: project_project_member_path(project, ':id'),
|
|
|
|
source_id: project.id,
|
2021-05-11 18:10:36 +00:00
|
|
|
can_manage_members: can_manage_project_members?(project)
|
2021-01-22 12:08:52 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-05-11 18:10:36 +00:00
|
|
|
def project_group_links_list_data(project, group_links)
|
2021-01-22 12:08:52 +00:00
|
|
|
{
|
2021-05-11 18:10:36 +00:00
|
|
|
members: project_group_links_serialized(group_links),
|
|
|
|
pagination: members_pagination_data(group_links),
|
2021-01-22 12:08:52 +00:00
|
|
|
member_path: project_group_link_path(project, ':id'),
|
|
|
|
source_id: project.id,
|
2021-05-11 18:10:36 +00:00
|
|
|
can_manage_members: can_manage_project_members?(project)
|
2021-01-22 12:08:52 +00:00
|
|
|
}
|
|
|
|
end
|
2021-01-06 09:10:31 +00:00
|
|
|
end
|