Class: Decidim::Assemblies::AssembliesWithUserRole
- Inherits:
-
Query
- Object
- Query
- Decidim::Assemblies::AssembliesWithUserRole
- Defined in:
- 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
-
.for(user, role = :any) ⇒ Object
Syntactic sugar to initialize the class and return the queried objects.
Instance Method Summary collapse
-
#initialize(user, role = :any) ⇒ AssembliesWithUserRole
constructor
Initializes the class.
-
#query ⇒ Object
Finds the Assemblies that the given user has role privileges.
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 '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 '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
#query ⇒ Object
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 '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 |