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:returnAsInquiry meteor method, as well as it adds an endpoint (livechat/inquiries.returnAsInquiry) to replace it.

Issue(s)

CTZ-61

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • New Features

    • Added a REST endpoint to return livechat chats to inquiry (POST, payload: roomId, optional departmentId) with request/response validation and public typings.
  • Deprecations

    • RPC method marked deprecated and now logs a deprecation warning; prefer the new REST endpoint.
  • Refactor

    • Client quick actions switched to call the new REST endpoint; no UI changes.
  • Tests

    • E2E tests updated to use the REST route and JSON payloads.
  • Bug Fixes

    • Enforced MAC limits when returning chats and clarified the "Room closed" error message.
  • Chores

    • Dependency version bumps.

@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: 1037b2b

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

This PR includes changesets to release 42 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/federation-matrix Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/federation-service 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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 17, 2025

Walkthrough

Adds a POST REST endpoint livechat/inquiries.returnAsInquiry with validators and typings; switches client hooks and E2E tests from the Meteor method to the REST endpoint; logs deprecation for livechat:returnAsInquiry; moves MAC-limit and closed-room checks into returnRoomAsInquiry; bump notes in changeset.

Changes

Cohort / File(s) Summary
REST endpoint & server handler
apps/meteor/app/livechat/imports/server/rest/inquiries.ts
Add POST livechat/inquiries.returnAsInquiry (auth + view-l-room) validated by isPOSTLivechatInquiriesReturnAsInquiry; find room, map errors (error-room-not-found, Meteor.Error reasons), delegate to returnRoomAsInquiry, respond { result }.
REST typings & validators
packages/rest-typings/src/v1/omnichannel.ts
Add request schema/validator isPOSTLivechatInquiriesReturnAsInquiry and success-response validator POSTLivechatInquiriesReturnAsInquirySuccessResponse; export types to REST surface.
Server room logic
apps/meteor/app/livechat/server/lib/rooms.ts
Import Omnichannel; standardize closed-room message to 'Room closed'; add Omnichannel.isWithinMACLimit(room) check that throws error-mac-limit-reached before proceeding.
Deprecated server method
apps/meteor/app/livechat/server/methods/returnAsInquiry.ts
Add methodDeprecationLogger call for livechat:returnAsInquiry; update method signature types; remove local MAC-limit/room-open gating and delegate to returnRoomAsInquiry, returning its boolean result.
Client hooks: switch to REST
apps/meteor/client/views/room/Header/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts, apps/meteor/client/views/room/HeaderV2/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts
Replace useMethod('livechat:returnAsInquiry') with useEndpoint('POST','/v1/livechat/inquiries.returnAsInquiry'); call payload { roomId, departmentId? }; onSuccess cache invalidation/removals unchanged.
E2E tests: migrate to REST
apps/meteor/tests/end-to-end/api/livechat/05-inquiries.ts
Replace RPC/methodCall tests with REST calls to livechat/inquiries.returnAsInquiry, send { roomId } payloads, adjust assertions to REST success/error structure, remove RPC helpers.
Changeset
.changeset/calm-hounds-look.md
Patch dependency bumps for @rocket.chat/meteor and @rocket.chat/rest-typings; deprecation note for livechat:returnAsInquiry and reference to new REST endpoint.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant UI as Client UI
  participant Hook as useReturnChatToQueueMutation
  participant API as POST /v1/livechat/inquiries.returnAsInquiry
  participant Handler as Server handler
  participant Rooms as LivechatRooms
  participant OC as Omnichannel
  participant Logic as returnRoomAsInquiry

  UI->>Hook: trigger(rid)
  Hook->>API: POST { roomId, departmentId? }
  API->>Handler: auth + permission (view-l-room)
  Handler->>Rooms: findOneById(roomId)
  Rooms-->>Handler: room or null
  alt room found
    Handler->>OC: isWithinMACLimit(room)
    OC-->>Handler: allowed / denied
    alt allowed
      Handler->>Logic: returnRoomAsInquiry(room, departmentId?)
      Logic-->>Handler: result (boolean)
      Handler-->>API: 200 { success:true, result }
      API-->>Hook: success
      Hook-->>UI: invalidate caches / update UI
    else MAC limit exceeded
      Handler-->>API: 400 { success:false, error:"error-mac-limit-reached" }
      API-->>Hook: error
    end
  else room not found
    Handler-->>API: 400 { success:false, error:"error-room-not-found" }
    API-->>Hook: error
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

