1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mygpo_ynh.git synced 2024-09-03 19:55:52 +02:00
mygpo_ynh/hooks/post_user_delete
Jules Bertholet eff624b855 Don't run Python as root
We don't want to give code from the internet that hasn't been reviewed more privileges than it needs
2021-03-30 00:29:43 -04:00

26 lines
No EOL
582 B
Bash

#!/usr/bin/env bash
source /usr/share/yunohost/helpers
app="${0//50-}"
username=$1
purge=$2
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
env_path=$final_path/envs/prod
pushd $final_path
source $final_path/venv/bin/activate
sudo -u $app $final_path/venv/bin/envdir $env_path python3 $final_path/manage.py shell <<< "
from django.contrib.auth import get_user_model
User = get_user_model()
try:
user = User.objects.get(username='$user')
user.is_active = False
user.save()
if $purge:
user.delete()
except User.DoesNotExist:
pass
"
popd