Skip to content

Conversation

@lucas-a-pelegrino
Copy link
Contributor

@lucas-a-pelegrino lucas-a-pelegrino commented Sep 17, 2025

Proposed changes (including videos or screenshots)

This PR adds a deprecation warning for livechat:saveAgentInfo meteor method, as well as it adds an endpoint (livechat/agents.saveInfo)to replace it.

Issue(s)

CTZ-62

Steps to test or reproduce

Further comments

Tests will be implemented on this task

Summary by CodeRabbit

  • New Features
    • Added a REST API endpoint to save Livechat agent information with stricter validation and permission checks.
  • Deprecations
    • Deprecated the legacy method for saving agent info; migrate to the new REST endpoint. Deprecation warnings are logged.
  • Tests
    • Updated integration and end-to-end tests to use the new endpoint for agent updates.
  • Chores
    • Bumped dependencies to latest patch versions for stability and compatibility.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Sep 17, 2025

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Sep 17, 2025

🦋 Changeset detected

Latest commit: f3673f9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 40 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/rest-typings Patch
@rocket.chat/api-client Patch
@rocket.chat/core-services Patch
@rocket.chat/ddp-client Patch
@rocket.chat/http-router Patch
@rocket.chat/models Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/stream-hub-service Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/network-broker Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/livechat Patch
@rocket.chat/mock-providers Patch
@rocket.chat/cron Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch
@rocket.chat/media-calls Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/gazzodown Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-client Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/ui-voip Patch
@rocket.chat/core-typings Patch
@rocket.chat/apps Patch
@rocket.chat/freeswitch Patch
@rocket.chat/model-typings Patch
@rocket.chat/license Patch
@rocket.chat/pdf-worker Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@lucas-a-pelegrino lucas-a-pelegrino added this to the 7.11.0 milestone Sep 17, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 17, 2025

Walkthrough

Introduces a new REST endpoint POST /v1/livechat/agents.saveInfo, updates client and tests to use it, adds request/response validators, and logs deprecation for the Meteor method livechat:saveAgentInfo. Includes dependency bumps and public typings exposure for the new route.

Changes

Cohort / File(s) Summary of changes
REST API: new endpoint
apps/meteor/app/livechat/server/api/v1/agent.ts, packages/rest-typings/src/v1/omnichannel.ts
Adds POST livechat/agents.saveInfo with auth and manage-livechat-agents permission, validates payload/response, checks agent role, calls saveAgentInfo, exposes route via typings; introduces validators isPOSTLivechatAgentSaveInfoParams and POSTLivechatAgentSaveInfoSuccessResponse.
Method deprecation
apps/meteor/app/livechat/server/methods/saveAgentInfo.ts
Logs deprecation for livechat:saveAgentInfo pointing to /v1/livechat/agents.saveInfo; existing logic unchanged.
Client update
apps/meteor/client/views/omnichannel/agents/AgentEdit.tsx
Replaces Meteor method call with REST POST /v1/livechat/agents.saveInfo; adjusts payload shape to { agentId, agentData, agentDepartments }.
Tests update
apps/meteor/tests/data/livechat/users.ts, apps/meteor/tests/e2e/omnichannel/omnichannel-agents.spec.ts
Switches tests from method call to REST endpoint; updates e2e waitForResponse to match **/api/v1/livechat/agents.saveInfo.
Meta / dependency bump
.changeset/cuddly-dots-end.md
Notes patch bumps for @rocket.chat/meteor and @rocket.chat/rest-typings and documents deprecation notice.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Client (UI/Tests)
  participant API as REST API<br>/v1/livechat/agents.saveInfo
  participant Auth as Auth/Permissions
  participant LC as Livechat Service
  participant DB as Data Store

  rect rgba(227,242,253,0.6)
  C->>API: POST agentId, agentData, agentDepartments
  API->>Auth: Validate auth + manage-livechat-agents
  Auth-->>API: OK / 401 / 403
  alt Unauthorized/Forbidden
    API-->>C: 401/403 error
  else Authorized
    API->>LC: hasRole(agentId, 'livechat-agent')
    LC-->>API: true/false
    alt Not agent
      API-->>C: 400 error-user-is-not-agent
    else Is agent
      API->>DB: saveAgentInfo(agentId, data, departments)
      DB-->>API: success
      API-->>C: 200 { success: true }
    end
  end
  end

  note over C,API: Legacy Meteor method logs deprecation and points here
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

