Sha256: d25ee7e0d668a441e36342fe4371a4559a64074630099bb8db2471c504bb465a

Contents?: true

Size: 963 Bytes

Versions: 46

Compression:

Stored size: 963 Bytes

Contents

# subclass built-in Hydra RightsDatastream and build in extra model-level validation
class ParanoidRightsDatastream < Hydra::Datastream::RightsMetadata
  use_terminology Hydra::Datastream::RightsMetadata

  VALIDATIONS = [
    {:key => :edit_users, :message => 'Depositor must have edit access', :condition => lambda { |obj| !obj.edit_users.include?(obj.depositor) }},
    {:key => :edit_groups, :message => 'Public cannot have edit access', :condition => lambda { |obj| obj.edit_groups.include?('public') }},
    {:key => :edit_groups, :message => 'Registered cannot have edit access', :condition => lambda { |obj| obj.edit_groups.include?('registered') }}
  ]

  def validate(object)
    valid = true
    VALIDATIONS.each do |validation|
      if validation[:condition].call(object)
        object.errors[validation[:key]] ||= []
        object.errors[validation[:key]] << validation[:message]
        valid = false
      end
    end
    return valid
  end
end

Version data entries

46 entries across 46 versions & 2 rubygems

Version Path
sufia-4.0.0.beta2 sufia-models/app/models/datastreams/paranoid_rights_datastream.rb
sufia-models-4.0.0.beta2 app/models/datastreams/paranoid_rights_datastream.rb
sufia-4.0.0.beta1 sufia-models/app/models/datastreams/paranoid_rights_datastream.rb
sufia-models-4.0.0.beta1 app/models/datastreams/paranoid_rights_datastream.rb
sufia-models-3.7.2 app/models/datastreams/paranoid_rights_datastream.rb
sufia-3.7.2 sufia-models/app/models/datastreams/paranoid_rights_datastream.rb
sufia-models-3.7.1 app/models/datastreams/paranoid_rights_datastream.rb
sufia-3.7.1 sufia-models/app/models/datastreams/paranoid_rights_datastream.rb
sufia-models-3.7.0 app/models/datastreams/paranoid_rights_datastream.rb
sufia-3.7.0 sufia-models/app/models/datastreams/paranoid_rights_datastream.rb
sufia-3.6.1 sufia-models/app/models/datastreams/paranoid_rights_datastream.rb
sufia-models-3.6.1 app/models/datastreams/paranoid_rights_datastream.rb
sufia-3.6.0 sufia-models/app/models/datastreams/paranoid_rights_datastream.rb
sufia-models-3.6.0 app/models/datastreams/paranoid_rights_datastream.rb
sufia-3.5.0 sufia-models/app/models/datastreams/paranoid_rights_datastream.rb
sufia-models-3.5.0 app/models/datastreams/paranoid_rights_datastream.rb
sufia-3.4.0 sufia-models/app/models/datastreams/paranoid_rights_datastream.rb
sufia-models-3.4.0 app/models/datastreams/paranoid_rights_datastream.rb
sufia-3.4.0.rc4 sufia-models/app/models/datastreams/paranoid_rights_datastream.rb
sufia-models-3.4.0.rc4 app/models/datastreams/paranoid_rights_datastream.rb