Created
June 21, 2012 18:22
-
-
Save DanCoughlin/2967556 to your computer and use it in GitHub Desktop.
permissions to prevent updates we don't want
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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