Sha256: a749f5d479dde0406ba559cf323d5b9914a647d6550f3ced8997cb84f912086a

Contents?: true

Size: 1.57 KB

Versions: 20

Compression:

Stored size: 1.57 KB

Contents

# Copyright © 2012 The Pennsylvania State University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'hydra/datastream/rights_metadata'
# 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

20 entries across 20 versions & 2 rubygems

Version Path
sufia-models-0.1.2 app/models/datastreams/paranoid_rights_datastream.rb
sufia-models-0.1.1 app/models/datastreams/paranoid_rights_datastream.rb
sufia-1.3.0 app/models/datastreams/paranoid_rights_datastream.rb
sufia-models-0.1.0 app/models/datastreams/paranoid_rights_datastream.rb
sufia-models-0.0.2 app/models/datastreams/paranoid_rights_datastream.rb
sufia-models-0.0.1 app/models/datastreams/paranoid_rights_datastream.rb
sufia-1.2.0 app/models/datastreams/paranoid_rights_datastream.rb
sufia-1.1.0 app/models/datastreams/paranoid_rights_datastream.rb
sufia-1.0.0 app/models/datastreams/paranoid_rights_datastream.rb
sufia-0.1.0 app/models/datastreams/paranoid_rights_datastream.rb
sufia-0.0.8 app/models/datastreams/paranoid_rights_datastream.rb
sufia-0.0.7 app/models/datastreams/paranoid_rights_datastream.rb
sufia-0.0.6 app/models/datastreams/paranoid_rights_datastream.rb
sufia-0.0.5 app/models/datastreams/paranoid_rights_datastream.rb
sufia-0.0.4 app/models/datastreams/paranoid_rights_datastream.rb
sufia-0.0.3 app/models/datastreams/paranoid_rights_datastream.rb
sufia-0.0.2 app/models/datastreams/paranoid_rights_datastream.rb
sufia-0.0.1 app/models/datastreams/paranoid_rights_datastream.rb
sufia-0.0.1.pre2 app/models/datastreams/paranoid_rights_datastream.rb
sufia-0.0.1.pre1 app/models/datastreams/paranoid_rights_datastream.rb