-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional triples for implied permissions, return effective mode…
…s by default
- Loading branch information
Showing
2 changed files
with
72 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,49 @@ def type | |
parsed_agent.first | ||
end | ||
|
||
# @param (optional) [Hash] opts will return the actual modes if { actual: true } is supplied | ||
def mode(opts={}) | ||
return super if opts.fetch(:actual, false) | ||
effective_mode(super) | ||
end | ||
|
||
def effective_mode(actual_modes) | ||
[ModeMap.new(actual_modes).resulting_mode] | ||
end | ||
|
||
# Internal class used to determine the resulting mode, either ACL.Write, ACL.Read, or Hydra::ACL.Discover, | ||
# based on the actual modes found in Hydra::AccessControls::Permission::mode | ||
# The resulting mode versus the actual modes are defined as follows: | ||
# Actual modes | Resulting mode | ||
# ---------------------------------------- | -------------------- | ||
# Hydra::ACL.Discover | Hydra::ACL.Discover | ||
# Hydra::ACL.Discover, ACL.Read | ACL.Read | ||
# Hydra::ACL.Discover, ACL.Read, ACL.Write | ACL.Write | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
awead
Author
Contributor
|
||
class ModeMap | ||
attr_reader :modes | ||
def initialize(modes) | ||
@modes = modes | ||
end | ||
|
||
def resulting_mode | ||
return map[ACL.Write.to_s] if map.keys.include?(ACL.Write) | ||
return map[ACL.Read.to_s] if map.keys.include?(ACL.Read) | ||
return map[Hydra::ACL.Discover.to_s] if map.keys.include?(Hydra::ACL.Discover) | ||
modes | ||
end | ||
|
||
def map | ||
@map ||= new_map | ||
end | ||
|
||
private | ||
def new_map | ||
result = {} | ||
modes.each { |mode| result[mode.id] = mode } | ||
result | ||
end | ||
end | ||
|
||
protected | ||
|
||
def parsed_agent | ||
|
@@ -71,9 +114,9 @@ def build_access(access) | |
raise "Can't build access #{inspect}" unless access | ||
self.mode = case access | ||
when "read" | ||
Mode.new(::ACL.Read) | ||
[Mode.new(::ACL.Read), Mode.new(Hydra::ACL.Discover)] | ||
when "edit" | ||
Mode.new(::ACL.Write) | ||
[Mode.new(::ACL.Write), Mode.new(::ACL.Read), Mode.new(Hydra::ACL.Discover)] | ||
when "discover" | ||
Mode.new(Hydra::ACL.Discover) | ||
else | ||
|
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
What is the behavior if ACL.Write is found but ACL.Read is not?