diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d145199f..dad309ac 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,11 @@ Version History =============== +v7.0.4 +------ + +* Remove cmd user creation for production deployments ``_ + v7.0.3 ------ diff --git a/manager/api/management/commands/createusers.py b/manager/api/management/commands/createusers.py index 6bc45461..9170dc9f 100644 --- a/manager/api/management/commands/createusers.py +++ b/manager/api/management/commands/createusers.py @@ -26,7 +26,6 @@ from django.core.management.base import BaseCommand user_username = "user" -test_username = "test" cmd_user_username = "cmd_user" admin_username = "admin" cmd_groupname = "cmd" @@ -39,17 +38,17 @@ class Command(BaseCommand): It creates 4 users with the following characteristics and permissions: - "admin": has all the permissions, it is a Django superuser - - "user": basic user with no permissions) + - "user": basic user with no commands execution permissions + but with permissions to add, edit and delete views - "cmd_user": basic user with commands execution permissions - - "test": basic user with commands execution permissions It also creates 2 Groups: "cmd_group", which defines the commands execution permissions. - "ui_framework_group", which defines the permissions to add, - edit and delete views. + "ui_framework_group", which defines the permissions + to add, edit and delete views. - "cmd_user" and "test" users belong to "cmd_group". - "cmd_user" and "test" users belong to "ui_framework_group". + "cmd_user" user belongs to "cmd_group". + "cmd_user" and "user" user belong to "ui_framework_group". The command receives arguments to set the passwords of the users, run `python manage.py createusers --help` for help. @@ -60,16 +59,16 @@ class Command(BaseCommand): It creates 4 users with the following characteristics and permissions: - "admin": has all the permissions, it is a Django superuser - - "user": basic user with no permissions) + - "user": basic user with no commands execution permissions, + but with permissions to add, edit and delete views - "cmd_user": basic user with commands execution permissions - - "test": basic user with commands execution permissions It also creates 2 Groups: "cmd_group", which defines the commands execution permissions. "ui_framework_group", which defines the permissions to add, edit and delete views. - "cmd_user" and "test" users belong to "cmd_group". - "cmd_user" and "test" users belong to "ui_framework_group".""" + "cmd_user" user belongs to "cmd_group". + "cmd_user" and "user" user belong to "ui_framework_group".""" requires_migrations_checks = True stealth_options = ("stdin",) @@ -111,7 +110,7 @@ def add_arguments(self, parser): ) parser.add_argument( "--cmduserpass", - help='Specifies password for the users with cmd permissions ("cmd_user" and "test").', + help='Specifies password for the users with cmd permissions ("cmd_user").', ) def handle(self, *args, **options): @@ -129,30 +128,29 @@ def handle(self, *args, **options): user_password = options["userpass"] cmd_password = options["cmduserpass"] - # Create users - admin = self._create_user(admin_username, admin_password) - self._create_user(user_username, user_password) - cmd_user = self._create_user(cmd_user_username, cmd_password) - test_user = self._create_user(test_username, cmd_password) - - # Make admin superuser and staff - admin.is_superuser = True - admin.is_staff = True - admin.save() - - # Create cmd_group - cmd_group = self._create_cmd_group() - - # Add cmd_user and test users to cmd_group - cmd_group.user_set.add(cmd_user) - cmd_group.user_set.add(test_user) - - # Create ui_framework group + # Create groups ui_framework_group = self._create_ui_framework_group() + cmd_group = self._create_cmd_group() - # Add cmd_user and test users to ui_framework_group - ui_framework_group.user_set.add(cmd_user) - ui_framework_group.user_set.add(test_user) + # Create admin user + if admin_password is not None: + admin = self._create_user(admin_username, admin_password) + + # Make admin superuser and staff + admin.is_superuser = True + admin.is_staff = True + admin.save() + + # Create user user + if user_password is not None: + user_user = self._create_user(user_username, user_password) + ui_framework_group.user_set.add(user_user) + + # Create cmd_user user + if cmd_password is not None: + cmd_user = self._create_user(cmd_user_username, cmd_password) + ui_framework_group.user_set.add(cmd_user) + cmd_group.user_set.add(cmd_user) def _create_user(self, username, password): """Create a given user, if it does not exist. Return it anyway. diff --git a/manager/api/management/commands/tests.py b/manager/api/management/commands/tests.py index cb52c408..b0cee42c 100644 --- a/manager/api/management/commands/tests.py +++ b/manager/api/management/commands/tests.py @@ -51,7 +51,7 @@ def test_command_creates_users(self): command.handle(*[], **options) # Assert: self.assertEqual( - User.objects.count(), old_users_num + 4, "There are no new users" + User.objects.count(), old_users_num + 3, "There are no new users" ) self.assertEqual( Group.objects.count(), old_groups_num + 2, "There is no new group" diff --git a/manager/runserver.sh b/manager/runserver.sh index bfe7c000..d589d995 100755 --- a/manager/runserver.sh +++ b/manager/runserver.sh @@ -12,7 +12,7 @@ echo -e "\nApplying migrations" python manage.py migrate echo -e "\nCreating default users" -python manage.py createusers --adminpass ${ADMIN_USER_PASS} --userpass ${USER_USER_PASS} --cmduserpass ${CMD_USER_PASS} +python manage.py createusers --adminpass ${ADMIN_USER_PASS} --userpass ${USER_USER_PASS} if [ -z ${LOVE_SITE} ]; then love_site="summit" else