Class: ROF::Filters::AccessToRelsext

Inherits:
ROF::Filter show all
Defined in:
lib/rof/filters/access_to_relsext.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AccessToRelsext

Returns a new instance of AccessToRelsext.



6
7
# File 'lib/rof/filters/access_to_relsext.rb', line 6

def initialize(options = {})
end

Instance Method Details

#convert_to_relsext(access_type, access_list, rof) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rof/filters/access_to_relsext.rb', line 19

def convert_to_relsext(access_type, access_list, rof)
  # map any access fields of the form XXX:YYY into
  # a rels-ext section
  Array.wrap(access_list).each do |access_user|
    if access_user =~ /([^:]+):.+/
      rof['rels-ext'] ||= {}
      case access_type
        when "read"
          rof['rels-ext']['hasViewer'] ||=[]
          rof['rels-ext']['hasViewer'] << access_user
        when "read-groups"
          rof['rels-ext']['hasViewerGroup'] ||= []
          rof['rels-ext']['hasViewerGroup'] << access_user
        when "edit"
          rof['rels-ext']['hasEditor'] ||= []
          rof['rels-ext']['hasEditor'] << access_user
        when "edit-groups"
          rof['rels-ext']['hasEditorGroup'] ||= []
          rof['rels-ext']['hasEditorGroup'] << access_user
        else
          raise AccessMappingNotFound
      end
    end
  end
  return rof
end

#process(obj_list) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/rof/filters/access_to_relsext.rb', line 9

def process(obj_list)
  # We need to map access with pid to rels-ext predicates
  obj_list.map! do |obj|
    obj.fetch("rights").each do |access_type, access_list|
      convert_to_relsext(access_type, access_list, obj)
    end
    obj
  end
end