Class: Hyrax::Resource

Inherits:
Valkyrie::Resource
  • Object
show all
Includes:
Naming, WithEvents
Defined in:
app/models/hyrax/resource.rb

Overview

Note:

Hyrax permissions are managed via [Access Control List](en.wikipedia.org/wiki/Access-control_list) style permissions. Legacy Hyrax models powered by ‘ActiveFedora` linked the ACLs from the repository object itself (as an `acl:accessControl` link to a container). Valkyrie models jettison that approach in favor of relying on links back from the permissions using `access_to`. As was the case in the past implementation, we include an object to represent the access list itself (`Hyrax::AccessControl`). This object’s ‘#access_to` is the way Hyrax discovers list entries–it MUST match between the `AccessControl` and its individual `Permissions`.

The effect of this change is that our ‘AccessControl` objects are detached from `Hyrax::Resource` they can (and usually should) be edited and persisted independently from the resource itself.

Some utilitiy methods are provided for ergonomics in transitioning from ‘ActiveFedora`: the `#visibility` accessor, and the `#*_users` and `#*_group` accessors. The main purpose of these is to provide a cached ACL attached to a given Resource instance. However, these will likely be deprecated in the future, and it’s advisable to avoid them in favor of ‘Hyrax::AccessControlList`, `Hyrax::PermissionManager` and/or `Hyrax::VisibilityWriter` (which provide their underlying implementations).

The base Valkyrie model for Hyrax.

Direct Known Subclasses

AdministrativeSet, FileSet, PcdmCollection, Work

Class Method Summary collapse

Instance Method Summary collapse

Methods included from WithEvents

#event_class, #events, #log_event, #stream

Class Method Details

.collection?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/models/hyrax/resource.rb', line 55

def collection?
  pcdm_collection?
end

.file?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'app/models/hyrax/resource.rb', line 61

def file?
  false
end

.file_set?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/models/hyrax/resource.rb', line 67

def file_set?
  false
end

.human_readable_typeString

Returns a human readable name for the model.

Returns:

  • (String)

    a human readable name for the model



49
50
51
# File 'app/models/hyrax/resource.rb', line 49

def human_readable_type
  I18n.translate("hyrax.models.#{model_name.i18n_key}", default: model_name.human)
end

.pcdm_collection?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'app/models/hyrax/resource.rb', line 73

def pcdm_collection?
  false
end

.pcdm_object?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'app/models/hyrax/resource.rb', line 79

def pcdm_object?
  false
end

.to_rdf_representationString

Returns:

  • (String)


93
94
95
# File 'app/models/hyrax/resource.rb', line 93

def to_rdf_representation
  name
end

.work?Boolean

Works are PCDM Objects which are not File Sets.

Returns:

  • (Boolean)


87
88
89
# File 'app/models/hyrax/resource.rb', line 87

def work?
  pcdm_object? && !file_set?
end

Instance Method Details

#==(other) ⇒ Object



152
153
154
# File 'app/models/hyrax/resource.rb', line 152

def ==(other)
  attributes.except(:created_at, :updated_at) == other.attributes.except(:created_at, :updated_at) if other.respond_to?(:attributes)
end

#collection?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'app/models/hyrax/resource.rb', line 110

def collection?
  self.class.collection?
end

#embargoObject



175
176
177
178
# File 'app/models/hyrax/resource.rb', line 175

def embargo
  return @embargo if @embargo
  @embargo = Hyrax.query_service.find_by(id: embargo_id) if embargo_id.present?
end

#embargo=(value) ⇒ Object



168
169
170
171
172
173
# File 'app/models/hyrax/resource.rb', line 168

def embargo=(value)
  raise TypeError "can't convert #{value.class} into Hyrax::Embargo" unless value.is_a? Hyrax::Embargo

  @embargo = value
  self.embargo_id = @embargo.id
end

#file?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'app/models/hyrax/resource.rb', line 116

def file?
  self.class.file?
end

#file_set?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'app/models/hyrax/resource.rb', line 122

def file_set?
  self.class.file_set?
end

#leaseObject



187
188
189
190
# File 'app/models/hyrax/resource.rb', line 187

def lease
  return @lease if @lease
  @lease = Hyrax.query_service.find_by(id: lease_id) if lease_id.present?
end

#lease=(value) ⇒ Object



180
181
182
183
184
185
# File 'app/models/hyrax/resource.rb', line 180

def lease=(value)
  raise TypeError "can't convert #{value.class} into Hyrax::Lease" unless value.is_a? Hyrax::Lease

  @lease = value
  self.lease_id = @lease.id
end

#pcdm_collection?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'app/models/hyrax/resource.rb', line 128

def pcdm_collection?
  self.class.pcdm_collection?
end

#pcdm_object?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'app/models/hyrax/resource.rb', line 134

def pcdm_object?
  self.class.pcdm_object?
end

#permission_managerObject



156
157
158
# File 'app/models/hyrax/resource.rb', line 156

def permission_manager
  @permission_manager ||= Hyrax::PermissionManager.new(resource: self)
end

#to_rdf_representationString

Returns:

  • (String)


140
141
142
# File 'app/models/hyrax/resource.rb', line 140

def to_rdf_representation
  self.class.to_rdf_representation
end

#visibilityObject



164
165
166
# File 'app/models/hyrax/resource.rb', line 164

def visibility
  visibility_reader.read
end

#visibility=(value) ⇒ Object



160
161
162
# File 'app/models/hyrax/resource.rb', line 160

def visibility=(value)
  visibility_writer.assign_access_for(visibility: value)
end

#work?Boolean

Works are PCDM Objects which are not File Sets.

Returns:

  • (Boolean)


148
149
150
# File 'app/models/hyrax/resource.rb', line 148

def work?
  self.class.work?
end