Skip to content

Instantly share code, notes, and snippets.

@DanCoughlin
Created June 21, 2012 18:22
Show Gist options
  • Save DanCoughlin/2967556 to your computer and use it in GitHub Desktop.
Save DanCoughlin/2967556 to your computer and use it in GitHub Desktop.
permissions to prevent updates we don't want
module Hydra
module Datastream
class RightsMetadata < ActiveFedora::NokogiriDatastream
# Updates permissions for all of the persons and groups in a hash
# @param params ex. {"group"=>{"group1"=>"discover","group2"=>"edit"}, "person"=>{"person1"=>"read","person2"=>"discover"}}
# Currently restricts actor type to group or person. Any others will be ignored
def update_permissions(params)
params.fetch("group", {}).each_pair {|group_id, access_level| self.permissions({"group"=>group_id}, access_level)}
#params.fetch("person", {}).each_pair {|group_id, access_level| self.permissions({"person"=>group_id}, access_level)}
params.fetch("persion, {}).each_pair do |group_id, access_level|
unless group_id == 'dmc186' and access_level != "edit"?
self.permissions({"person"=>group_id}, access_level)}
end
end
end
end
end
@mjgiarlo
Copy link

module Hydra
module Datastream
class RightsMetadata < ActiveFedora::NokogiriDatastream
# Validates permissions changes
def validate_permissions(type, actor, access_level)
# do some validations, throw some errors, whatever
end
# Wraps permissions with validation
old_permissions = instance_method(:permissions)
define_method(:permissions) do |selector, new_access_level=nil|
type = selector.keys.first.to_sym
actor = selector.values.first
validate_permissions(type, actor, new_access_level)
old_permissions.bind(self).call
end
end
end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment