Class: RightsRestriction

Inherits:
Sequel::Model
  • Object
show all
Includes:
ASModel::CRUD, ASModel::ModelScoping
Defined in:
backend/app/model/rights_restriction.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ASModel::CRUD

#apply_nested_records, #create_ark_name, #delete, #delete_ark_name, #eagerly_load!, included, #map_validation_to_json_property, #mark_as_system_modified, #remove_nested_records, set_audit_fields, #system_modified?, #update_from_json, #validate

Methods included from ASModel::ModelScoping

included, #publish!, #set_suppressed, #unpublish!, #uri

Class Method Details

.applicable_modelsObject



23
24
25
# File 'backend/app/model/rights_restriction.rb', line 23

def self.applicable_models
  @applicable_models ||= calculate_applicable_models
end

.calculate_applicable_modelsObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'backend/app/model/rights_restriction.rb', line 28

def self.calculate_applicable_models
  result = {}

  models_supporting_rights_restrictions = ASModel.all_models.select {|model| model.included_modules.include?(RightsRestrictionNotes)}

  models_supporting_rights_restrictions.each do |model|
    join_column = model.association_reflection(:rights_restriction)[:key]

    result[join_column] = model
  end

  result
end

.sequel_to_jsonmodel(objs, opts = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'backend/app/model/rights_restriction.rb', line 43

def self.sequel_to_jsonmodel(objs, opts = {})
  jsons = super

  jsons.zip(objs).each do |json, obj|
    json['local_access_restriction_type'] = obj.rights_restriction_type.map {|obj| obj.values[:restriction_type]}
    json['linked_records'] = {'ref' => obj.linked_record_uri}
  end

  jsons
end

Instance Method Details

#linked_record_uriObject



12
13
14
15
16
17
18
19
20
# File 'backend/app/model/rights_restriction.rb', line 12

def linked_record_uri
  self.class.applicable_models.each do |column, model|
    if self[column]
      return model.uri_for(model.my_jsonmodel.record_type, self[column])
    end
  end

  nil
end