Class: Hydra::AccessControls::AccessRight

Inherits:
Object
  • Object
show all
Defined in:
app/models/concerns/hydra/access_controls/access_right.rb

Constant Summary collapse

PERMISSION_TEXT_VALUE_PUBLIC =

What these groups are called in the Hydra rights assertions:

'public'.freeze
PERMISSION_TEXT_VALUE_AUTHENTICATED =
'registered'.freeze
VISIBILITY_TEXT_VALUE_PUBLIC =

The values that get drawn to the page

'open'.freeze
VISIBILITY_TEXT_VALUE_EMBARGO =
'embargo'.freeze
VISIBILITY_TEXT_VALUE_LEASE =
'lease'.freeze
VISIBILITY_TEXT_VALUE_AUTHENTICATED =
'authenticated'.freeze
VISIBILITY_TEXT_VALUE_PRIVATE =
'restricted'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(permissionable) ⇒ AccessRight

Returns a new instance of AccessRight.

Examples:

file = GenericFile.find('sufia:1234')
access = Sufia::AccessRight.new(file)

Parameters:

  • permissionable (#visibility, #permissions)


19
20
21
# File 'app/models/concerns/hydra/access_controls/access_right.rb', line 19

def initialize(permissionable)
  @permissionable = permissionable
end

Instance Attribute Details

#permissionableObject (readonly)

Returns the value of attribute permissionable.



23
24
25
# File 'app/models/concerns/hydra/access_controls/access_right.rb', line 23

def permissionable
  @permissionable
end

Instance Method Details

#authenticated_only?Boolean Also known as: authenticated_only_access?

Returns:

  • (Boolean)


43
44
45
46
47
# File 'app/models/concerns/hydra/access_controls/access_right.rb', line 43

def authenticated_only?
  return false if open_access?
  has_permission_text_for?(PERMISSION_TEXT_VALUE_AUTHENTICATED) ||
    has_visibility_text_for?(VISIBILITY_TEXT_VALUE_AUTHENTICATED)
end

#open_access?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
# File 'app/models/concerns/hydra/access_controls/access_right.rb', line 28

def open_access?
  return true if has_visibility_text_for?(VISIBILITY_TEXT_VALUE_PUBLIC)
  # We don't want to know if its under embargo, simply does it have a date.
  # In this way, we can properly inform the label input
  persisted_open_access_permission? && !permissionable.embargo_release_date.present?
end

#open_access_with_embargo_release_date?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
# File 'app/models/concerns/hydra/access_controls/access_right.rb', line 35

def open_access_with_embargo_release_date?
  return false unless permissionable_is_embargoable?
  return true if has_visibility_text_for?(VISIBILITY_TEXT_VALUE_EMBARGO)
  # We don't want to know if its under embargo, simply does it have a date.
  # In this way, we can properly inform the label input
  persisted_open_access_permission? && permissionable.embargo_release_date.present?
end

#private?Boolean Also known as: private_access?

Returns:

  • (Boolean)


51
52
53
54
55
56
# File 'app/models/concerns/hydra/access_controls/access_right.rb', line 51

def private?
  return false if open_access?
  return false if authenticated_only?
  return false if open_access_with_embargo_release_date?
  true
end