Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab
authorCiro Scognamiglio <ciro.scognamiglio@cslash.net>
Tue, 25 Feb 2014 18:06:48 +0000 (19:06 +0100)
committerCiro Scognamiglio <ciro.scognamiglio@cslash.net>
Tue, 25 Feb 2014 18:06:48 +0000 (19:06 +0100)
myslice/settings.py
portal/accountview.py
portal/actions.py
portal/registrationview.py
portal/slicerequestview.py

index 9c8ab57..30887d6 100644 (file)
@@ -259,7 +259,7 @@ AUTHENTICATION_BACKENDS = ( 'auth.manifoldbackend.ManifoldBackend','django.contr
 ### the view to redirect malformed (i.e. with a wrong CSRF) incoming requests
 # without this setting django will return a 403 forbidden error, which is fine
 # if you need to see the error message then use this setting
-CSRF_FAILURE_VIEW = 'manifold.manifoldproxy.csrf_failure'
+CSRF_FAILURE_VIEW = 'manifoldapi.manifoldproxy.csrf_failure'
 
 #################### for insert_above
 #IA_JS_FORMAT = "<script type='text/javascript' src='{URL}' />"
index 62c6305..f2b3457 100644 (file)
@@ -2,7 +2,7 @@ from unfold.loginrequired               import LoginRequiredAutoLogoutView
 #
 from manifold.core.query                import Query
 from manifoldapi.manifoldapi            import execute_query
-from portal.actions                     import manifold_update_user, manifold_update_account, manifold_add_account, manifold_delete_account, sfa_update_user
+from portal.actions                     import manifold_update_user, manifold_update_account, manifold_add_account, manifold_delete_account, sfa_update_user, sfa_get_user
 #
 from unfold.page                        import Page    
 from ui.topmenu                         import topmenu_items_live, the_user
@@ -336,15 +336,25 @@ def account_process(request):
                         # preserving user_hrn
                         user_hrn = account_config.get('user_hrn','N/A')
                         keypair = '{"user_public_key":'+ public_key + ', "user_private_key":'+ private_key + ', "user_hrn":"'+ user_hrn + '"}'
-                        updated_config = json.dumps(account_config) 
+                        #updated_config = json.dumps(account_config) 
                         # updating manifold
-                        user_params = { 'config': keypair, 'auth_type':'managed'}
-                        manifold_update_account(request, user_id, user_params)
+                        #user_params = { 'config': keypair, 'auth_type':'managed'}
+                        #manifold_update_account(request, user_id, user_params)
                         # updating sfa
                         public_key = public_key.replace('"', '');
                         user_pub_key = {'keys': public_key}
+                        #sfa_update_user(request, user_hrn, user_pub_key)
                         sfa_update_user(request, user_hrn, user_pub_key)
-                        messages.success(request, 'Sucess: New Keypair Generated! Delegation of your credentials will be automatic.')
+                        result_sfa_user = sfa_get_user(request, user_hrn, public_key)
+                        result_sfa_user = result_sfa_user[0]
+                        if 'keys' in result_sfa_user and result_sfa_user['keys'][0] == public_key:
+                            # updating manifold
+                            updated_config = json.dumps(account_config) 
+                            user_params = { 'config': keypair, 'auth_type':'managed'}
+                            manifold_update_account(request, user_id, user_params)
+                            messages.success(request, 'Sucess: New Keypair Generated! Delegation of your credentials will be automatic.')
+                        else:
+                            messages.error(request, 'Error: An error occured during the update of your public key at the Registry, or your public key is not matching the one stored.')
                         return HttpResponseRedirect("/portal/account/")
         else:
             messages.error(request, 'Account error: You need an account in myslice platform to perform this action')
index 36d019c..c22d8fb 100644 (file)
@@ -14,7 +14,7 @@ import json
 
 def authority_get_pis(request, authority_hrn):
     query = Query.get('authority').filter_by('authority_hrn', '==', authority_hrn).select('pi_users')
-    results = execute_query(request, query)
+    results = execute_admin_query(request, query)
     # NOTE: temporarily commented. Because results is giving empty list. 
     # Needs more debugging
     #if not results:
@@ -25,13 +25,22 @@ def authority_get_pis(request, authority_hrn):
 
 def authority_get_pi_emails(request, authority_hrn):
     #return ['jordan.auge@lip6.fr', 'loic.baron@lip6.fr']
-
     pi_users = authority_get_pis(request,authority_hrn)
-    pi_user_hrns = [ hrn for x in pi_users for hrn in x['pi_users'] ]
-    query = Query.get('user').filter_by('user_hrn', 'included', pi_user_hrns).select('email')
-    results = execute_query(request, query)
-    print "mails",  [result['email'] for result in results]
-    return [result['email'] for result in results]
+    if any(d['pi_users'] == None for d in pi_users):
+        return ['support@myslice.info']
+    else:
+        pi_user_hrns = [ hrn for x in pi_users for hrn in x['pi_users'] ]
+        query = Query.get('user').filter_by('user_hrn', 'included', pi_user_hrns).select('email')
+        results = execute_admin_query(request, query)
+        print "mails",  [result['email'] for result in results]
+        return [result['email'] for result in results]
+
+# SFA get record
+
+def sfa_get_user(request, user_hrn, pub):
+    query_sfa_user = Query.get('user').filter_by('user_hrn', '==', user_hrn)
+    result_sfa_user = execute_query(request, query_sfa_user)
+    return result_sfa_user                        
 
 # SFA add record (user, slice)
 
index 42d10e9..7c2ab03 100644 (file)
@@ -175,12 +175,9 @@ class RegistrationView (FreeAccessView, ThemeView):
                     'user_hrn'      : user_hrn,
                     'public_key'    : public_key,
                     }
+                
                 recipients = authority_get_pi_emails(request,reg_auth)
                 
-                # We don't need to send this email to user.
-                # it's for the PI only
-                #if ctx['cc_myself']:
-                #    recipients.append(ctx['email'])
 
                 msg = render_to_string('user_request_email.txt', ctx)
                 send_mail("Onelab New User request for %s submitted"%reg_email, msg, 'support@myslice.info', recipients)
index c26f67d..42395d0 100644 (file)
@@ -108,11 +108,7 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView):
     
                 # The recipients are the PI of the authority
                 recipients = authority_get_pi_emails(request, authority_hrn)
-    
-                if cc_myself:
-                    recipients.append(email)
                 msg = render_to_string('slice-request-email.txt', ctx)
-                #print "email, msg, email, recipients", email , msg, email, recipients 
                 send_mail("Onelab user %s requested a slice"%email , msg, email, recipients)
                 
                 self.template_name = 'slice-request-ack-view.html'