Registration and Join Organization: Fixed private key of the user in Join and allowin...
[myslice.git] / portal / slicerequestview.py
index 734ac9c..95d2794 100644 (file)
@@ -34,6 +34,8 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView):
         slice_name =''
         purpose=''
         exp_url=''
+        authority_hrn = None
+        authority_name = None
         # Retrieve the list of authorities
         authorities_query = Query.get('authority').select('name', 'authority_hrn')
         authorities = execute_admin_query(wsgi_request, authorities_query)
@@ -53,6 +55,9 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView):
             if authority['authority_hrn'] == user_authority:
                 authority_name = authority['name']
 
+        # Handle the case when we use only hrn and not name
+        if authority_name is None:
+            authority_name = user_authority
         #
         account_query  = Query().get('local:account').select('user_id','platform_id','auth_type','config')
         account_details = execute_query(wsgi_request, account_query)
@@ -83,6 +88,7 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView):
         page = Page(wsgi_request)
         page.add_js_files  ( [ "js/jquery.validate.js", "js/jquery-ui.js" ] )
         page.add_css_files ( [ "https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" ] )
+        page.expose_js_metadata()
 
         if method == 'POST':
             # The form has been submitted
@@ -91,12 +97,14 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView):
             current_site = Site.objects.get_current()
             current_site = current_site.domain
             
-            # getting the authority_hrn from the selected organization           
+            # getting the authority_hrn from the selected organization
             for authority in authorities:
                 if authority['name'] == wsgi_request.POST.get('org_name', ''):
                     authority_hrn = authority['authority_hrn']
 
-            
+            # Handle the case when we use only hrn and not name
+            if authority_hrn is None:
+                authority_hrn = wsgi_request.POST.get('org_name', '')
 
             slice_request = {
                 'type'              : 'slice',
@@ -112,24 +120,35 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView):
                 'current_site'      : current_site
             }
             
-            exp_url = slice_request['exp_url']
-           
-            authority_hrn = slice_request['authority_hrn']
-            if (authority_hrn is None or authority_hrn == ''):
-                errors.append('Please, select an authority')
+            # create slice_hrn based on authority_hrn and slice_name
+            slice_name = slice_request['slice_name']
+            req_slice_hrn = authority_hrn + '.' + slice_name
+            # comparing requested slice_hrn with the existing slice_hrn 
+            slice_query  = Query().get('slice').select('slice_hrn','parent_authority').filter_by('parent_authority','==',authority_hrn)
+            slice_details_sfa = execute_admin_query(wsgi_request, slice_query)
+            for _slice in slice_details_sfa:
+                if _slice['slice_hrn'] == req_slice_hrn:
+                    errors.append('Slice already exists. Please use a different slice name.')
+            
 
             # What kind of slice name is valid?
-            slice_name = slice_request['slice_name']
             if (slice_name is None or slice_name == ''):
                 errors.append('Slice name is mandatory')
             
             if (re.search(r'^[A-Za-z0-9_]*$', slice_name) == None):
                 errors.append('Slice name may contain only letters, numbers, and underscore.')
+            
+            organization = slice_request['organization']    
+            if (organization is None or organization == ''):
+                errors.append('Organization is mandatory')
+
 
     
             purpose = slice_request['purpose']
             if (purpose is None or purpose == ''):
-                errors.append('Purpose is mandatory')
+                errors.append('Experiment purpose is mandatory')
+
+            exp_url = slice_request['exp_url']
 
             if not errors:
                 if is_pi(wsgi_request, user_hrn, authority_hrn):
@@ -156,6 +175,7 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView):
             'exp_url': exp_url,
             'pi': pi,
             'authority_name': authority_name,        
+            'authority_hrn': user_authority,        
             'cc_myself': True,
             'authorities': authorities,
             'theme': self.theme,