from django.views.generic.base import TemplateView
from unfold.loginrequired import LoginRequiredView
-from django.http import HttpResponse
-from django.shortcuts import render
+from django.http import HttpResponse
+from django.shortcuts import render
-from manifold.core.query import Query, AnalyzedQuery
-from manifoldapi.manifoldapi import execute_query
+from manifold.core.query import Query, AnalyzedQuery
+from manifoldapi.manifoldapi import execute_query
-from portal.actions import get_requests
+from portal.actions import get_requests
from myslice.theme import ThemeView
import json
+import ast
class ManagementRequestsView (LoginRequiredView, ThemeView):
template_name = "management-tab-requests.html"
- def get(self, request):
+ def get_context_data(self, **kwargs):
ctx_my_authorities = {}
ctx_delegation_authorities = {}
ctx_sub_authorities = {}
dest = {}
-
+ user_username = ''
+ user_authority = ''
# The user need to be logged in
- if (request.user):
+ if (self.request.user):
- user_query = Query().get('local:user').filter_by('email', '==', self.request.user.email).select('user_id')
+ user_query = Query().get('local:user').filter_by('email', '==', self.request.user.username).select('user_id')
user, = execute_query(self.request, user_query)
user_id = user['user_id']
-
+ user_query = Query().get('local:user').filter_by('email', '==', self.request.user.username).select('config')
+ user, = execute_query(self.request, user_query)
+ user_config = user['config']
+ user_config = ast.literal_eval(user_config)
+ user_authority = user_config['authority']
+ user_username = self.request.user.username
# Query manifold to learn about available SFA platforms for more information
# In general we will at least have the portal
# For now we are considering all registries
# iterate on the requests and check if the authority matches a prefix
# startswith an authority on which the user is PI
requests = get_requests()
- for r in requests:
- auth_hrn = r['authority_hrn']
+ auth_hrn = ''
+ for r in requests:
+ auth_hrn = r['authority_hrn']
for my_auth in pi_my_authorities:
if auth_hrn.startswith(my_auth):
dest = ctx_my_authorities
if auth_hrn in pi_expired_credential_authorities:
r['allowed'] = 'expired'
if 'allowed' not in r:
- r['allowed'] = 'denied'
-
+ ## TEMP FIX for allowing new authority registration
+ #r['allowed'] = 'denied'
+ r['allowed'] = 'allowed'
if not auth_hrn in dest:
dest[auth_hrn] = []
- dest[auth_hrn].append(request)
+ dest[auth_hrn].append(r)
- env = {}
- env['my_authorities'] = ctx_my_authorities
- env['sub_authorities'] = ctx_sub_authorities
- env['delegation_authorities'] = ctx_delegation_authorities
+# env = {}
+# env['my_authorities'] = ctx_my_authorities
+# env['sub_authorities'] = ctx_sub_authorities
+# env['delegation_authorities'] = ctx_delegation_authorities
+#
+# # XXX This is repeated in all pages
+# # more general variables expected in the template
+# # the menu items on the top
+# #env['topmenu_items'] = topmenu_items_live('Validation', page)
+# # so we can sho who is logged
+# env['username'] = request.user
+# env['pi'] = "is_pi"
+# env['theme'] = self.theme
+# env['section'] = "Requests"
+# auth_hrn = user_authority + '.' + user_username.split("@")[1]
+ ctx_list = [ctx_my_authorities, ctx_sub_authorities, ctx_delegation_authorities]
+ for ctx in ctx_list:
+ if ctx:
+ for authorities in ctx:
+ for requests in ctx[authorities]:
+ try:
+ requests['object_auth'] = requests['user_hrn'].split('.')[0] + '.' + requests['user_hrn'].split('@')[1]
+ except:
+ print "This object has no user_hrn"
+
+ pi_authority = user_authority + '.' + user_username.split("@")[1]
+ context = super(ManagementRequestsView, self).get_context_data(**kwargs)
+ #print "testing"
+ #print ctx_my_authorities
+ #print auth_hrn
+ #print user_username
+ #print pi_authority
+ context['my_authorities'] = ctx_my_authorities
+ context['sub_authorities'] = ctx_sub_authorities
+ context['delegation_authorities'] = ctx_delegation_authorities
# XXX This is repeated in all pages
# more general variables expected in the template
+ context['title'] = 'Test view that combines various plugins'
# the menu items on the top
- #env['topmenu_items'] = topmenu_items_live('Validation', page)
+ #context['topmenu_items'] = topmenu_items_live('Validation', page)
# so we can sho who is logged
- env['username'] = request.user
- env['pi'] = "is_pi"
- env['theme'] = self.theme
- env['section'] = "Requests"
-
- return render_to_response(self.template, env, context_instance=RequestContext(request))
+ context['username'] = self.request.user
+ context['pi'] = "is_pi"
+ context['theme'] = self.theme
+ context['section'] = "Requests"
+ context['pi_authority'] = pi_authority
+ # XXX We need to prepare the page for queries
+ #context.update(page.prelude_env())
+
+ return context
+
+ #return render_to_response(self.template, env, context_instance=RequestContext(request))