Merge branch '7032/bugfix_existing_key' into 'master'
7032/bugfix existing key See merge request ungleich-public/dynamicweb!712
This commit is contained in:
		
				commit
				
					
						5646e370ec
					
				
			
		
					 2 changed files with 1 additions and 11 deletions
				
			
		| 
						 | 
				
			
			@ -9,7 +9,6 @@ from django.contrib.auth import authenticate
 | 
			
		|||
from django.utils.translation import ugettext_lazy as _
 | 
			
		||||
 | 
			
		||||
from membership.models import CustomUser
 | 
			
		||||
from utils.hosting_utils import get_all_public_keys
 | 
			
		||||
from .models import UserHostingKey, GenericProduct
 | 
			
		||||
 | 
			
		||||
logger = logging.getLogger(__name__)
 | 
			
		||||
| 
						 | 
				
			
			@ -193,15 +192,6 @@ class UserHostingKeyForm(forms.ModelForm):
 | 
			
		|||
        KEY_ERROR_MESSAGE = _("Please input a proper SSH key")
 | 
			
		||||
        openssh_pubkey_str = self.data.get('public_key').strip()
 | 
			
		||||
 | 
			
		||||
        if openssh_pubkey_str in get_all_public_keys(self.request.user):
 | 
			
		||||
            key_name = UserHostingKey.objects.filter(
 | 
			
		||||
                user_id=self.request.user.id,
 | 
			
		||||
                public_key=openssh_pubkey_str).first().name
 | 
			
		||||
            KEY_EXISTS_MESSAGE = _(
 | 
			
		||||
                "This key exists already with the name \"%(name)s\"") % {
 | 
			
		||||
                                     'name': key_name}
 | 
			
		||||
            raise forms.ValidationError(KEY_EXISTS_MESSAGE)
 | 
			
		||||
 | 
			
		||||
        with tempfile.NamedTemporaryFile(delete=True) as tmp_public_key_file:
 | 
			
		||||
            tmp_public_key_file.write(openssh_pubkey_str.encode('utf-8'))
 | 
			
		||||
            tmp_public_key_file.flush()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,7 +18,7 @@ def get_all_public_keys(customer):
 | 
			
		|||
    :return: A list of public keys
 | 
			
		||||
    """
 | 
			
		||||
    return UserHostingKey.objects.filter(user_id=customer.id).values_list(
 | 
			
		||||
        "public_key", flat=True)
 | 
			
		||||
        "public_key", flat=True).distinct()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_or_create_vm_detail(user, manager, vm_id):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue