Sha256: 28222908cbea6b84fa8b9211b45365d2bc7b6baa4af21b350406dae78e940770

Contents?: true

Size: 1.08 KB

Versions: 13

Compression:

Stored size: 1.08 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

        class_attribute :paranoid_edit_permissions
        self.paranoid_edit_permissions =
          [
            { 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

      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
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
curation_concerns-1.7.8 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-1.7.7 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-2.0.0 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-2.0.0.rc2 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-1.7.6 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-1.7.5 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-1.7.4 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-1.7.3 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-1.7.2 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-2.0.0.rc1 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-1.7.1 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-1.7.0 app/models/concerns/curation_concerns/permissions/writable.rb
curation_concerns-1.7.0.beta1 app/models/concerns/curation_concerns/permissions/writable.rb