Permalink
Browse files

Possibility to change default username for initial admin.

see #903
  • Loading branch information...
tonioo committed Sep 12, 2016
1 parent 9427637 commit f97457c30a7792d10d76676ef7d981ae3e40ae92
Showing with 27 additions and 4 deletions.
  1. +6 −1 modoboa/core/commands/deploy.py
  2. +8 −1 modoboa/core/management/commands/load_initial_data.py
  3. +12 −1 modoboa/core/tests.py
  4. +1 −1 tests.py
@@ -82,6 +82,10 @@ def __init__(self, *args, **kwargs):
'--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 @@ def handle(self, parsed_args):
"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(
View
@@ -4,7 +4,7 @@
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 @@ def test_authentication(self):
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."""
View
@@ -24,7 +24,7 @@ def test_silent(self):
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)

0 comments on commit f97457c

Please sign in to comment.