Class: Decidim::UserGroups::AcceptedUserGroups

Inherits:
Rectify::Query
  • Object
show all
Defined in:
decidim-core/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

Instance Method Summary collapse

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 'decidim-core/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 'decidim-core/app/queries/decidim/user_groups/accepted_user_groups.rb', line 12

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

Instance Method Details

#queryObject

Finds the UserGroups where the user has an accepted membership.

Returns an ActiveRecord::Relation.


26
27
28
29
30
31
# File 'decidim-core/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