Sha256: d0d1f62ce93c12bb91966f8460e4734ca4a4fa2464f730d9cdd1dffb22a4a7f9

Contents?: true

Size: 1.3 KB

Versions: 40

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module Decidim
  module Verifications
    # Finds authorizations by different criteria
    class Authorizations < Rectify::Query
      # Initializes the class.
      #
      # @param organization [Organization] The organization where this authorization belongs to
      # @param name [String] The name of an authorization method
      # @param user [User] A user to find authorizations for
      # @param granted [Boolean] Whether the authorization is granted or not
      def initialize(organization:, user: nil, name: nil, granted: nil)
        @organization = organization
        @user = user
        @name = name
        @granted = granted
      end

      # Finds the Authorizations for the given method
      #
      # Returns an ActiveRecord::Relation.
      def query
        scope = Decidim::Authorization.left_outer_joins(:organization).where(decidim_organizations: { id: organization.id })

        scope = scope.where(name: name) unless name.nil?
        scope = scope.where(user: user) unless user.nil?

        if granted == true
          scope = scope.where.not(granted_at: nil)
        elsif granted == false
          scope = scope.where(granted_at: nil)
        end

        scope
      end

      private

      attr_reader :user, :name, :granted, :organization
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
decidim-verifications-0.23.6 app/queries/decidim/verifications/authorizations.rb
decidim-verifications-0.23.5 app/queries/decidim/verifications/authorizations.rb
decidim-verifications-0.23.4 app/queries/decidim/verifications/authorizations.rb
decidim-verifications-0.23.3 app/queries/decidim/verifications/authorizations.rb
decidim-verifications-0.23.2 app/queries/decidim/verifications/authorizations.rb
decidim-verifications-0.23.1 app/queries/decidim/verifications/authorizations.rb
decidim-verifications-0.23.1.rc1 app/queries/decidim/verifications/authorizations.rb
decidim-verifications-0.23.0 app/queries/decidim/verifications/authorizations.rb
decidim-verifications-0.22.0 app/queries/decidim/verifications/authorizations.rb
decidim-verifications-0.21.0 app/queries/decidim/verifications/authorizations.rb
decidim-verifications-0.20.1 app/queries/decidim/verifications/authorizations.rb
decidim-verifications-0.20.0 app/queries/decidim/verifications/authorizations.rb
decidim-verifications-0.19.1 app/queries/decidim/verifications/authorizations.rb
decidim-verifications-0.18.1 app/queries/decidim/verifications/authorizations.rb
decidim-verifications-0.19.0 app/queries/decidim/verifications/authorizations.rb
decidim-verifications-0.17.2 app/queries/decidim/verifications/authorizations.rb
decidim-verifications-0.18.0 app/queries/decidim/verifications/authorizations.rb
decidim-verifications-0.17.1 app/queries/decidim/verifications/authorizations.rb
decidim-verifications-0.16.1 app/queries/decidim/verifications/authorizations.rb
decidim-verifications-0.17.0 app/queries/decidim/verifications/authorizations.rb