1 from unfold.plugin import Plugin
3 class TopmenuValidation (Plugin):
5 """This plugin is designed to work together with topmenu.
7 It will check to see if user has PI rights at least on one authority,
8 and if so will enable corresponding validation button in topmenu.
10 A realistic example would have incoming query as
12 Query.get('ple:user').filter_by('user_hrn', '==', '$user_hrn').select('pi_authorities')
16 def __init__ (self, query=None, button_domid=None, **settings):
17 Plugin.__init__ (self, **settings)
20 query = Query.get('ple:user').filter_by('user_hrn', '==', '$user_hrn').select('pi_authorities')
21 if button_domid is None: button_domid="topmenu-validate"
23 self.button_domid=button_domid
25 # this does not have any materialization
26 def render_content (self, request):
29 def requirements (self):
30 return { 'js_files': [ 'js/topmenuvalidation.js', 'js/manifold-query.js',
31 "js/spin-presets.js", "js/spin.min.js", "js/jquery.spin.js",
34 def json_settings_list (self):
35 return [ 'query_uuid', 'button_domid', ]
37 #################### here is an extract previously in topmenu.py
39 #from pprint import pprint
40 #from manifoldapi.manifoldapi import execute_query
41 #from manifold.core.query import Query
42 ### # ** Where am I a PI **
43 ### # For this we need to ask SFA (of all authorities) = PI function
44 ### user_query = Query().get('local:user').select('config','email')
45 ### user_details = execute_query(request, user_query)
47 ### # Required: the user must have an authority in its user.config
48 ### # XXX Temporary solution
49 ### # not always found in user_details...
51 #### Deactivated until fixed
52 #### if user_details is not None:
53 #### for user_detail in user_details:
54 #### #email = user_detail['email']
55 #### if user_detail['config']:
56 #### config = json.loads(user_detail['config'])
57 #### user_detail['authority'] = config.get('authority',"Unknown Authority")
58 #### print "topmenu: %s", (user_detail['authority'])
59 #### if user_detail['authority'] is not None:
60 #### sub_authority = user_detail['authority'].split('.')
61 #### root_authority = sub_authority[0]
62 #### pi_authorities_query = Query.get(root_authority+':user').filter_by('user_hrn', '==', '$user_hrn').select('pi_authorities')
64 #### pi_authorities_query = Query.get('user').filter_by('user_hrn', '==', '$user_hrn').select('pi_authorities')
66 #### pi_authorities_tmp = execute_query(request, pi_authorities_query)
68 #### pi_authorities_tmp = set()
69 #### pi_authorities = set()
70 #### for pa in pi_authorities_tmp:
71 #### if 'pi_authorities' in pa:
72 #### pi_authorities |= set(pa['pi_authorities'])
73 #### print "pi_authorities =", pi_authorities
74 #### if len(pi_authorities) > 0:
75 #### result.append({'label':'Validation', 'href': '/portal/validate/'})
76 ### result.append({'label':'Validation', 'href': '/portal/validate/'})