Class: Decidim::Assemblies::Admin::AdminUsers

Inherits:
Query
  • Object
show all
Defined in:
decidim-assemblies/app/queries/decidim/assemblies/admin/admin_users.rb

Overview

A class used to find the admins for an assembly or an organization assemblies.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Query

#cached_query, #each, #eager?, #exists?, merge, #none?, #relation?, #|

Constructor Details

#initialize(assembly, organization = nil) ⇒ AdminUsers

Initializes the class.

assembly - an assembly that needs to find its assembly admins organization - an organization that needs to find its assembly admins


26
27
28
29
# File 'decidim-assemblies/app/queries/decidim/assemblies/admin/admin_users.rb', line 26

def initialize(assembly, organization = nil)
  @assembly = assembly
  @organization = assembly&.organization || organization
end

Class Method Details

.for(assembly) ⇒ Object

Syntactic sugar to initialize the class and return the queried objects.

assembly - an assembly that needs to find its assembly admins


11
12
13
# File 'decidim-assemblies/app/queries/decidim/assemblies/admin/admin_users.rb', line 11

def self.for(assembly)
  new(assembly).query
end

.for_organization(organization) ⇒ Object

Syntactic sugar to initialize the class and return the queried objects.

organization - an organization that needs to find its assembly admins


18
19
20
# File 'decidim-assemblies/app/queries/decidim/assemblies/admin/admin_users.rb', line 18

def self.for_organization(organization)
  new(nil, organization).query
end

Instance Method Details

#queryObject

Finds organization admins and the users with role admin for the given assembly.

Returns an ActiveRecord::Relation.


34
35
36
# File 'decidim-assemblies/app/queries/decidim/assemblies/admin/admin_users.rb', line 34

def query
  organization.admins.or(assemblies_user_admins)
end