stat: ready to merge, stat: QA assured

Suggested reviewers

  • sampaiodiego
  • KevLehman
  • MartinSchoeler

Poem

I hop from RPC to POST with cheer,
I check each room, the limits clear,
Hooks and tests now speak in REST,
A deprecation logged, old calls rest. 🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The pull request includes changes to returnRoomAsInquiry business logic by adding MAC limit validation and expanding error messages, which falls outside the stated objectives of deprecating the method and adding the new endpoint. Please isolate the business logic updates such as MAC limit validation and enhanced error messaging into a separate pull request so that this change remains focused on deprecation and endpoint introduction.
✅ 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 describes the deprecation of the existing method and the introduction of its replacement endpoint, clearly reflecting the most important changes in this pull request and avoiding unnecessary detail or noise.
Linked Issues Check ✅ Passed The changes implement the deprecation logger on the Meteor method and introduce the new HTTP endpoint along with corresponding UI and test updates, fully satisfying the coding objectives outlined in issue CTZ-61.
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-61

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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.36%. Comparing base (dca0b3a) to head (1037b2b).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #36973      +/-   ##
===========================================
- Coverage    67.38%   66.36%   -1.03%     
===========================================
  Files         3328     3382      +54     
  Lines       113342   115594    +2252     
  Branches     20562    21203     +641     
