1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mygpo_ynh.git synced 2024-09-03 19:55:52 +02:00

Add post_user_delete hook to deactivate user account

This commit is contained in:
Jules Bertholet 2021-03-25 22:00:31 -04:00
parent 64c340fe91
commit 79de807fcd
2 changed files with 27 additions and 3 deletions

26
hooks/post_user_delete Normal file
View file

@ -0,0 +1,26 @@
#!/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
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

View file

@ -125,7 +125,7 @@ ynh_app_setting_set --app=$app --key=datadir --value="$datadir"
#================================================= #=================================================
# ENVDIR CONFIGURATION # ENVDIR CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Setting up envdir..." --weight=1 ynh_script_progression --message="Building configuration..." --weight=1
env_path=$final_path/envs/prod env_path=$final_path/envs/prod
@ -175,7 +175,6 @@ popd || ynh_die
#================================================= #=================================================
ynh_script_progression --message="Configuring systemd services..." --weight=1 ynh_script_progression --message="Configuring systemd services..." --weight=1
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config ynh_add_systemd_config
ynh_add_systemd_config --service="$app-socket" --template systemd.socket ynh_add_systemd_config --service="$app-socket" --template systemd.socket
@ -209,7 +208,6 @@ yunohost service add $app --description="Manage podcast subscriptions, and sync
#================================================= #=================================================
ynh_script_progression --message="Starting systemd services..." --weight=1 ynh_script_progression --message="Starting systemd services..." --weight=1
# Start systemd services # Start systemd services
ynh_systemd_action --service_name=$app-celery --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app-celery --action="start" --log_path="/var/log/$app/$app.log"
ynh_systemd_action --service_name=$app-beat --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app-beat --action="start" --log_path="/var/log/$app/$app.log"