Class: Decidim::Conferences::ConferencesWithUserRole
- Inherits:
-
Query
- Object
- Query
- Decidim::Conferences::ConferencesWithUserRole
- Defined in:
- app/queries/decidim/conferences/conferences_with_user_role.rb
Overview
A class used to find the Conferences 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) ⇒ ConferencesWithUserRole
constructor
Initializes the class.
-
#query ⇒ Object
Finds the Conferences that the given user has role privileges.
Constructor Details
#initialize(user, role = :any) ⇒ ConferencesWithUserRole
Initializes the class.
user - a User that needs to find which conferences can manage role - (optional) a Symbol to specify the role privilege
20 21 22 23 |
# File 'app/queries/decidim/conferences/conferences_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 conferences can manage role - (optional) a Symbol to specify the role privilege
12 13 14 |
# File 'app/queries/decidim/conferences/conferences_with_user_role.rb', line 12 def self.for(user, role = :any) new(user, role).query end |
Instance Method Details
#query ⇒ Object
Finds the Conferences that the given user has role privileges. If the special role ‘:any’ is provided it returns all conferences where the user has some kind of role privilege.
Returns an ActiveRecord::Relation.
30 31 32 33 34 35 |
# File 'app/queries/decidim/conferences/conferences_with_user_role.rb', line 30 def query # Admin users have all role privileges for all organization conferences return Conferences::OrganizationConferences.new(user.organization).query if user.admin? Conference.where(id: conference_ids) end |