===========================================
+ Hits         76375    76713     +338     
- Misses       34363    36274    +1911     
- Partials      2604     2607       +3     
Flag Coverage Δ
e2e 57.36% <100.00%> (+0.07%) ⬆️
unit 71.16% <ø> (+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 17, 2025 21:33
@lucas-a-pelegrino lucas-a-pelegrino requested review from a team as code owners September 17, 2025 21:33
@lucas-a-pelegrino lucas-a-pelegrino added this to the 7.11.0 milestone Sep 17, 2025
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: 1

🧹 Nitpick comments (5)
packages/rest-typings/src/v1/omnichannel.ts (1)

3392-3433: Schema/validators added—align naming and TS type with existing conventions.

  • Naming: most validators use the is* prefix (e.g., isPOSTLivechatRoomsCloseAllSuccessResponse). Consider renaming the success validator for consistency.
  • Typing: include success: true in the compile generic for better TS accuracy.

Proposed tweak:

- export const POSTLivechatInquiriesReturnAsInquirySuccessResponse = ajv.compile<{ result: boolean }>(
+ export const isPOSTLivechatInquiriesReturnAsInquirySuccessResponse = ajv.compile<{ result: boolean; success: true }>(
   POSTLivechatInquiriesReturnAsInquirySuccessResponseSchema,
 );
apps/meteor/client/views/room/HeaderV2/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts (1)

11-18: Return the boolean result so UIs can react (optional).

Endpoint returns { result: boolean }. Exposing it lets consumers notify when nothing was returned to queue (result=false).

-export const useReturnChatToQueueMutation = (
-  options?: Omit<UseMutationOptions<void, Error, IRoom['_id']>, 'mutationFn'>,
-): UseMutationResult<void, Error, IRoom['_id']> => {
+export const useReturnChatToQueueMutation = (
+  options?: Omit<UseMutationOptions<boolean, Error, IRoom['_id']>, 'mutationFn'>,
+): UseMutationResult<boolean, Error, IRoom['_id']> => {
   const returnChatToQueue = useEndpoint('POST', '/v1/livechat/inquiries.returnAsInquiry');
   …
   return useMutation({
     mutationFn: async (rid) => {
-      await returnChatToQueue({ roomId: rid });
+      const { result } = await returnChatToQueue({ roomId: rid });
+      return result;
     },
apps/meteor/client/views/room/Header/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts (1)

11-18: Mirror V2: surface the boolean result (optional).

Same rationale as V2 hook—bubble up the outcome for UX feedback.

- options?: Omit<UseMutationOptions<void, Error, IRoom['_id']>, 'mutationFn'>,
-): UseMutationResult<void, Error, IRoom['_id']> => {
+ options?: Omit<UseMutationOptions<boolean, Error, IRoom['_id']>, 'mutationFn'>,
+): UseMutationResult<boolean, Error, IRoom['_id']> => {-  await returnChatToQueue({ roomId: rid });
+  const { result } = await returnChatToQueue({ roomId: rid });
+  return result;
apps/meteor/tests/end-to-end/api/livechat/05-inquiries.ts (1)

327-437: Good migration to REST; consider adding a couple of edge-case assertions.

  • Add tests for MAC limit and on-hold rooms to cover the explicit failure branches (mac-limit-reached, error-room-onHold via service).
  • Optional: also assert that the endpoint preserves HTTP 400 with those error keys.

I can draft these tests if helpful.

apps/meteor/app/livechat/imports/server/rest/inquiries.ts (1)

13-14: Validator import name consistency (if you adopt the rename).

Update the imported success validator to isPOSTLivechatInquiriesReturnAsInquirySuccessResponse for consistency with other routes.

📜 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 27cc5b7 and e137035.

📒 Files selected for processing (6)
  • apps/meteor/app/livechat/imports/server/rest/inquiries.ts (2 hunks)
  • apps/meteor/app/livechat/server/methods/returnAsInquiry.ts (2 hunks)
  • apps/meteor/client/views/room/Header/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts (2 hunks)
  • apps/meteor/client/views/room/HeaderV2/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts (2 hunks)
  • apps/meteor/tests/end-to-end/api/livechat/05-inquiries.ts (7 hunks)
  • packages/rest-typings/src/v1/omnichannel.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (5)
apps/meteor/tests/end-to-end/api/livechat/05-inquiries.ts (1)
apps/meteor/tests/data/api-data.ts (1)
  • credentials (39-42)
apps/meteor/client/views/room/HeaderV2/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts (1)
packages/ui-contexts/src/index.ts (1)
  • useEndpoint (32-32)
apps/meteor/app/livechat/imports/server/rest/inquiries.ts (7)
packages/rest-typings/src/v1/omnichannel.ts (2)
  • POSTLivechatInquiriesReturnAsInquirySuccessResponse (3430-3432)
  • isPOSTLivechatInquiriesReturnAsInquiry (3412-3414)
packages/rest-typings/src/v1/Ajv.ts (3)
  • validateBadRequestErrorResponse (46-46)
  • validateUnauthorizedErrorResponse (69-69)
  • validateForbiddenErrorResponse (92-92)
packages/models/src/index.ts (1)
  • LivechatRooms (175-175)
packages/core-services/src/index.ts (1)
  • Omnichannel (181-181)
apps/meteor/app/livechat/server/lib/rooms.ts (1)
  • returnRoomAsInquiry (211-255)
apps/meteor/app/api/server/ApiClass.ts (1)
  • ExtractRoutesFromAPI (73-77)
packages/rest-typings/src/index.ts (1)
  • Endpoints (52-100)
apps/meteor/client/views/room/Header/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts (1)
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/returnAsInquiry.ts (1)

8-8: Deprecation notice looks good—please confirm version and path.

The logger call correctly points callers to the new REST endpoint. Double‑check that the deprecation version '8.0.0' aligns with your public deprecation policy and that the endpoint path is final.

Also applies to: 20-21

apps/meteor/tests/end-to-end/api/livechat/05-inquiries.ts (1)

515-519: Nice check on inquiry lastMessage after return.

This verifies the queue UI stays accurate post-return. LGTM.

@lucas-a-pelegrino lucas-a-pelegrino marked this pull request as draft September 17, 2025 21:45
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: 2

🧹 Nitpick comments (12)
.changeset/calm-hounds-look.md (1)

6-6: Clarify replacement path and add removal timeline.

Recommend referencing the full REST path with version prefix and stating the deprecation/removal plan to guide integrators.

Proposed wording tweak:

  • “Adds deprecation warning for Meteor method livechat:returnAsInquiry. Use REST endpoint /v1/livechat/inquiries.returnAsInquiry instead. Deprecated in 8.0.0; planned removal in next major.”
apps/meteor/client/views/room/HeaderV2/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts (1)

11-18: Switch to REST endpoint looks good; consider surfacing the boolean result.

Calling POST /v1/livechat/inquiries.returnAsInquiry with { roomId } is correct. Today the hook discards the endpoint’s { result: boolean }; if useful for UX (e.g., “no one serving” returns false), consider returning/forwarding it without changing the external signature (e.g., keep void but optionally let callers pass an onSuccess that inspects the response).

Also ensure the REST typings map includes this path (see comment on packages/rest-typings: add '/v1/livechat/inquiries.returnAsInquiry' to OmnichannelEndpoints).

apps/meteor/app/livechat/server/methods/returnAsInquiry.ts (1)

20-20: Deprecation logger placement is correct; align parameter naming for consistency.

Positional args work, but the declared method type uses departmentID while the impl uses departmentId. Consider aligning to departmentId across types for consistency with REST.

Suggested type tweak (outside this hunk):

interface ServerMethods {
  'livechat:returnAsInquiry'(rid: IRoom['_id'], departmentId?: ILivechatDepartment['_id']): boolean;
}
apps/meteor/client/views/room/Header/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts (1)

11-18: LGTM; keep both hook variants consistent and consider a shared constant for the path.

Both Header and HeaderV2 now hit the same endpoint with the same payload—great. To avoid drift, consider a small constants module for '/v1/livechat/inquiries.returnAsInquiry'.

As above, verify the REST typings expose this path to preserve type safety.

packages/rest-typings/src/v1/omnichannel.ts (1)

3430-3432: Nit: align validator export naming with existing “is…” convention.

Many validators use the is* prefix (e.g., isPOSTLivechatRoomsCloseAllSuccessResponse). Consider renaming to isPOSTLivechatInquiriesReturnAsInquirySuccessResponse for consistency. Non‑blocking.

-export const POSTLivechatInquiriesReturnAsInquirySuccessResponse = ajv.compile<{ result: boolean }>(
+export const isPOSTLivechatInquiriesReturnAsInquirySuccessResponse = ajv.compile<{ result: boolean }>(
   POSTLivechatInquiriesReturnAsInquirySuccessResponseSchema,
 );
apps/meteor/tests/end-to-end/api/livechat/05-inquiries.ts (2)

347-355: Avoid brittle assertion on full error message string.

Asserting the exact i18n’d message can be flaky. Prefer checking status (403), success === false, and that error contains 'error-unauthorized'.

- expect(body.error).to.have.equal('User does not have the permissions required for this action [error-unauthorized]');
+ expect(body).to.have.property('success', false);
+ expect(String(body.error)).to.include('error-unauthorized');

372-380: Minor: avoid relying on 'GENERAL' channel existence.

In some environments 'GENERAL' may be renamed/absent. Consider creating a temp non‑livechat room for this check.

apps/meteor/app/livechat/imports/server/rest/inquiries.ts (5)

145-147: Use 403 for MAC/plan policy denial.

Returning 400 for MAC limit muddies semantics. Prefer Forbidden (policy) to distinguish from client input errors.

-    if (!(await Omnichannel.isWithinMACLimit(room))) {
-      return API.v1.failure('mac-limit-reached');
-    }
+    if (!(await Omnichannel.isWithinMACLimit(room))) {
+      return API.v1.forbidden();
+    }

134-135: Validate departmentId if provided.

If departmentId is present, ensure it exists; otherwise callers get a “successful” 200 with later failures/side-effects.

   const { roomId, departmentId } = this.bodyParams;
 
+  if (departmentId) {
+    const dep = await LivechatDepartment.findOneById(departmentId, { projection: { _id: 1 } });
+    if (!dep) {
+      return API.v1.failure('invalid-department');
+    }
+  }

149-152: Return deterministic errors instead of { result: false }.

False conflates “no inquiry”, “already unassigned”, etc. Prefer explicit error for client handling.

-    const result = await returnRoomAsInquiry(room, departmentId);
-
-    return API.v1.success({ result });
+    const result = await returnRoomAsInquiry(room, departmentId);
+    if (!result) {
+      return API.v1.failure('inquiry-not-found-or-already-unassigned');
+    }
+    return API.v1.success({ result: true });

120-132: Align declared response schemas with actual error paths.

returnRoomAsInquiry can throw (e.g., error-room-onHold, error-returning-inquiry). Ensure these map to 400/403/401 or declare 5xx in response, or catch and translate.

Would you like a patch that wraps returnRoomAsInquiry with try/catch and maps known Meteor.Error codes to the declared responses?

Also applies to: 149-152


155-160: Type augmentation placement: avoid duplicate interface merging.

Placing the Endpoints augmentation here risks multiple merges if this file is imported in different server bundles. Consider centralizing augmentations (e.g., a single rest-typings augmentation module).

📜 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 27cc5b7 and 46fe174.

📒 Files selected for processing (7)
  • .changeset/calm-hounds-look.md (1 hunks)
  • apps/meteor/app/livechat/imports/server/rest/inquiries.ts (2 hunks)
  • apps/meteor/app/livechat/server/methods/returnAsInquiry.ts (2 hunks)
  • apps/meteor/client/views/room/Header/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts (2 hunks)
  • apps/meteor/client/views/room/HeaderV2/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts (2 hunks)
  • apps/meteor/tests/end-to-end/api/livechat/05-inquiries.ts (7 hunks)
  • packages/rest-typings/src/v1/omnichannel.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (5)
apps/meteor/client/views/room/Header/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts (1)
packages/ui-contexts/src/index.ts (1)
  • useEndpoint (32-32)
apps/meteor/client/views/room/HeaderV2/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts (1)
packages/ui-contexts/src/index.ts (1)
  • useEndpoint (32-32)
apps/meteor/app/livechat/imports/server/rest/inquiries.ts (7)
packages/rest-typings/src/v1/omnichannel.ts (2)
  • POSTLivechatInquiriesReturnAsInquirySuccessResponse (3430-3432)
  • isPOSTLivechatInquiriesReturnAsInquiry (3412-3414)
packages/rest-typings/src/v1/Ajv.ts (3)
  • validateBadRequestErrorResponse (46-46)
  • validateUnauthorizedErrorResponse (69-69)
  • validateForbiddenErrorResponse (92-92)
packages/models/src/index.ts (1)
  • LivechatRooms (175-175)
packages/core-services/src/index.ts (1)
  • Omnichannel (181-181)
apps/meteor/app/livechat/server/lib/rooms.ts (1)
  • returnRoomAsInquiry (211-255)
apps/meteor/app/api/server/ApiClass.ts (1)
  • ExtractRoutesFromAPI (73-77)
packages/rest-typings/src/index.ts (1)
  • Endpoints (52-100)
packages/rest-typings/src/v1/omnichannel.ts (1)
packages/rest-typings/src/v1/Ajv.ts (1)
  • ajv (23-23)
apps/meteor/tests/end-to-end/api/livechat/05-inquiries.ts (1)
apps/meteor/tests/data/api-data.ts (1)
  • credentials (39-42)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: 📦 Meteor Build - coverage
  • GitHub Check: CodeQL-Build
🔇 Additional comments (8)
apps/meteor/app/livechat/server/methods/returnAsInquiry.ts (1)

8-8: Import LGTM.

Deprecation logger import path and usage match existing patterns.

apps/meteor/tests/end-to-end/api/livechat/05-inquiries.ts (6)

7-7: Import update LGTM.

Using shared credentials import is consistent with other suites.


22-22: Sleep utility import LGTM.


359-369: Invalid room case assertions LGTM.

Status 400 with error 'invalid-room' matches the new endpoint contract.


406-415: “No one serving” path LGTM.

Asserting 200 with { success: true, result: false } matches the intended semantics.


429-437: Happy path LGTM.

Checks for { success: true, result: true } after returning to queue are appropriate.


516-519: Message-updated flow LGTM.

Endpoint call integrated into the existing “keep inquiry last message updated” test without changing semantics.

apps/meteor/app/livechat/imports/server/rest/inquiries.ts (1)

1-14: Imports/typings look consistent.

New imports (LivechatRooms, Omnichannel, validators, ExtractRoutesFromAPI) align with usage.

@lucas-a-pelegrino lucas-a-pelegrino marked this pull request as ready for review September 17, 2025 22:57
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

♻️ Duplicate comments (3)
apps/meteor/app/livechat/imports/server/rest/inquiries.ts (3)

152-159: Harden Meteor error mapping.

Use error.error || error.reason || error.message to avoid empty messages when reason isn’t set.

-    } catch (error) {
-      if (error instanceof Meteor.Error) {
-        return API.v1.failure(error.reason);
-      }
-
-      return API.v1.failure('error-returning-inquiry');
-    }
+    } catch (error) {
+      if (error instanceof Meteor.Error) {
+        const reason = (error as any).error || (error as any).reason || (error as any).message;
+        return API.v1.failure(reason);
+      }
+      return API.v1.failure('error-returning-inquiry');
+    }

153-159: Fix: Missing Meteor import (breaks error handling).

Meteor.Error is referenced but Meteor isn’t imported; this will crash the endpoint on error paths.

+import { Meteor } from 'meteor/meteor';

Also applies to: 1-4


141-147: Authorize who can return a room to the queue (assignee or manager only).

Any agent with view-l-room can return another agent’s chat; restrict to current assignee or privileged users.

+import { hasPermissionAsync } from '../../../../authorization/server/functions/hasPermission';
@@
   if (!room.open) {
     return API.v1.failure('room-closed');
   }
 
+  const isAssignee = room.servedBy?._id === this.userId;
+  const canManageQueue = await hasPermissionAsync(this.userId, 'view-livechat-manager');
+  if (!isAssignee && !canManageQueue) {
+    return API.v1.forbidden();
+  }
+
   if (!(await Omnichannel.isWithinMACLimit(room))) {
     return API.v1.failure('mac-limit-reached');
   }
🧹 Nitpick comments (1)
apps/meteor/app/livechat/imports/server/rest/inquiries.ts (1)

134-139: Validate departmentId when provided.

Early-check the department to fail fast with a clear 400, avoiding generic backend errors.

   const { roomId, departmentId } = this.bodyParams;
 
+  if (departmentId) {
+    const dep = await LivechatDepartment.findOneById(departmentId, { projection: { _id: 1 } });
+    if (!dep) {
+      return API.v1.failure('invalid-department');
+    }
+  }
+
   const room = await LivechatRooms.findOneById(roomId);
   if (!room || room.t !== 'l') {
     return API.v1.failure('invalid-room');
   }
📜 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 46fe174 and 19ac582.

📒 Files selected for processing (1)
  • apps/meteor/app/livechat/imports/server/rest/inquiries.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/meteor/app/livechat/imports/server/rest/inquiries.ts (6)
packages/rest-typings/src/v1/omnichannel.ts (2)
  • POSTLivechatInquiriesReturnAsInquirySuccessResponse (3430-3432)
  • isPOSTLivechatInquiriesReturnAsInquiry (3412-3414)
packages/rest-typings/src/v1/Ajv.ts (3)
  • validateBadRequestErrorResponse (46-46)
  • validateUnauthorizedErrorResponse (69-69)
  • validateForbiddenErrorResponse (92-92)
packages/models/src/index.ts (1)
  • LivechatRooms (175-175)
packages/core-services/src/index.ts (1)
  • Omnichannel (181-181)
apps/meteor/app/livechat/server/lib/rooms.ts (1)
  • returnRoomAsInquiry (211-255)
apps/meteor/app/api/server/ApiClass.ts (1)
  • ExtractRoutesFromAPI (73-77)

dougfabris
dougfabris previously approved these changes Sep 18, 2025
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!

MartinSchoeler
MartinSchoeler previously approved these changes Sep 19, 2025
@dougfabris dougfabris added the stat: QA assured Means it has been tested and approved by a company insider label Sep 26, 2025
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Sep 26, 2025
@dougfabris dougfabris modified the milestones: 7.12.0, 7.11.0 Sep 26, 2025
@kodiakhq kodiakhq bot merged commit 48d1442 into develop Sep 29, 2025
48 of 49 checks passed
@kodiakhq kodiakhq bot deleted the chore/v7/CTZ-61 branch September 29, 2025 14:19
@dougfabris dougfabris modified the milestones: 7.11.0, 7.12.0 Sep 29, 2025
debdutdeb pushed a commit that referenced this pull request Sep 29, 2025
ricardogarim pushed a commit that referenced this pull request Oct 6, 2025
ricardogarim pushed a commit that referenced this pull request Oct 6, 2025
debdutdeb pushed a commit that referenced this pull request Oct 7, 2025
sampaiodiego pushed a commit that referenced this pull request Oct 7, 2025
juliajforesti pushed a commit that referenced this pull request Oct 8, 2025
juliajforesti pushed a commit that referenced this pull request Oct 8, 2025
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.

6 participants