mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Merge pull request #910 from tonioo/feature/default_admin_username_903
Possibility to change default username for initial admin.
This commit is contained in:
@@ -82,6 +82,10 @@ class DeployCommand(Command):
|
||||
'--dont-install-extensions', action='store_true', default=False,
|
||||
help='Do not install extensions using pip'
|
||||
)
|
||||
self._parser.add_argument(
|
||||
'--admin-username', default='admin',
|
||||
help="Username of the initial super administrator"
|
||||
)
|
||||
|
||||
def _exec_django_command(self, name, cwd, *args):
|
||||
"""Run a django command for the freshly created project
|
||||
@@ -249,7 +253,8 @@ class DeployCommand(Command):
|
||||
"migrate", parsed_args.name, '--noinput'
|
||||
)
|
||||
self._exec_django_command(
|
||||
"load_initial_data", parsed_args.name
|
||||
"load_initial_data", parsed_args.name,
|
||||
"--admin-username", parsed_args.admin_username
|
||||
)
|
||||
if parsed_args.collectstatic:
|
||||
self._exec_django_command(
|
||||
|
||||
@@ -24,10 +24,17 @@ class Command(BaseCommand):
|
||||
|
||||
help = "Load Modoboa initial data"
|
||||
|
||||
def add_arguments(self, parser):
|
||||
"""Add extra arguments to command."""
|
||||
parser.add_argument(
|
||||
"--admin-username", default="admin",
|
||||
help="Username of the initial super administrator."
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
"""Command entry point."""
|
||||
if not User.objects.filter(is_superuser=True).count():
|
||||
admin = User(username="admin", is_superuser=True)
|
||||
admin = User(username=options["admin_username"], is_superuser=True)
|
||||
admin.set_password("password")
|
||||
admin.save()
|
||||
ObjectAccess.objects.create(
|
||||
|
||||
+12
-1
@@ -4,7 +4,7 @@ import httmock
|
||||
|
||||
from django.core import management
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test import override_settings
|
||||
from django.test import override_settings, TestCase
|
||||
|
||||
from modoboa.lib import exceptions
|
||||
from modoboa.lib import parameters
|
||||
@@ -44,6 +44,17 @@ class AuthenticationTestCase(ModoTestCase):
|
||||
self.assertTrue(response.url.endswith(reverse("core:dashboard")))
|
||||
|
||||
|
||||
class ChangeDefaultAdminTestCase(TestCase):
|
||||
"""Try to change the default username."""
|
||||
|
||||
def test_management_command(self):
|
||||
"""Use dedicated option."""
|
||||
management.call_command(
|
||||
"load_initial_data", "--admin-username", "modoadmin")
|
||||
self.assertTrue(
|
||||
self.client.login(username="modoadmin", password="password"))
|
||||
|
||||
|
||||
class DashboardTestCase(ModoTestCase):
|
||||
"""Dashboard tests."""
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class DeployTest(unittest.TestCase):
|
||||
self.dbhost, self.projname)
|
||||
cmd = (
|
||||
"modoboa-admin.py deploy --collectstatic "
|
||||
"--dburl %s --domain %s %s"
|
||||
"--dburl %s --domain %s --admin-username admin %s"
|
||||
% (dburl, 'localhost', self.projname)
|
||||
)
|
||||
code, output = exec_cmd(cmd, cwd=self.workdir)
|
||||
|
||||
Reference in New Issue
Block a user