Possibility to change default username for initial admin.

see #903
This commit is contained in:
Antoine Nguyen
2016-09-12 16:19:02 +02:00
parent 942763784c
commit f97457c30a
4 changed files with 27 additions and 4 deletions
+6 -1
View File
@@ -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
View File
@@ -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."""
+1 -1
View File
@@ -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)