slice and project name should be lowercase, added checks in js and python
authorciro <ciro.scognamiglio@lip6.fr>
Tue, 21 Apr 2015 15:34:06 +0000 (17:34 +0200)
committerciro <ciro.scognamiglio@lip6.fr>
Tue, 21 Apr 2015 15:34:06 +0000 (17:34 +0200)
portal/projectrequestview.py
portal/slicerequestview.py
portal/templates/fed4fire/fed4fire_projectrequest_view.html
portal/templates/fed4fire/fed4fire_slicerequest_view.html
portal/templates/slicerequest_view.html

index 5fd7d8c..086d60c 100644 (file)
@@ -92,13 +92,20 @@ class ProjectRequestView(LoginRequiredAutoLogoutView, ThemeView):
                 authority_name = authority['name']
         
         if method == 'POST' :
-        
+
+            project_name = wsgi_request.POST.get('project_name', '')
+            if not project_name or len(project_name) == 0 :
+                errors.append('Project name can\'t be empty')
+
+            # accept only lowercase names
+            project_name = project_name.lower()
+
             if 'join' in wsgi_request.POST:
                 post = {
                     'user_hrn'          : user_hrn,
                     'email'             : user_email,
-                    'project_name'      : wsgi_request.POST.get('project_name', ''),
-                    'authority_hrn'     : wsgi_request.POST.get('project_name', ''),
+                    'project_name'      : project_name,
+                    'authority_hrn'     : project_name,
                 }
 
             else:
@@ -106,10 +113,10 @@ class ProjectRequestView(LoginRequiredAutoLogoutView, ThemeView):
                     'user_hrn'          : user_hrn,
                     'email'             : user_email,
                     'authority_hrn'     : wsgi_request.POST.get('authority_name', ''),
-                    'project_name'      : wsgi_request.POST.get('project_name', ''),
+                    'project_name'      : project_name,
                     'purpose'           : wsgi_request.POST.get('purpose', ''),
                 }
-                
+
                 # for new projects max project_name length is 10
                 if (len(post['project_name']) >10):
                     errors.append('Project name can be maximum 10 characters long')
@@ -117,14 +124,14 @@ class ProjectRequestView(LoginRequiredAutoLogoutView, ThemeView):
                 #if (post['authority_hrn'] is None or post['authority_hrn'] == ''):
                 #    errors.append('Organization is mandatory')
     
-                if (post['purpose'] is None or post['purpose'] == ''):
+                if post['purpose'] is None or post['purpose'] == '':
                     errors.append('Project purpose is mandatory')
 
-                if (re.search(r'^[A-Za-z0-9_]*$', post['project_name']) == None):
+                if re.search(r'^[A-Za-z0-9_]*$', post['project_name']) is None:
                     errors.append('Project name may contain only letters, numbers, and underscore.')
 
             # What kind of project name is valid?
-            if (post['project_name'] is None or post['project_name'] == ''):
+            if post['project_name'] is None or post['project_name'] == '':
                 errors.append('Project name is mandatory')   
             
             if not errors:
@@ -163,167 +170,3 @@ class ProjectRequestView(LoginRequiredAutoLogoutView, ThemeView):
                'pending_join_projects': pending_join_projects,
         }
         return render(wsgi_request, self.template, env)
