Class: Decidim::UserGroups::AcceptedUserGroups
- Defined in:
- app/queries/decidim/user_groups/accepted_user_groups.rb
Overview
Use this class to find the user groups the given user is accepted. In order to calculate this, we get those groups where the user has a role of member, creator or admin.
Class Method Summary collapse
-
.for(user) ⇒ Object
Syntactic sugar to initialize the class and return the queried objects.
Instance Method Summary collapse
-
#initialize(user) ⇒ AcceptedUserGroups
constructor
Initializes the class.
-
#query ⇒ Object
Finds the UserGroups where the user has an accepted membership.
Methods inherited from Query
#cached_query, #each, #eager?, #exists?, merge, #none?, #relation?, #|
Constructor Details
#initialize(user) ⇒ AcceptedUserGroups
Initializes the class.
user - a User that needs to find the groups where they are accepted
19 20 21 |
# File 'app/queries/decidim/user_groups/accepted_user_groups.rb', line 19 def initialize(user) @user = user end |
Class Method Details
.for(user) ⇒ Object
Syntactic sugar to initialize the class and return the queried objects.
user - a User that needs to find the groups where they are accepted
12 13 14 |
# File 'app/queries/decidim/user_groups/accepted_user_groups.rb', line 12 def self.for(user) new(user).query end |
Instance Method Details
#query ⇒ Object
Finds the UserGroups where the user has an accepted membership.
Returns an ActiveRecord::Relation.
26 27 28 29 30 31 |
# File 'app/queries/decidim/user_groups/accepted_user_groups.rb', line 26 def query user .user_groups .includes(:memberships) .where(decidim_user_group_memberships: { role: %w(creator admin member) }) end |