Sha256: a4665e46ef23b5782cb0cdaa1aa6aec6eb4733b898de510a3056cfeec99512af

Contents?: true

Size: 1.04 KB

Versions: 49

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Decidim
  module UserGroups
    # 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 AcceptedUserGroups < Rectify::Query
      # Syntactic sugar to initialize the class and return the queried objects.
      #
      # user - a User that needs to find the groups where they are accepted
      def self.for(user)
        new(user).query
      end

      # Initializes the class.
      #
      # user - a User that needs to find the groups where they are accepted
      def initialize(user)
        @user = user
      end

      # Finds the UserGroups where the user has an accepted membership.
      #
      # Returns an ActiveRecord::Relation.
      def query
        user
          .user_groups
          .includes(:memberships)
          .where(decidim_user_group_memberships: { role: %w(creator admin member) })
      end

      private

      attr_reader :user
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
decidim-core-0.26.10 app/queries/decidim/user_groups/accepted_user_groups.rb
decidim-core-0.26.9 app/queries/decidim/user_groups/accepted_user_groups.rb
decidim-core-0.26.8 app/queries/decidim/user_groups/accepted_user_groups.rb
decidim-core-0.26.7 app/queries/decidim/user_groups/accepted_user_groups.rb
decidim-core-0.26.5 app/queries/decidim/user_groups/accepted_user_groups.rb
decidim-core-0.26.4 app/queries/decidim/user_groups/accepted_user_groups.rb
decidim-core-0.26.3 app/queries/decidim/user_groups/accepted_user_groups.rb
decidim-core-0.26.2 app/queries/decidim/user_groups/accepted_user_groups.rb
decidim-core-0.26.1 app/queries/decidim/user_groups/accepted_user_groups.rb
decidim-core-0.26.0 app/queries/decidim/user_groups/accepted_user_groups.rb
decidim-core-0.26.0.rc2 app/queries/decidim/user_groups/accepted_user_groups.rb
decidim-core-0.26.0.rc1 app/queries/decidim/user_groups/accepted_user_groups.rb
decidim-core-0.25.2 app/queries/decidim/user_groups/accepted_user_groups.rb
decidim-core-0.25.1 app/queries/decidim/user_groups/accepted_user_groups.rb
decidim-core-0.25.0 app/queries/decidim/user_groups/accepted_user_groups.rb
decidim-core-0.25.0.rc4 app/queries/decidim/user_groups/accepted_user_groups.rb
decidim-core-0.25.0.rc3 app/queries/decidim/user_groups/accepted_user_groups.rb
decidim-core-0.25.0.rc2 app/queries/decidim/user_groups/accepted_user_groups.rb
decidim-core-0.25.0.rc1 app/queries/decidim/user_groups/accepted_user_groups.rb
decidim-core-0.24.3 app/queries/decidim/user_groups/accepted_user_groups.rb