Sha256: 7372c82a73043799d5cb3f023e87751b3ea85f83334fa240c6a4637c1b60494d

Contents?: true

Size: 1.16 KB

Versions: 53

Compression:

Stored size: 1.16 KB

Contents

module CurationConcerns
  module Permissions
    module Writable
      extend ActiveSupport::Concern

      # we're overriding the permissions= method which is in Hydra::AccessControls::Permissions
      include Hydra::AccessControls::Permissions
      include Hydra::AccessControls::Visibility

      included do
        validate :paranoid_permissions
      end

      def paranoid_permissions
        valid = true
        paranoid_edit_permissions.each do |validation|
          next unless validation[:condition].call(self)
          errors[validation[:key]] ||= []
          errors[validation[:key]] << validation[:message]
          valid = false
        end
        valid
      end

      def paranoid_edit_permissions
        [
          { key: :edit_users, message: 'Depositor must have edit access', condition: ->(obj) { !obj.edit_users.include?(obj.depositor) } },
          { key: :edit_groups, message: 'Public cannot have edit access', condition: ->(obj) { obj.edit_groups.include?('public') } },
          { key: :edit_groups, message: 'Registered cannot have edit access', condition: ->(obj) { obj.edit_groups.include?('registered') } }
        ]
      end
    end
  end
end

Version data entries

53 entries across 53 versions & 2 rubygems

Version Path
curation_concerns-1.0.0.beta5 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-1.0.0.beta4 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-1.0.0.beta3 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-1.0.0.beta2 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-1.0.0.beta1 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-0.14.0 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-0.14.0.pre4 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-0.14.0.pre3 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-0.14.0.pre2 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-0.14.0.pre1 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-0.13.1 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-0.13.0 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-0.12.0 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-0.12.0.pre9 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-0.12.0.pre8 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-0.12.0.pre7 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-0.12.0.pre6 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-0.12.0.pre5 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-0.12.0.pre4 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-0.12.0.pre3 app/models/concerns/curation_concerns/permissions/writable.rb