Sha256: 01ed52f32a994566ef27a5c792efe0b4eb88935f1bbe358819283931aeae0e35

Contents?: true

Size: 897 Bytes

Versions: 24

Compression:

Stored size: 897 Bytes

Contents

module Ddr::Batch

  class BatchObjectRole < ActiveRecord::Base
    belongs_to :batch_object, :inverse_of => :batch_object_roles

    OPERATION_ADD = "ADD".freeze  # Add the principal and role to the object in the indicated scope
    OPERATIONS = [ OPERATION_ADD ].freeze

    validates :operation, inclusion: { in: OPERATIONS }
    validate :valid_role, if: :operation_requires_valid_role?
    validate :policy_role_scope_only_for_collections, if: "role_scope == Ddr::Auth::Roles::POLICY_SCOPE"

    def operation_requires_valid_role?
      [ OPERATION_ADD ].include? operation
    end

    def valid_role
      Ddr::Auth::Roles::Role.build(type: role_type, agent: agent, scope: role_scope).valid?
    end

    def policy_role_scope_only_for_collections
      errors.add(:role_scope, "policy role scope is valid only for Collections") unless batch_object.model == "Collection"
    end
  end

end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
ddr-batch-1.7.2 app/models/ddr/batch/batch_object_role.rb
ddr-batch-1.7.1 app/models/ddr/batch/batch_object_role.rb
ddr-batch-1.7.0 app/models/ddr/batch/batch_object_role.rb
ddr-batch-1.6.1 app/models/ddr/batch/batch_object_role.rb
ddr-batch-1.6.0 app/models/ddr/batch/batch_object_role.rb
ddr-batch-1.6.0.rc1 app/models/ddr/batch/batch_object_role.rb
ddr-batch-1.5.1 app/models/ddr/batch/batch_object_role.rb
ddr-batch-1.5.0 app/models/ddr/batch/batch_object_role.rb
ddr-batch-1.5.0.rc1 app/models/ddr/batch/batch_object_role.rb
ddr-batch-1.4.1 app/models/ddr/batch/batch_object_role.rb
ddr-batch-1.4.0 app/models/ddr/batch/batch_object_role.rb
ddr-batch-1.4.0.rc1 app/models/ddr/batch/batch_object_role.rb
ddr-batch-1.3.0 app/models/ddr/batch/batch_object_role.rb
ddr-batch-1.3.0.rc1 app/models/ddr/batch/batch_object_role.rb
ddr-batch-1.2.0 app/models/ddr/batch/batch_object_role.rb
ddr-batch-1.2.0.rc6 app/models/ddr/batch/batch_object_role.rb
ddr-batch-1.2.0.rc5 app/models/ddr/batch/batch_object_role.rb
ddr-batch-1.2.0.rc4 app/models/ddr/batch/batch_object_role.rb
ddr-batch-1.2.0.rc3 app/models/ddr/batch/batch_object_role.rb
ddr-batch-1.2.0.rc2 app/models/ddr/batch/batch_object_role.rb