Class: Decidim::UserGroups::ManageableUserGroups

Inherits:
Rectify::Query
  • Object
show all
Defined in:
app/queries/decidim/user_groups/manageable_user_groups.rb

Overview

Use this class to find the user groups the given user can manage. In order to calculate this, we get those groups where the user has a role of creator or admin.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ ManageableUserGroups

Initializes the class.

user - a User that needs to find which groups can manage



19
20
21
# File 'app/queries/decidim/user_groups/manageable_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 which groups can manage



12
13
14
# File 'app/queries/decidim/user_groups/manageable_user_groups.rb', line 12

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

Instance Method Details

#queryObject

Finds the UserGroups where the user has a role of ‘:admin` or `:creator`.

Returns an ActiveRecord::Relation.



27
28
29
30
31
32
# File 'app/queries/decidim/user_groups/manageable_user_groups.rb', line 27

def query
  user
    .user_groups
    .includes(:memberships)
    .where(decidim_user_group_memberships: { role: %w(admin creator) })
end