mirror of
				https://github.com/retspen/webvirtcloud
				synced 2025-07-31 12:41:08 +00:00 
			
		
		
		
	make console password optional for users with permissions
This commit is contained in:
		
							parent
							
								
									74a4a1a3ef
								
							
						
					
					
						commit
						44aa746f4b
					
				
					 8 changed files with 57 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -24,6 +24,19 @@ def apply_change_password(sender, **kwargs):
 | 
			
		|||
                user.user_permissions.remove(permission)
 | 
			
		||||
        print('\033[1mDon`t forget to remove the option from settings.py\033[0m')
 | 
			
		||||
 | 
			
		||||
def apply_passwordless_console(sender, **kwargs):
 | 
			
		||||
    '''
 | 
			
		||||
    Apply new passwordless_console permission for all users
 | 
			
		||||
    '''
 | 
			
		||||
    from django.conf import settings
 | 
			
		||||
    from django.contrib.auth.models import User, Permission
 | 
			
		||||
 | 
			
		||||
    print('\033[92mApplying permission passwordless_console for all users\033[0m')
 | 
			
		||||
    users = User.objects.all()
 | 
			
		||||
    permission = Permission.objects.get(codename='passwordless_console')
 | 
			
		||||
    for user in users:
 | 
			
		||||
            user.user_permissions.add(permission)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def create_admin(sender, **kwargs):
 | 
			
		||||
    '''
 | 
			
		||||
| 
						 | 
				
			
			@ -49,3 +62,4 @@ class AccountsConfig(AppConfig):
 | 
			
		|||
    def ready(self):
 | 
			
		||||
        post_migrate.connect(apply_change_password, sender=self)
 | 
			
		||||
        post_migrate.connect(create_admin, sender=self)
 | 
			
		||||
        post_migrate.connect(apply_passwordless_console, sender=self)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,6 +6,7 @@ from django.utils.translation import ugettext_lazy as _
 | 
			
		|||
 | 
			
		||||
from instances.models import Instance
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class UserInstanceManager(models.Manager):
 | 
			
		||||
    def get_queryset(self):
 | 
			
		||||
        return super().get_queryset().select_related('instance', 'user')
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue