Improve GrampsWeb admin script: reset password if user exists (STI-90)
Some checks failed
CI/CD Pipeline / test (push) Has been cancelled
CI/CD Pipeline / deploy (push) Has been cancelled
Code Quality / quality (push) Has been cancelled

When the admin user already exists with an unknown password, the startup
script now attempts to reset the password instead of skipping. This
handles the case where GrampsWeb was previously set up without tracking
the admin credentials.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
SysAdmin Agent
2026-05-09 14:01:06 +00:00
parent 3f9c3d6527
commit 63315d388f

View File

@@ -225,7 +225,7 @@ services:
python3 << 'PYEOF' 2>&1 | grep -v Gtk
from gramps_webapi.app import create_app
from gramps_webapi.auth import add_user, get_number_users, ROLE_OWNER
import os
import os, sqlite3, hashlib
email = os.environ.get('GRAMPSWEB_ADMIN_EMAIL', '')
pw = os.environ.get('GRAMPSWEB_ADMIN_PASSWORD', '')
if email and pw:
@@ -235,7 +235,17 @@ services:
add_user(name='Admin', email=email, password=pw, role=ROLE_OWNER)
print('[grampsweb] Admin user created')
else:
print('[grampsweb] Users already exist, skipping')
try:
add_user(name='Admin', email=email, password=pw, role=ROLE_OWNER)
print('[grampsweb] Admin user created')
except Exception:
from gramps_webapi.auth import get_user_details, modify_user
try:
user = get_user_details(name='Admin')
modify_user(name='Admin', password=pw, role=ROLE_OWNER)
print('[grampsweb] Admin user password reset')
except Exception as e:
print(f'[grampsweb] Could not update admin user: {e}')
else:
print('[grampsweb] No admin credentials configured, skipping')
PYEOF