Class: API::Entities::ProjectWithAccess

Inherits:
Project show all
Defined in:
lib/api/entities/project_with_access.rb

Class Method Summary collapse

Methods inherited from Project

forks_counting_projects

Methods included from Helpers::RelatedResourcesHelpers

#expose_path, #expose_url, #issues_available?, #mrs_available?

Class Method Details

.preload_relation(projects_relation, options = {}) ⇒ Object

rubocop: disable CodeReuse/ActiveRecord


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/api/entities/project_with_access.rb', line 27

def self.preload_relation(projects_relation, options = {})
  relation = super(projects_relation, options)
  project_ids = relation.select('projects.id')
  namespace_ids = relation.select(:namespace_id)

  options[:project_members] = options[:current_user]
    .project_members
    .where(source_id: project_ids)
    .preload(:source, user: [notification_settings: :source])

  options[:group_members] = options[:current_user]
    .group_members
    .where(source_id: namespace_ids)
    .preload(:source, user: [notification_settings: :source])

  relation
end