-    
-        
-    
-        """
-        """
-        errors = []
-        slice_name =''
-        purpose=''
-        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)
-        if authorities is not None:
-            authorities = sorted(authorities, key=lambda k: k['authority_hrn'])
-            authorities = sorted(authorities, key=lambda k: k['name'])
-
-        # Get user_email (XXX Would deserve to be simplified)
-        user_query  = Query().get('local:user').select('email','config')
-        user_details = execute_query(wsgi_request, user_query)
-        user_email = user_details[0].get('email')
-        # getting user_hrn
-        for user_detail in user_details:
-            user_config = json.loads(user_detail['config'])
-            user_authority = user_config.get('authority','N/A')              
-        # getting the org from authority        
-        for authority in authorities:
-            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)
-        #
-        platform_query  = Query().get('local:platform').select('platform_id','platform','gateway_type','disabled')
-        platform_details = execute_query(wsgi_request, platform_query)
-        
-        user_hrn = None
-        # getting user_hrn from local:account
-        for account_detail in account_details:
-            for platform_detail in platform_details:
-                if platform_detail['platform_id'] == account_detail['platform_id']:
-                    # taking user_hrn only from myslice account
-                    # NOTE: we should later handle accounts filter_by auth_type= managed OR user
-                    if 'myslice' in platform_detail['platform']:
-                        account_config = json.loads(account_detail['config'])
-                        user_hrn = account_config.get('user_hrn','N/A')
-                        acc_auth_cred = account_config.get('delegated_authority_credentials','N/A')
-
-
-        # checking if pi or not
-        if acc_auth_cred == {} or acc_auth_cred == 'N/A':
-            pi = "is_not_pi"
-        else:
-            pi = "is_pi"
-
-
-        # Page rendering
-#         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
-
-            # get the domain url
-#             current_site = Site.objects.get_current()
-#             current_site = current_site.domain
-            
-            # 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',
-                'id'                : None,
-                'user_hrn'          : user_hrn,
-                'email'             : user_email,
-                'timestamp'         : time.time(),
-                'authority_hrn'     : authority_hrn,
-                'organization'      : wsgi_request.POST.get('org_name', ''),
-                'slice_name'        : wsgi_request.POST.get('slice_name', ''),
-                'url'               : wsgi_request.POST.get('url', ''),
-                'purpose'           : wsgi_request.POST.get('purpose', ''),
-                'current_site'      : current_site
-            }
-            
-            # 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('myslice: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?
-            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('Experiment purpose is mandatory')
-
-            url = slice_request['url']
-
-            if not errors:
-                if is_pi(wsgi_request, user_hrn, authority_hrn):
-                    # PIs can directly create slices in their own authority...
-                    create_slice(wsgi_request, slice_request)
-                    clear_user_creds(wsgi_request, user_email)
-                    self.template_name = 'slice-request-done-view.html'
-                else:
-                    # Otherwise a wsgi_request is sent to the PI
-                    create_pending_slice(wsgi_request, slice_request, user_email)
-                    self.template_name = 'slice-request-ack-view.html'
-                
-                # log user activity
-                activity.user.slice(wsgi_request)
-                
-                return render(wsgi_request, self.template, {'theme': self.theme}) # Redirect after POST
-        else:
-            slice_request = {}
-
-        template_env = {
-            'username': wsgi_request.user.email,
-            'errors': errors,
-            'slice_name': slice_name,
-            'purpose': purpose,
-            'email': user_email,
-            'user_hrn': user_hrn,
-            'url': url,
-            'pi': pi,
-            'authority_name': authority_name,        
-            'authority_hrn': user_authority,        
-            'cc_myself': True,
-            'authorities': authorities,
-            'theme': self.theme,
-            'section': "Slice request"
-        }
-        template_env.update(slice_request)
-        template_env.update(page.prelude_env())
-        return render(wsgi_request, self.template, template_env)
index f0643e2..f11603f 100644 (file)
@@ -119,6 +119,13 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView):
             if project is not None and project != '':
                 authority_hrn = project
 
+            slice_name = wsgi_request.POST.get('slice_name', '')
+            if not slice_name or len(slice_name) == 0 :
+                errors.append('Slice name can\'t be empty')
+
+            # accept only lowercase names
+            slice_name = slice_name.lower()
+
             slice_request = {
                 'type'              : 'slice',
                 'id'                : None,
@@ -127,16 +134,14 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView):
                 'timestamp'         : time.time(),
                 'authority_hrn'     : authority_hrn,
                 'organization'      : wsgi_request.POST.get('org_name', ''),
-                'slice_name'        : wsgi_request.POST.get('slice_name', ''),
+                'slice_name'        : slice_name,
                 'url'               : wsgi_request.POST.get('url', ''),
                 'purpose'           : wsgi_request.POST.get('purpose', ''),
                 'current_site'      : current_site
             }
