Do SSH key validation only if the user doesn't have an existing key and
the user has input some value in the add ssh key field
This commit is contained in:
		
					parent
					
						
							
								34c917acc2
							
						
					
				
			
			
				commit
				
					
						feeb102f92
					
				
			
		
					 3 changed files with 32 additions and 23 deletions
				
			
		| 
						 | 
				
			
			@ -1004,13 +1004,16 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView, FormView):
 | 
			
		|||
    def post(self, request):
 | 
			
		||||
        # Check ssh public key and then proceed
 | 
			
		||||
        form = self.get_form()
 | 
			
		||||
        required = 'add_ssh' in self.request.POST
 | 
			
		||||
        required = True
 | 
			
		||||
 | 
			
		||||
        # SSH key is required only if the user doesn't have an existing
 | 
			
		||||
        # key
 | 
			
		||||
        if len(get_all_public_keys(self.request.user)) == 0:
 | 
			
		||||
            form.fields['name'].required = required
 | 
			
		||||
            form.fields['public_key'].required = required
 | 
			
		||||
        # SSH key validation is required only if the user doesn't have an
 | 
			
		||||
        # existing key and user has input some value in the add ssh key fields
 | 
			
		||||
        if (len(get_all_public_keys(self.request.user)) > 0 and
 | 
			
		||||
                (len(form.data.get('public_key')) == 0 and
 | 
			
		||||
                         len(form.data.get('name')) == 0)):
 | 
			
		||||
            required = False
 | 
			
		||||
        form.fields['name'].required = required
 | 
			
		||||
        form.fields['public_key'].required = required
 | 
			
		||||
        if not form.is_valid():
 | 
			
		||||
            response = {
 | 
			
		||||
                'status': False,
 | 
			
		||||
| 
						 | 
				
			
			@ -1019,9 +1022,10 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView, FormView):
 | 
			
		|||
            }
 | 
			
		||||
            return JsonResponse(response)
 | 
			
		||||
 | 
			
		||||
        # We have a valid SSH key from the user, save it in opennebula and db
 | 
			
		||||
        # and proceed further
 | 
			
		||||
        form.save()
 | 
			
		||||
        if required:
 | 
			
		||||
            # We have a valid SSH key from the user, save it in opennebula and
 | 
			
		||||
            # db and proceed further
 | 
			
		||||
            form.save()
 | 
			
		||||
 | 
			
		||||
        template = request.session.get('template')
 | 
			
		||||
        specs = request.session.get('specs')
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue