From 266ba5295f630d768492300fd7736c29ead9b706 Mon Sep 17 00:00:00 2001 From: adam-sutton-1992 <60137864+adam-sutton-1992@users.noreply.github.com> Date: Thu, 18 Jan 2024 16:46:59 +0000 Subject: [PATCH] Cu 862j1wq35 default user group (#171) * initial commit for a default user group * fixed issue with multiple permissions * pulled group creation out of if statement * added new script for a group to be created --------- Authored-by: Adam Sutton --- webapp/scripts/create_group.py | 14 ++++++++++++++ webapp/scripts/run.sh | 4 ++++ 2 files changed, 18 insertions(+) create mode 100644 webapp/scripts/create_group.py diff --git a/webapp/scripts/create_group.py b/webapp/scripts/create_group.py new file mode 100644 index 00000000..acfda277 --- /dev/null +++ b/webapp/scripts/create_group.py @@ -0,0 +1,14 @@ +from django.contrib.auth.models import Group, Permission +from itertools import chain + +print("Checking for Default User Group") +group, created = Group.objects.get_or_create(name='user_group') +if created: + print("No Default User Group Found - Creating with Permissions") +dataset = list(Permission.objects.filter(codename__contains='dataset').exclude(codename__contains='delete')) +concept = list(Permission.objects.filter(codename__contains='concept')) +project = list(Permission.objects.filter(codename__contains="projectannotateentities").exclude(codename__contains="delete")) +permissions = chain(dataset, concept, project) +for p in permissions: + group.permissions.add(p) +print("User_group created with minimum correct permissions") \ No newline at end of file diff --git a/webapp/scripts/run.sh b/webapp/scripts/run.sh index be575207..3f2285e9 100755 --- a/webapp/scripts/run.sh +++ b/webapp/scripts/run.sh @@ -17,6 +17,7 @@ python /home/api/manage.py migrate api --noinput python /home/api/manage.py process_tasks --log-std & # create a new super user, with username and password 'admin' +# also create a user group `user_group` that prevents users from deleting models echo "from django.contrib.auth import get_user_model User = get_user_model() if User.objects.count() == 0: @@ -27,6 +28,9 @@ if [ $LOAD_EXAMPLES ]; then python /home/scripts/load_examples.py & fi +# Creating a default user group that can manage projects and annotate but not delete +python manage.py shell < /home/scripts/create_group.py + # RESET any Env vars to original stat export RESUBMIT_ALL_ON_STARTUP=$TMP_RESUBMIT_ALL_VAR