Skip to content

Commit

Permalink
Cu 862j1wq35 default user group (#171)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
adam-sutton-1992 authored Jan 18, 2024
1 parent a74c704 commit 266ba52
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions webapp/scripts/create_group.py
Original file line number Diff line number Diff line change
@@ -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")
4 changes: 4 additions & 0 deletions webapp/scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down

0 comments on commit 266ba52

Please sign in to comment.