[BUG] POST /api/v1/custom-user-status.update silently overwrites statusType with empty string when omitted

Aperta
#43,591 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Supriyo760 ci sta già lavorando.

Dal 7/11/2026.

  • #43592 di @Supriyo760 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
mongodb, node.js, typescript
Ambito
api, backend, databases

Direzione di ricerca

Start with apps/meteor/server/api/v1/custom-user-status.ts and trace how omitted statusType reaches insertOrUpdateUserStatus.ts; inspect the update tests around this endpoint. Done means updating only the name preserves the existing presence indicator, with a regression test covering an omitted statusType.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

type: bug
Description:

When updating a custom user status using the REST API endpoint POST /api/v1/custom-user-status.update without providing statusType (which is optional according to the endpoint schema isCustomUserStatusUpdateProps), the endpoint silently sets statusType to an empty string "" in MongoDB, permanently erasing the user status presence indicator.

Steps to reproduce:
  1. Create a custom user status with a presence indicator (e.g. name: "Supriyo", statusType: "busy").
  2. Confirm the presence indicator shows as busy in the UI table (/admin/user-status).
  3. Send a POST request to /api/v1/custom-user-status.update to update only the name, omitting statusType:
    {
      "_id": "6aef44df9bb283fd2954335f",
      "name": "Supriyo"
    }
    
  4. Query /api/v1/custom-user-status.list or view the Administration -> User status page.
Expected behavior:

The existing statusType ("busy") should be preserved when statusType is not provided in the update payload.

Actual behavior:

statusType is overwritten with "" (empty string) in MongoDB, causing permanent data loss. The presence indicator badge disappears completely from the UI table.

Visual Evidence:

1. Before Update (UI Table shows "busy"):

Image

2. API Request (omitting statusType):

Image

3. Server Response (statusType is wiped to empty string):

Image

4. After Update (UI Table presence is completely wiped):

Image
Server Setup Information:
  • Version of Rocket.Chat Server: 8.9.1 / 9.1.0-develop
  • License Type: Community
  • Number of Users: 1
  • Operating System: Windows / Linux
  • Deployment Method: docker / source
  • Number of Running Instances: 1
  • DB Replicaset Oplog: Enabled
  • NodeJS Version: 24.x
  • MongoDB Version: 8.0
Client Setup Information
  • Desktop App or Browser Version: Chrome
  • Operating System: Windows 11
Additional context

Root Cause:
In apps/meteor/server/api/v1/custom-user-status.ts (line 233):

const userStatusData = {
    _id: this.bodyParams._id,
    name: this.bodyParams.name,
    statusType: this.bodyParams.statusType || '', // <-- Defaults undefined to ''
};

Because this.bodyParams.statusType is undefined, it evaluates to ''. Then in insertOrUpdateUserStatus.ts (line 83):

if (userStatusData.statusType !== userStatusData.previousStatusType) {
    await CustomUserStatus.setStatusType(userStatusData._id, userStatusData.statusType);
}

userStatusData.previousStatusType is never passed from the endpoint (undefined), so '' !== undefined evaluates to true, and MongoDB writes statusType: '' over the existing record.

I have a fix ready with automated end-to-end test cases and would love to open a PR for this.

Lingua principale
TypeScript
Stelle
46.5k
Fork
14.1k
Merge medio
1g 21h
PR unite (30g)
381

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di RocketChat/Rocket.Chat

Tutte le issue di RocketChat/Rocket.Chat

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.