-            
-            # create slice_hrn based on authority_hrn and slice_name
-            slice_name = slice_request['slice_name']
+
             # slice name is unique among all authorities 
-            slice_query  = Query().get('myslice:slice').select('slice_hrn')
+            slice_query = Query().get('myslice:slice').select('slice_hrn')
             slice_details_sfa = execute_admin_query(wsgi_request, slice_query)
             for _slice in slice_details_sfa:
                 split_list = _slice['slice_hrn'].split('.')
@@ -146,18 +151,18 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView):
             
 
             # What kind of slice name is valid?
-            if (slice_name is None or 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):
+            if re.search(r'^[A-Za-z0-9_]*$', slice_name) is None:
                 errors.append('Slice name may contain only letters, numbers, and underscore.')
             
             organization = slice_request['organization']
             if theme.theme == 'fed4fire':
-                if (organization is None or organization == ''):
+                if organization is None or organization == '':
                     errors.append('Selecting project is mandatory')
             else:
-                if (organization is None or organization == ''):
+                if organization is None or organization == '':
                     errors.append('Organization is mandatory')
 
             slice_length= len(slice_request['slice_name'])
@@ -167,7 +172,7 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView):
 
     
             purpose = slice_request['purpose']
-            if (purpose is None or purpose == ''):
+            if purpose is None or purpose == '':
                 errors.append('Experiment purpose is mandatory')
 
             url = slice_request['url']
index 1da22fa..8c8ff52 100644 (file)
 <script>
 $(document).ready(function() {
     var myprojects = JSON.parse(localStorage.getItem('projects'));
-    console.log(myprojects);
     if (myprojects) {
         $.each(myprojects, function (i, val){
-            console.log(val);
             $('.project-list').append('<tr><td>'+ val +'</td></tr>');
         });
     } else {
@@ -204,6 +202,9 @@ $(document).ready(function() {
        // auto-complete the form
     jQuery("#org_name").combobox();
 
+    $('input[name=project_name]').keyup(function(){
+        this.value = this.value.toLowerCase();
+    });
 });
 </script>
 {% endblock %}
index 4f8546e..07a4597 100644 (file)
@@ -79,39 +79,10 @@ jQuery(document).ready(function(){
                 }
         }
     }).bind('focus', function(){ $(this).autocomplete("search"); } );
+    $('input[name=slice_name]').keyup(function(){
+        this.value = this.value.toLowerCase();
+    });
 });
-
-/*function draw_projects(authority_hrn){
-
-    var projects = [];
-    project_row = "<option value=''> - </option>";
-    projects.push(project_row);
-
-    if(authority_hrn.length > 0){
-        // Not for root authority
-        if(authority_hrn.split('.').length > 1){
-            $.post("/rest/myslice:authority/",{'fields':['authority_hrn','pi_users'],'filters':{'authority_hrn':'CONTAINS'+authority_hrn}}, function( data ) {
-               
-                $.each( data, function( key, val ) {
-                    project_row = "<option value='"+val.authority_hrn+"'>"+val.authority_hrn+"</option>";
-                    projects.push(project_row);
-                });
-                $("#project").html(projects.join( "" ));
-            });
-        }else{
-            $("#project").html(projects.join( "" ));
-        }
-    }else{
-        my_projects = JSON.parse(localStorage.getItem('projects'));
-        $.each( my_projects, function( i, val ) {
-            project_row = "<option value='"+val+"'>"+val+"</option>";
-            projects.push(project_row);
-        });
-        $("#project").html(projects.join( "" ));
-    }
-    $("#project").show();
-    $("#project_loading").hide();
-}*/
 </script>
 {% endblock %}
 
index 880521b..41dc1ff 100644 (file)
@@ -79,6 +79,9 @@ jQuery(document).ready(function(){
       minLength: 0,
       select: function( event, ui ) {console.log(jQuery(this));}
     });
+    $('input[name=slice_name]').keyup(function(){
+        this.value = this.value.toLowerCase();
+    });
 });
 </script>
 {% endblock %}