Skip to content

Commit

Permalink
Merge pull request #280 from lsst-ts/tickets/DM-45973
Browse files Browse the repository at this point in the history
Remove cmd user creation for production deployments
  • Loading branch information
sebastian-aranda authored Sep 6, 2024
2 parents a95d80e + 2c607e3 commit 0f1313c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 36 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Version History
===============

v7.0.4
------

* Remove cmd user creation for production deployments `<https://github.com/lsst-ts/LOVE-manager/pull/280>`_

v7.0.3
------

Expand Down
66 changes: 32 additions & 34 deletions manager/api/management/commands/createusers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand All @@ -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",)
Expand Down Expand Up @@ -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):
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion manager/api/management/commands/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion manager/runserver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0f1313c

Please sign in to comment.