1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2025-07-31 12:41:08 +00:00

Added admin app unit tests

This commit is contained in:
Real-Gecko 2020-05-29 12:46:25 +06:00
parent 85929b5327
commit 83b1dde673
4 changed files with 51 additions and 13 deletions

View file

@ -10,19 +10,19 @@ def apply_change_password(sender, **kwargs):
from django.conf import settings
from django.contrib.auth.models import User, Permission
if hasattr(settings, 'SHOW_PROFILE_EDIT_PASSWORD'):
print('\033[92mSHOW_PROFILE_EDIT_PASSWORD is found inside settings.py')
print('\033[92mApplying permission can_change_password for all users')
print('\033[92mSHOW_PROFILE_EDIT_PASSWORD is found inside settings.py\033[0m')
print('\033[92mApplying permission can_change_password for all users\033[0m')
users = User.objects.all()
permission = Permission.objects.get(codename='change_password')
if settings.SHOW_PROFILE_EDIT_PASSWORD:
print('\033[91mWarning!!! Setting to True for all users')
print('\033[91mWarning!!! Setting to True for all users\033[0m')
for user in users:
user.user_permissions.add(permission)
else:
print('\033[91mWarning!!! Setting to False for all users')
print('\033[91mWarning!!! Setting to False for all users\033[0m')
for user in users:
user.user_permissions.remove(permission)
print('\033[1mDon`t forget to remove the option from settings.py')
print('\033[1mDon`t forget to remove the option from settings.py\033[0m')
def create_admin(sender, **kwargs):
@ -36,7 +36,7 @@ def create_admin(sender, **kwargs):
for migration, rolled_back in plan:
if migration.app_label == 'accounts' and migration.name == '0001_initial' and not rolled_back:
if User.objects.count() == 0:
print('\033[92mCreating default admin user')
print('\033[92mCreating default admin user\033[0m')
admin = User.objects.create_superuser('admin', None, 'admin')
UserAttributes(user=admin, max_instances=-1, max_cpus=-1, max_memory=-1, max_disk_size=-1).save()
break