Sha256: a38fd3e984e0c73d98969921268c7db6194d35293cbe6074486af64d962440ca

Contents?: true

Size: 887 Bytes

Versions: 5

Compression:

Stored size: 887 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # An authorization is a record that a User has been authorized somehow. Other
  # models in the system can use different kind of authorizations to allow a
  # user to perform actions.
  #
  # To create an authorization for a user we need to use an
  # AuthorizationHandler that validates the user against a set of rules. An
  # example could be a handler that validates a user email against an API and
  # depending on the response it allows the creation of the authorization or
  # not.
  class Authorization < ApplicationRecord
    belongs_to :user, foreign_key: "decidim_user_id", class_name: "Decidim::User", inverse_of: :authorizations

    validates :name, uniqueness: { scope: :decidim_user_id }

    validate :active_handler?

    private

    def active_handler?
      AuthorizationHandler.active_handler?(name)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
decidim-core-0.7.4 app/models/decidim/authorization.rb
decidim-core-0.7.3 app/models/decidim/authorization.rb
decidim-core-0.7.2 app/models/decidim/authorization.rb
decidim-core-0.7.1 app/models/decidim/authorization.rb
decidim-core-0.7.0 app/models/decidim/authorization.rb