Sha256: 644476e435d0556bf24140dd2c5f6b0aa6ab7c3ced5612335b43bd6a8fcc0070

Contents?: true

Size: 905 Bytes

Versions: 25

Compression:

Stored size: 905 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module UserGroups
    # Use this class to find the invitations to user groups the given user has.
    class InvitedMemberships < Decidim::Query
      # Syntactic sugar to initialize the class and return the queried objects.
      #
      # user - a User that needs to find which groups they have been invited to
      def self.for(user)
        new(user).query
      end

      # Initializes the class.
      #
      # user - a User that needs to find which groups they have been invited to
      def initialize(user)
        @user = user
      end

      # Finds the UserGroupMemberships the user has been invited to.
      #
      # Returns an ActiveRecord::Relation.
      def query
        user
          .memberships
          .includes(:user_group)
          .where(role: "invited")
      end

      private

      attr_reader :user
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
decidim-core-0.27.2 app/queries/decidim/user_groups/invited_memberships.rb
decidim-core-0.27.1 app/queries/decidim/user_groups/invited_memberships.rb
decidim-core-0.27.0 app/queries/decidim/user_groups/invited_memberships.rb
decidim-core-0.27.0.rc2 app/queries/decidim/user_groups/invited_memberships.rb
decidim-core-0.27.0.rc1 app/queries/decidim/user_groups/invited_memberships.rb