Fix #4996 + Fix HTTP 500 errors when creating users (domain folder/role) and folders (roles cache refresh) #5009
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes multiple issues reproducible on TeamPass 3.1.5.17 (fresh installs and restored production backups).
TPsystem user (TP_USER_ID = 9999997) is created successfully on fresh installs (fixes admin-side HTTP 500 / TypeError incryption()when TP user is missing).auth_type='local'(fixes missing Reset password action whenauth_typedefaults to NULL).auth_typeon soft-delete so restored users keep their original authentication method (fixes restored accounts stuck withauth_type='none', and missing actions like local password reset).users.fonction_id(no longer present in recent schemas).Affected version
1) Root cause & fix (installer): missing internal “TP” system user (TP_USER_ID = 9999997)
On fresh installs, some admin pages/actions can trigger an HTTP 500 (TypeError in
cryption()) when the code expects the internalTPuser to exist in theuserstable, but the lookupSELECT … WHERE id = TP_USER_IDreturns no row (so$userInfobecomesnull).Why the TP user is missing
userstable no longer includes legacy columns such asgroupes_visibles,fonction_id,groupes_interdits,favourites,latest_items.install/install-steps/run.step6.phpstill attempts to create theTPuser using anINSERTreferencing those removed columns.Quick DB check
Expected: OTV (9999991), TP (9999997), API (9999999). In the broken case, TP is missing.
Fix
Update
install/install-steps/run.step6.phpand remove the legacy fields from the TP-user INSERT:groupes_visibles,fonction_id,groupes_interdits,favourites,latest_items. Optionally setemailanduser_iptonone.Optional hardening note: a defensive null-check in
sources/admin.queries.phpcould avoid a hard 500 if TP is missing, but the correct fix is to ensure the installer creates TP successfully.2) Fix: HTTP 500 when creating a user with “Create a new folder and a role for …”
How to reproduce
Observed error (example)
Root cause
The domain folder insertion into
nested_treedid not setcategories. On strict DB configurations wherenested_tree.categorieshas no default value, the insert fails and triggers an HTTP 500.Fix
nested_tree.categorieswhen inserting the domain folder.users.fonction_id(and an incorrectis_int()usage) with a proper role assignment viasetUserRoles().2b) Additional fix: local users created with NULL auth_type (missing reset password action)
Context
On instances where
teampass_users.auth_typehas DEFAULT NULL, locally-created users could end up withauth_type = NULL. In this case, the UI hides local-password actions (e.g. the Reset password button), even though the user is a regular local account.Evidence
Fix
In
sources/users.queries.php, explicitly setauth_type = 'local'when creating a user from the admin UI (local user creation flow). This ensures the UI consistently exposes local password management actions.Validation
auth_type = 'local'.auth_type = 'local'.auth_type = 'ldap'and can authenticate/access items normally.3) Fix: HTTP 500 when creating a folder (Folders page)
How to reproduce
Observed error (example)
Root cause
A legacy query in
getUsersWithRoles()still selectsfonction_idfromusers, but roles are stored inusers_roleson recent schemas. This breaks the cache refresh during folder creation.Fix
getUsersWithRoles()to build role lists fromusers_roles(LEFT JOIN + GROUP_CONCAT) instead of selectingusers.fonction_id.Testing
auth_type='local'and the UI exposes the Reset password action.