Skip to content

Diya 🔥 feat: Enhanced existing User State Feature#2148

Merged
one-community merged 3 commits intodevelopmentfrom
Diya_UserStateFeature
Apr 7, 2026
Merged

Diya 🔥 feat: Enhanced existing User State Feature#2148
one-community merged 3 commits intodevelopmentfrom
Diya_UserStateFeature

Conversation

@DiyaWadhwani
Copy link
Copy Markdown
Contributor

Description

Backend implementation for the enhanced User State Feature. Introduces the emoji field to the UserStateCatalog model, expands the catalog management API with emoji/color support, adds a batch selections endpoint for efficient team list loading, and includes password-protected utility scripts for catalog and selection management.

Related PRS (if any):

This backend PR is related to the frontend PR #5098

Main changes explained:

  • Update src/models/userStateCatalog.js — add emoji field (String, default ''), update color default from 'blue' to '#3498db'
  • Update src/controllers/userStateController.js — accept and sanitize emoji in createCatalog and updateCatalog; update ALLOWED_COLORS to hex values (15 colors); add generateKey with random suffix replacing slugify-based key generation to prevent emoji collision; add duplicate detection (same label + emoji blocked with 409); fix updateCatalog label clash check to allow case-only edits; fix isActive logic to only cascade-delete user selections when explicitly set to false; add getBatchUserSelections for single-call team selections fetch (supports up to 3000 userIds); add getCatalogItemUsage to count users assigned a given state before deletion
  • Update src/routes/userState.js — register POST /selections/batch and GET /catalog/:key/usage routes
  • Create src/scripts/seedUserCatalog.js — idempotent seed script for 5 default states with emoji, label, color, and order; skips existing keys with log output
  • Create src/scripts/resetUserCatalog.js — password-protected (RESET_USERCATALOG_PASSWORD env var) catalog reset script with double confirmation prompt
  • Create src/scripts/resetUserStateSelections.js — password-protected (RESET_USERSELECTIONS_PASSWORD env var) selections reset script with double confirmation prompt
  • Update .gitignore — remove scripts/ ignore rule so utility scripts are tracked

How to test:

Follow testing instructions on the frontend PR #5098

Note:

  • Scripts require separate env variables (RESET_USERCATALOG_PASSWORD, RESET_USERSELECTIONS_PASSWORD) — add these to your .env before running. Reach out to author of this PR for passwords
  • Run node src/scripts/seedUserCatalog.js once on each environment (dev/prod) to populate the default catalog states — script is safe to re-run (skips existing keys)
  • Do not run reset scripts unless explicitly required — they are destructive and password-protected

@one-community one-community merged commit 11a052e into development Apr 7, 2026
2 checks passed
@one-community one-community changed the title Diya feat: Enhanced existing User State Feature Diya 🔥 feat: Enhanced existing User State Feature Apr 7, 2026
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 7, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants