2018-09-14 01:42:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-07 04:11:41 -05:00
|
|
|
module RendersMemberAccess
|
|
|
|
def prepare_groups_for_rendering(groups)
|
|
|
|
preload_max_member_access_for_collection(Group, groups)
|
|
|
|
|
|
|
|
groups
|
|
|
|
end
|
|
|
|
|
|
|
|
def prepare_projects_for_rendering(projects)
|
|
|
|
preload_max_member_access_for_collection(Project, projects)
|
|
|
|
|
|
|
|
projects
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-12-07 04:11:41 -05:00
|
|
|
def preload_max_member_access_for_collection(klass, collection)
|
|
|
|
return if !current_user || collection.blank?
|
|
|
|
|
|
|
|
method_name = "max_member_access_for_#{klass.name.underscore}_ids"
|
|
|
|
|
|
|
|
current_user.public_send(method_name, collection.ids) # rubocop:disable GitlabSecurity/PublicSend
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-12-07 04:11:41 -05:00
|
|
|
end
|