Sha256: a95ce6a1e03f80e89eab1e6db7b8c296879c5d231391eddd28a9c26e0407b277

Contents?: true

Size: 1.01 KB

Versions: 30

Compression:

Stored size: 1.01 KB

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, :handler, presence: true
    validates :name, uniqueness: { scope: :decidim_user_id }

    # The handler that created this authorization.
    #
    # Returns an instance that inherits from Decidim::AuthorizationHandler.
    def handler
      @handler ||= AuthorizationHandler.handler_for(name, metadata)
    end
  end
end

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
decidim-core-0.5.0 app/models/decidim/authorization.rb
decidim-0.5.0 decidim-core/app/models/decidim/authorization.rb
decidim-core-0.4.4 app/models/decidim/authorization.rb
decidim-core-0.4.2 app/models/decidim/authorization.rb
decidim-core-0.4.1 app/models/decidim/authorization.rb
decidim-core-0.4.3 app/models/decidim/authorization.rb
decidim-core-0.4.0 app/models/decidim/authorization.rb
decidim-core-0.3.2 app/models/decidim/authorization.rb
decidim-core-0.3.1 app/models/decidim/authorization.rb
decidim-core-0.3.0 app/models/decidim/authorization.rb