Module: CPEE::Worklist::User

Defined in:
lib/cpee-worklist/user.rb

Class Method Summary collapse

Class Method Details

.info(opts, task, user) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/cpee-worklist/user.rb', line 51

def self::info(opts,task,user)
  fname = File.join(opts[:top],'orgmodels',Riddl::Protocols::Utils::escape(task['orgmodel']))
  orgmodel = XML::Smart.open_unprotected(fname)
  orgmodel.register_namespace 'o', 'http://cpee.org/ns/organisation/1.0'
  user = orgmodel.find("/o:organisation/o:subjects/o:subject[@uid='#{user}']/o:relation")
  {}.tap{ |t| user.map{|u| (t[u.attributes['unit']]||=[]) <<  u.attributes['role']}}
end

.ok?(opts, task, user) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cpee-worklist/user.rb', line 22

def self::ok?(opts,task,user)
  fname = File.join(opts[:top],'orgmodels',Riddl::Protocols::Utils::escape(task['orgmodel']))
  orgmodel = XML::Smart.open_unprotected(fname)
  orgmodel.register_namespace 'o', 'http://cpee.org/ns/organisation/1.0'
  subjects = orgmodel.find('/o:organisation/o:subjects/o:subject')
  unit = task['unit']
  role = task['role']
  if (unit=='*')
    if (role=='*')
      subjects.each{|s| return true if s.attributes['uid']==user}
    else
      orgmodel.find("/o:organisation/o:subjects/o:subject[o:relation/@role='#{role}']").each do |s|
        return true if user==s.attributes['uid']
      end
    end
  else
    if (role=='*')
      orgmodel.find("/o:organisation/o:subjects/o:subject[o:relation/@unit='#{unit}']").each do |s|
        return true if user==s.attributes['uid']
      end
    else
      orgmodel.find("/o:organisation/o:subjects/o:subject[o:relation/@unit='#{unit}' and o:relation/@role='#{role}']").each do |s|
        return true if user==s.attributes['uid']
      end
    end
  end
  false
end