[PR #4828] [MERGED] Refine and Standardize Username Constraints #4782

Closed
opened 2026-02-22 18:36:31 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Mintplex-Labs/anything-llm/pull/4828
Author: @angelplusultra
Created: 1/7/2026
Status: Merged
Merged: 1/26/2026
Merged by: @timothycarambat

Base: masterHead: 4809-standardize-username-constraints


📝 Commits (10+)

  • 28f69a6 Implement Unix username standard validations on username creation and updating.
  • 0b615c1 Remove leading underscore permissibility | Replace hardcoded username rules with a centralized USERNAME_REQUIREMENTS_TEXT for better maintainability.
  • ce83e69 Add username requirements translations for invite and admin user creation | Replace hardcoded username requirements with localized strings in user modals
  • ce9a3f0 Refactor username requirements localization
  • 20badb5 Remove unneeded comment | Move Regex comment to validator fn
  • e5b6204 Remove username validation utility function to keep validation responsibilities on the server | Allow onboarding flow multi-user mode username creation step to send pre-validated credentials to server.
  • f8c1f02 Enhance error handling in system endpoints by returning a JSON response with error details instead of a plain status for internal server errors.
  • e3ffd5f Update username requirement localization in AccountModal and UserSetup components to use centralized translation key.
  • 970d1f5 Merge branch 'master' of github.com:Mintplex-Labs/anything-llm into 4809-standardize-username-constraints
  • 66c8589 test enforcements

📊 Changes

33 files changed (+207 additions, -121 deletions)

View changed files

📝 frontend/src/components/UserMenu/AccountModal/index.jsx (+9 -2)
📝 frontend/src/locales/ar/common.js (+2 -3)
📝 frontend/src/locales/cs/common.js (+2 -4)
📝 frontend/src/locales/da/common.js (+2 -4)
📝 frontend/src/locales/de/common.js (+2 -4)
📝 frontend/src/locales/en/common.js (+2 -4)
📝 frontend/src/locales/es/common.js (+2 -4)
📝 frontend/src/locales/et/common.js (+2 -4)
📝 frontend/src/locales/fa/common.js (+2 -2)
📝 frontend/src/locales/fr/common.js (+2 -4)
📝 frontend/src/locales/he/common.js (+2 -4)
📝 frontend/src/locales/it/common.js (+2 -2)
📝 frontend/src/locales/ja/common.js (+2 -4)
📝 frontend/src/locales/ko/common.js (+2 -4)
📝 frontend/src/locales/lv/common.js (+2 -4)
📝 frontend/src/locales/nl/common.js (+2 -4)
📝 frontend/src/locales/pl/common.js (+2 -4)
📝 frontend/src/locales/pt_BR/common.js (+2 -4)
📝 frontend/src/locales/ro/common.js (+2 -4)
📝 frontend/src/locales/ru/common.js (+2 -4)

...and 13 more files

📄 Description

Pull Request Type

  • feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 🔨 chore
  • 📝 docs

Relevant Issues

resolves #4809

What is in this change?

This PR refactors username validation to use Unix-style constraints consistently across the entire application with proper internationalization support:

Standardized Username Requirements:

  • Length: 2-32 characters (previously 2-100)
  • Must start with a lowercase letter
  • Can only contain: lowercase letters, numbers, underscores, hyphens, and periods
  • Removed support for uppercase letters and special characters (@, %, +, -)

Key Changes:

  1. Centralized Validation Utility - Created frontend/src/utils/username.js with:

    • Shared validation constants (USERNAME_MIN_LENGTH, USERNAME_MAX_LENGTH, USERNAME_PATTERN)
    • Unix-style regex pattern (/^[a-z][a-z0-9._-]*$/)
    • validateUsername() function for programmatic validation with detailed error messages
  2. Internationalization (i18n) - Added localized username requirement strings:

    • invite.username_requirements
    • admin.users.username_requirements
    • security.multiuser.enable.username_requirements
    • Updated existing locale strings in onboarding and account sections
  3. Frontend Form Updates - All user creation/edit forms now use:

    • Shared validation constants from utility file
    • HTML5 form validation attributes (minLength, maxLength, pattern)
    • Translated help text via useTranslation() hook
    • Affected forms:
      • Admin user creation/editing
      • Multi-user mode setup with client-side validation before submission
      • User onboarding flow with live validation
      • Account settings modal
      • Invite acceptance flow
  4. Backend Validation - Updated server/models/user.js:

    • Aligned regex pattern with frontend Unix-style constraints
    • Enhanced username validation function to check regex pattern
    • Removed duplicate validation logic
    • Consistent error messages between frontend and backend

Files Modified:

  • frontend/src/utils/username.js (new file)
  • frontend/src/locales/en/common.js
  • frontend/src/components/UserMenu/AccountModal/index.jsx
  • frontend/src/pages/Admin/Users/NewUserModal/index.jsx
  • frontend/src/pages/Admin/Users/UserRow/EditUserModal/index.jsx
  • frontend/src/pages/GeneralSettings/Security/index.jsx
  • frontend/src/pages/Invite/NewUserModal/index.jsx
  • frontend/src/pages/OnboardingFlow/Steps/UserSetup/index.jsx
  • server/models/user.js

Additional Information

The translation normalization updates are included in #4832

Developer Validations

  • I ran yarn lint from the root of the repo & committed changes
  • Relevant documentation has been updated
  • I have tested my code functionality
  • Docker build succeeds locally

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Mintplex-Labs/anything-llm/pull/4828 **Author:** [@angelplusultra](https://github.com/angelplusultra) **Created:** 1/7/2026 **Status:** ✅ Merged **Merged:** 1/26/2026 **Merged by:** [@timothycarambat](https://github.com/timothycarambat) **Base:** `master` ← **Head:** `4809-standardize-username-constraints` --- ### 📝 Commits (10+) - [`28f69a6`](https://github.com/Mintplex-Labs/anything-llm/commit/28f69a66ac6cd08942452ffdce282dbf4988940f) Implement Unix username standard validations on username creation and updating. - [`0b615c1`](https://github.com/Mintplex-Labs/anything-llm/commit/0b615c1bd2418f1e6b13bb6f6348236e935b622f) Remove leading underscore permissibility | Replace hardcoded username rules with a centralized USERNAME_REQUIREMENTS_TEXT for better maintainability. - [`ce83e69`](https://github.com/Mintplex-Labs/anything-llm/commit/ce83e69324fc948f8191b1a19cf235cf681782e1) Add username requirements translations for invite and admin user creation | Replace hardcoded username requirements with localized strings in user modals - [`ce9a3f0`](https://github.com/Mintplex-Labs/anything-llm/commit/ce9a3f0e04ec23b766dcd8f2eacbabb0658e7d68) Refactor username requirements localization - [`20badb5`](https://github.com/Mintplex-Labs/anything-llm/commit/20badb5cfd1f2319212e061d0e272dbfe87ae899) Remove unneeded comment | Move Regex comment to validator fn - [`e5b6204`](https://github.com/Mintplex-Labs/anything-llm/commit/e5b620404044f210375b3f715f5f7db7735f4118) Remove username validation utility function to keep validation responsibilities on the server | Allow onboarding flow multi-user mode username creation step to send pre-validated credentials to server. - [`f8c1f02`](https://github.com/Mintplex-Labs/anything-llm/commit/f8c1f029070ce6860ef0afcbf2be8318a76da216) Enhance error handling in system endpoints by returning a JSON response with error details instead of a plain status for internal server errors. - [`e3ffd5f`](https://github.com/Mintplex-Labs/anything-llm/commit/e3ffd5fda8b35ddf95db99a618d5738a0485d05d) Update username requirement localization in AccountModal and UserSetup components to use centralized translation key. - [`970d1f5`](https://github.com/Mintplex-Labs/anything-llm/commit/970d1f594770f4631a7562b4358d6fd077fabdc6) Merge branch 'master' of github.com:Mintplex-Labs/anything-llm into 4809-standardize-username-constraints - [`66c8589`](https://github.com/Mintplex-Labs/anything-llm/commit/66c8589647ad0cae8f34614dfe4caa6361514361) test enforcements ### 📊 Changes **33 files changed** (+207 additions, -121 deletions) <details> <summary>View changed files</summary> 📝 `frontend/src/components/UserMenu/AccountModal/index.jsx` (+9 -2) 📝 `frontend/src/locales/ar/common.js` (+2 -3) 📝 `frontend/src/locales/cs/common.js` (+2 -4) 📝 `frontend/src/locales/da/common.js` (+2 -4) 📝 `frontend/src/locales/de/common.js` (+2 -4) 📝 `frontend/src/locales/en/common.js` (+2 -4) 📝 `frontend/src/locales/es/common.js` (+2 -4) 📝 `frontend/src/locales/et/common.js` (+2 -4) 📝 `frontend/src/locales/fa/common.js` (+2 -2) 📝 `frontend/src/locales/fr/common.js` (+2 -4) 📝 `frontend/src/locales/he/common.js` (+2 -4) 📝 `frontend/src/locales/it/common.js` (+2 -2) 📝 `frontend/src/locales/ja/common.js` (+2 -4) 📝 `frontend/src/locales/ko/common.js` (+2 -4) 📝 `frontend/src/locales/lv/common.js` (+2 -4) 📝 `frontend/src/locales/nl/common.js` (+2 -4) 📝 `frontend/src/locales/pl/common.js` (+2 -4) 📝 `frontend/src/locales/pt_BR/common.js` (+2 -4) 📝 `frontend/src/locales/ro/common.js` (+2 -4) 📝 `frontend/src/locales/ru/common.js` (+2 -4) _...and 13 more files_ </details> ### 📄 Description ### Pull Request Type <!-- For change type, change [ ] to [x]. --> - [ ] ✨ feat - [ ] 🐛 fix - [x] ♻️ refactor - [ ] 💄 style - [ ] 🔨 chore - [ ] 📝 docs ### Relevant Issues <!-- Use "resolves #xxx" to auto resolve on merge. Otherwise, please use "connect #xxx" --> resolves #4809 ### What is in this change? <!-- Describe the changes in this PR that are impactful to the repo. --> This PR refactors username validation to use Unix-style constraints consistently across the entire application with proper internationalization support: **Standardized Username Requirements:** - Length: 2-32 characters (previously 2-100) - Must start with a lowercase letter - Can only contain: lowercase letters, numbers, underscores, hyphens, and periods - Removed support for uppercase letters and special characters (@, %, +, -) **Key Changes:** 1. **Centralized Validation Utility** - Created `frontend/src/utils/username.js` with: - Shared validation constants (`USERNAME_MIN_LENGTH`, `USERNAME_MAX_LENGTH`, `USERNAME_PATTERN`) - Unix-style regex pattern (`/^[a-z][a-z0-9._-]*$/`) - `validateUsername()` function for programmatic validation with detailed error messages 2. **Internationalization (i18n)** - Added localized username requirement strings: - `invite.username_requirements` - `admin.users.username_requirements` - `security.multiuser.enable.username_requirements` - Updated existing locale strings in `onboarding` and `account` sections 3. **Frontend Form Updates** - All user creation/edit forms now use: - Shared validation constants from utility file - HTML5 form validation attributes (`minLength`, `maxLength`, `pattern`) - Translated help text via `useTranslation()` hook - **Affected forms:** - Admin user creation/editing - Multi-user mode setup with client-side validation before submission - User onboarding flow with live validation - Account settings modal - Invite acceptance flow 4. **Backend Validation** - Updated `server/models/user.js`: - Aligned regex pattern with frontend Unix-style constraints - Enhanced `username` validation function to check regex pattern - Removed duplicate validation logic - Consistent error messages between frontend and backend **Files Modified:** - `frontend/src/utils/username.js` (new file) - `frontend/src/locales/en/common.js` - `frontend/src/components/UserMenu/AccountModal/index.jsx` - `frontend/src/pages/Admin/Users/NewUserModal/index.jsx` - `frontend/src/pages/Admin/Users/UserRow/EditUserModal/index.jsx` - `frontend/src/pages/GeneralSettings/Security/index.jsx` - `frontend/src/pages/Invite/NewUserModal/index.jsx` - `frontend/src/pages/OnboardingFlow/Steps/UserSetup/index.jsx` - `server/models/user.js` ### Additional Information <!-- Add any other context about the Pull Request here that was not captured above. --> The translation normalization updates are included in #4832 ### Developer Validations <!-- All of the applicable items should be checked. --> - [x] I ran `yarn lint` from the root of the repo & committed changes - [x] Relevant documentation has been updated - [x] I have tested my code functionality - [x] Docker build succeeds locally --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-22 18:36:31 -05:00
yindo closed this issue 2026-02-22 18:36:31 -05:00
yindo changed title from [PR #4828] Refine and Standardize Username Constraints to [PR #4828] [MERGED] Refine and Standardize Username Constraints 2026-06-05 15:20:21 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#4782