Sha256: 16c42c6a2cf30a330f10f44073bbda5312fa517c977984f4b017f62a6c797819

Contents?: true

Size: 1.2 KB

Versions: 9

Compression:

Stored size: 1.2 KB

Contents

module Ddr
  module Models
    module Governable
      extend ActiveSupport::Concern

      included do
        belongs_to :admin_policy,
                   predicate: ActiveFedora::RDF::ProjectHydra.isGovernedBy,
                   class_name: "Collection"
      end

      def inherited_permissions
        admin_policy ? admin_policy.default_permissions : []
      end

      def inherited_rights
        admin_policy.datastreams[Ddr::Datastreams::DEFAULT_RIGHTS] if admin_policy
      end

      # Creates convenience methods:
      # inherited_discover_users, inherited_discover_groups,
      # inherited_read_users, inherited_read_groups,
      # inherited_edit_user, inherited_edit_groups
      ["discover", "read", "edit"].each do |access|
        ["user", "group"].each do |type|
          define_method("inherited_#{access}_#{type}s") do
            admin_policy ? admin_policy.send("default_#{access}_#{type}s") : []
          end
        end
      end

      def copy_admin_policy_from(other)
        if admin_policy = other.admin_policy
          self.admin_policy = admin_policy
          logger.debug "Copied admin policy from #{other.model_and_id} to #{model_and_id}"
        end
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ddr-models-3.0.0.beta.9 lib/ddr/models/governable.rb
ddr-models-3.0.0.beta.8 lib/ddr/models/governable.rb
ddr-models-3.0.0.beta.7 lib/ddr/models/governable.rb
ddr-models-3.0.0.beta.6 lib/ddr/models/governable.rb
ddr-models-3.0.0.beta.4 lib/ddr/models/governable.rb
ddr-models-3.0.0.beta.3 lib/ddr/models/governable.rb
ddr-models-3.0.0.beta.2 lib/ddr/models/governable.rb
ddr-models-3.0.0.beta.1 lib/ddr/models/governable.rb
ddr-models-3.0.0.alpha.4 lib/ddr/models/governable.rb