Class: Decidim::Assemblies::AssembliesWithUserRole

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

Overview

A class used to find the Assemblies that the given user has the specific role privilege.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, role = :any) ⇒ AssembliesWithUserRole

Initializes the class.

user - a User that needs to find which assemblies can manage role - (optional) a Symbol to specify the role privilege


20
21
22
23
# File 'decidim-assemblies/app/queries/decidim/assemblies/assemblies_with_user_role.rb', line 20

def initialize(user, role = :any)
  @user = user
  @role = role
end

Class Method Details

.for(user, role = :any) ⇒ Object

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

user - a User that needs to find which assemblies can manage role - (optional) a Symbol to specify the role privilege


12
13
14
# File 'decidim-assemblies/app/queries/decidim/assemblies/assemblies_with_user_role.rb', line 12

def self.for(user, role = :any)
  new(user, role).query
end

Instance Method Details

#queryObject

Finds the Assemblies that the given user has role privileges. If the special role ':any' is provided it returns all assemblies where the user has some kind of role privilege.

Returns an ActiveRecord::Relation.


30
31
32
33
34
35
# File 'decidim-assemblies/app/queries/decidim/assemblies/assemblies_with_user_role.rb', line 30

def query
  # Admin users have all role privileges for all organization assemblies
  return Assemblies::OrganizationAssemblies.new(user.organization).query if user.admin?

  Assembly.where(id: assembly_ids)
end