stat: ready to merge, stat: QA assured

Suggested reviewers

  • aleksandernsilva
  • sampaiodiego
  • tassoevan

Poem

A rabbit taps out REST with glee,
Hop-hop from RPC to HTTP.
New paths are paved, old ways retire,
Agents saved as tests conspire.
Typings hum, the endpoints sing—
Patchy clouds, a shipping spring. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Linked Issues Check ⚠️ Warning The PR implements the deprecation and replacement endpoint required by CTZ-62 by adding method deprecation logging, a POST /v1/livechat/agents.saveInfo route, typings, and client updates CTZ-62; however, the linked testing task CORE-1365 appears not fully satisfied because while some test files were adapted to call the new endpoint there is no evidence of dedicated tests covering the endpoint's success and error cases [CORE-1365]. Add the tests required by CORE-1365 (unit and e2e coverage for success and error paths of the new endpoint) or explicitly state that tests will be delivered in a follow-up PR and adjust the linked-issue references accordingly.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title concisely and accurately summarizes the primary change: adding a deprecation warning for the Meteor method livechat:saveAgentInfo and introducing a replacement REST endpoint; it is specific, directly related to the changeset, and readable for teammates scanning history.
Out of Scope Changes Check ✅ Passed All changes in the provided summaries are scoped to the deprecation and the new endpoint (server endpoint and types, method deprecation log, client migration to use the endpoint, and related test updates); I did not observe unrelated feature changes or refactors in the summarized files.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/v7/CTZ-62

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Sep 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.27%. Comparing base (72d9474) to head (f3673f9).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #36975      +/-   ##
===========================================
- Coverage    67.34%   66.27%   -1.08%     
===========================================
  Files         3339     3393      +54     
  Lines       113205   115459    +2254     
  Branches     20532    21164     +632     
===========================================
+ Hits         76234    76516     +282     
- Misses       34361    36332    +1971     
- Partials      2610     2611       +1     
Flag Coverage Δ
e2e 56.91% <100.00%> (-0.03%) ⬇️
unit 71.25% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lucas-a-pelegrino lucas-a-pelegrino marked this pull request as ready for review September 18, 2025 13:16
@lucas-a-pelegrino lucas-a-pelegrino requested review from a team as code owners September 18, 2025 13:16
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
.changeset/cuddly-dots-end.md (1)

1-7: Fix stray character and clarify endpoint path in changeset

There’s an orphan “7” at the end and the replacement endpoint should include the version prefix for clarity.

Apply this diff:

 Adds deprecation warning on `livechat:saveAgentInfo` with new endpoint replacing it; `livechat/agents.saveInfo`
+Adds deprecation warning for `livechat:saveAgentInfo`; replacement endpoint: `POST /v1/livechat/agents.saveInfo`.
-7
apps/meteor/client/views/omnichannel/agents/AgentEdit.tsx (1)

82-92: Send only mutable fields in agentData (avoid name/username/email), and precompute department IDs

Prevents leaking read‑only fields and makes payload minimal/explicit.

-  await saveAgentInfo({
-    agentId: agentData._id,
-    agentData: data,
-    agentDepartments: departments.map((dep) => dep.value),
-  });
+  const agentDepartmentsIds = departments.map((dep) => dep.value);
+  const { maxNumberSimultaneousChat, voipExtension } = data;
+  await saveAgentInfo({
+    agentId: agentData._id,
+    agentData: {
+      ...(typeof maxNumberSimultaneousChat === 'number' ? { maxNumberSimultaneousChat } : {}),
+      ...(voipEnabled ? { voipExtension } : {}),
+    },
+    agentDepartments: agentDepartmentsIds,
+  });
packages/rest-typings/src/v1/omnichannel.ts (1)

1726-1767: Add route signature to OmnichannelEndpoints to avoid relying on server-side module augmentation for client typing

