Server IP : 85.214.239.14 / Your IP : 3.145.106.176 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /srv/modoboa/env/lib/python3.5/site-packages/modoboa/core/management/commands/ |
Upload File : |
"""A management command to load Modoboa initial data: * Create a default super admin if none exists * Create groups and permissions """ from functools import reduce from django.contrib.auth.models import Group from django.core.management.base import BaseCommand from modoboa.lib.permissions import add_permissions_to_group from ... import constants, extensions, models, signals class Command(BaseCommand): """Command definition.""" help = "Load Modoboa initial data" # NOQA:A003 def add_arguments(self, parser): """Add extra arguments to command.""" parser.add_argument( "--admin-username", default="admin", help="Username of the initial super administrator." ) parser.add_argument( "--extra-fixtures", action="store_true", default=False, help="Also load some fixtures from the admin application." ) def handle(self, *args, **options): """Command entry point.""" extensions.exts_pool.load_all() if not models.User.objects.filter(is_superuser=True).count(): admin = models.User( username=options["admin_username"], is_superuser=True) admin.set_password("password") admin.save() models.ObjectAccess.objects.create( user=admin, content_object=admin, is_owner=True) groups = list(constants.PERMISSIONS.keys()) for groupname in groups: group, created = Group.objects.get_or_create(name=groupname) results = signals.extra_role_permissions.send( sender=self.__class__, role=groupname) permissions = constants.PERMISSIONS.get(groupname, []) if results: permissions += reduce( lambda a, b: a + b, [result[1] for result in results]) if not permissions: continue add_permissions_to_group(group, permissions) for extname in list(extensions.exts_pool.extensions.keys()): extension = extensions.exts_pool.get_extension(extname) try: extension.load_initial_data() except Exception as e: self.stderr.write( "Unable to load initial data for '{}' ({}).".format( extname, str(e) ) ) else: signals.initial_data_loaded.send( sender=self.__class__, extname=extname ) if options["extra_fixtures"]: from modoboa.admin import factories factories.populate_database()