You defined validators but didn’t wire the endpoint into the OmnichannelEndpoints map. Adding it here ensures useEndpoint gets proper types in the client without depending on ambient augmentation declared in a server file.

 export type OmnichannelEndpoints = {
+  '/v1/livechat/agents.saveInfo': {
+    POST: (params: POSTLivechatAgentSaveInfoParams) => void;
+  };

Please confirm TS type inference for useEndpoint('POST', '/v1/livechat/agents.saveInfo') works in the client after this change. If you prefer keeping the server-side augmentation, ensure the ambient declaration is included in the client TS program.

apps/meteor/tests/data/livechat/users.ts (1)

101-116: Assert success:true in response to catch silent failures

Currently only status and content-type are asserted.

   await request
     .post(api('livechat/agents.saveInfo'))
     .set(credentials)
     .send({
       agentId,
       agentData: livechatSettings,
       agentDepartments,
     })
     .expect('Content-Type', 'application/json')
-    .expect(200);
+    .expect(200)
+    .expect((res) => {
+      if (res.body?.success !== true) throw new Error('Expected { success: true } from livechat/agents.saveInfo');
+    });
apps/meteor/tests/e2e/omnichannel/omnichannel-agents.spec.ts (1)

118-118: Tighten waitForResponse filter (URL + method) to reduce flakiness

Use a predicate to ensure it’s the POST to the exact endpoint.

-    const response = page.waitForResponse('**/api/v1/livechat/agents.saveInfo');
+    const response = page.waitForResponse((r) => r.url().endsWith('/api/v1/livechat/agents.saveInfo') && r.request().method() === 'POST');
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between b1cefb0 and a8fa8f3.

📒 Files selected for processing (7)
  • .changeset/cuddly-dots-end.md (1 hunks)
  • apps/meteor/app/livechat/server/api/v1/agent.ts (2 hunks)
  • apps/meteor/app/livechat/server/methods/saveAgentInfo.ts (2 hunks)
  • apps/meteor/client/views/omnichannel/agents/AgentEdit.tsx (2 hunks)
  • apps/meteor/tests/data/livechat/users.ts (2 hunks)
  • apps/meteor/tests/e2e/omnichannel/omnichannel-agents.spec.ts (1 hunks)
  • packages/rest-typings/src/v1/omnichannel.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
apps/meteor/tests/e2e/**/*.spec.ts

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

apps/meteor/tests/e2e/**/*.spec.ts: All Playwright test files must be located under apps/meteor/tests/e2e/ and use the .spec.ts extension (e.g., login.spec.ts)
Use descriptive test names that clearly communicate expected behavior
Use test.beforeAll() and test.afterAll() for setup and teardown
Use test.step() to organize complex test scenarios
Group related tests in the same file
Utilize Playwright fixtures (test, page, expect) consistently
Prefer web-first assertions (e.g., toBeVisible, toHaveText)
Use expect matchers (toEqual, toContain, toBeTruthy, toHaveLength, etc.) instead of assert statements
Maintain test isolation between test cases
Ensure a clean state for each test execution
Ensure tests run reliably in parallel without shared state conflicts

Files:

  • apps/meteor/tests/e2e/omnichannel/omnichannel-agents.spec.ts
apps/meteor/tests/e2e/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

apps/meteor/tests/e2e/**/*.{ts,tsx,js,jsx}: Write concise, technical TypeScript/JavaScript with accurate typing
Follow DRY by extracting reusable logic into helper functions or page objects
Avoid code comments in the implementation

Files:

  • apps/meteor/tests/e2e/omnichannel/omnichannel-agents.spec.ts
apps/meteor/tests/e2e/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

apps/meteor/tests/e2e/**/*.{ts,tsx}: Avoid using page.locator(); prefer semantic locators like page.getByRole, page.getByLabel, page.getByText, and page.getByTitle
Store commonly used locators in variables/constants for reuse
Use page.waitFor() with specific conditions and avoid hardcoded timeouts
Implement proper wait strategies for dynamic content
Follow the Page Object Model pattern consistently

Files:

  • apps/meteor/tests/e2e/omnichannel/omnichannel-agents.spec.ts
🧠 Learnings (7)
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
PR: RocketChat/Rocket.Chat#0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Use descriptive test names that clearly communicate expected behavior

Applied to files:

  • apps/meteor/tests/e2e/omnichannel/omnichannel-agents.spec.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
PR: RocketChat/Rocket.Chat#0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.{ts,tsx} : Implement proper wait strategies for dynamic content

Applied to files:

  • apps/meteor/tests/e2e/omnichannel/omnichannel-agents.spec.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
PR: RocketChat/Rocket.Chat#0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.{ts,tsx} : Use page.waitFor() with specific conditions and avoid hardcoded timeouts

Applied to files:

  • apps/meteor/tests/e2e/omnichannel/omnichannel-agents.spec.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
PR: RocketChat/Rocket.Chat#0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Utilize Playwright fixtures (test, page, expect) consistently

Applied to files:

  • apps/meteor/tests/e2e/omnichannel/omnichannel-agents.spec.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
PR: RocketChat/Rocket.Chat#0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Ensure tests run reliably in parallel without shared state conflicts

Applied to files:

  • apps/meteor/tests/e2e/omnichannel/omnichannel-agents.spec.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
PR: RocketChat/Rocket.Chat#0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Prefer web-first assertions (e.g., toBeVisible, toHaveText)

Applied to files:

  • apps/meteor/tests/e2e/omnichannel/omnichannel-agents.spec.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
PR: RocketChat/Rocket.Chat#0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.{ts,tsx} : Avoid using page.locator(); prefer semantic locators like page.getByRole, page.getByLabel, page.getByText, and page.getByTitle

Applied to files:

  • apps/meteor/tests/e2e/omnichannel/omnichannel-agents.spec.ts
🧬 Code graph analysis (4)
apps/meteor/tests/data/livechat/users.ts (1)
apps/meteor/tests/data/api-data.ts (1)
  • credentials (39-42)
apps/meteor/app/livechat/server/api/v1/agent.ts (5)
packages/rest-typings/src/v1/omnichannel.ts (2)
  • POSTLivechatAgentSaveInfoSuccessResponse (1766-1766)
  • isPOSTLivechatAgentSaveInfoParams (1753-1753)
packages/rest-typings/src/v1/Ajv.ts (3)
  • validateBadRequestErrorResponse (46-46)
  • validateUnauthorizedErrorResponse (69-69)
  • validateForbiddenErrorResponse (92-92)
apps/meteor/app/authorization/server/functions/hasRole.ts (1)
  • hasRoleAsync (23-29)
apps/meteor/app/livechat/server/lib/omni-users.ts (1)
  • saveAgentInfo (84-114)
apps/meteor/app/api/server/ApiClass.ts (1)
  • ExtractRoutesFromAPI (73-77)
apps/meteor/client/views/omnichannel/agents/AgentEdit.tsx (2)
apps/meteor/app/livechat/server/lib/omni-users.ts (1)
  • saveAgentInfo (84-114)
packages/ui-contexts/src/index.ts (1)
  • useEndpoint (32-32)
packages/rest-typings/src/v1/omnichannel.ts (1)
packages/rest-typings/src/v1/Ajv.ts (1)
  • ajv (23-23)
🔇 Additional comments (2)
apps/meteor/app/livechat/server/methods/saveAgentInfo.ts (1)

16-19: Deprecation logger usage looks good

Logs the deprecation with removal target and replacement endpoint right at method entry.

Minor: please verify that check is imported (e.g., import { check } from 'meteor/check') in this file; it’s referenced below.

apps/meteor/app/livechat/server/api/v1/agent.ts (1)

139-163: New REST endpoint is correctly validated and permission-gated

Auth + manage-livechat-agents permission, AJV body/response validators, agent role check, and reuse of saveAgentInfo are all appropriate.

Copy link
Member

@dougfabris dougfabris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On behalf of frontend, LGTM!

@lucas-a-pelegrino lucas-a-pelegrino added stat: ready to merge PR tested and approved waiting for merge stat: QA assured Means it has been tested and approved by a company insider labels Sep 22, 2025
@kodiakhq kodiakhq bot merged commit ba79354 into develop Sep 22, 2025
85 of 88 checks passed
@kodiakhq kodiakhq bot deleted the chore/v7/CTZ-62 branch September 22, 2025 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants