From 5fe3bfda6a7141b68e884df38e3a00235a857816 Mon Sep 17 00:00:00 2001 From: Keshav Bhatt Date: Mon, 11 Nov 2024 16:53:06 +0530 Subject: [PATCH 1/3] feat: [CO-1547] add msg move constrains in move conversation action --- src/constants/index.ts | 3 +-- src/store/actions/conv-action.ts | 6 ++++-- src/types/conversations/index.d.ts | 1 + src/ui-actions/move-conv-msg.tsx | 4 +++- src/views/sidebar/accordion-custom-component.tsx | 5 +++-- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/constants/index.ts b/src/constants/index.ts index 00726838d..2564dd3ca 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -565,7 +565,6 @@ export const MAIL_SENSITIVITY_HEADER = { companyConfidential: 'Company-Confidential' } as const; -export const MAIL_SENSITIVITY_HEADER_VALUES = ['Personal', 'Private', 'Company-Confidential']; - export const SENSITIVITY_VALUES = ['Private', 'Company-Confidential'] as const; export const VALID_MAIL_AUTHENTICATION_HEADERS = ['dkim', 'spf', 'dmarc'] as const; +export const CONV_ACTION_CONSTRAINS = '-stdj'; diff --git a/src/store/actions/conv-action.ts b/src/store/actions/conv-action.ts index 8ebb9fecf..03e67383e 100644 --- a/src/store/actions/conv-action.ts +++ b/src/store/actions/conv-action.ts @@ -6,6 +6,7 @@ import { createAsyncThunk } from '@reduxjs/toolkit'; import { soapFetch } from '@zextras/carbonio-shell-ui'; import { isNil } from 'lodash'; + import { omitBy } from '../../commons/utils'; import type { ConvActionParameters, @@ -16,7 +17,7 @@ import type { export const convAction = createAsyncThunk( 'convAction', - async ({ ids, operation, parent, tagName }) => { + async ({ ids, operation, parent, tagName, constrains }) => { const { action } = (await soapFetch('ConvAction', { _jsns: 'urn:zimbraMail', @@ -25,7 +26,8 @@ export const convAction = createAsyncThunk { diff --git a/src/views/sidebar/accordion-custom-component.tsx b/src/views/sidebar/accordion-custom-component.tsx index 541ba6e19..9946cd6e1 100644 --- a/src/views/sidebar/accordion-custom-component.tsx +++ b/src/views/sidebar/accordion-custom-component.tsx @@ -37,7 +37,7 @@ import { FOLDERS } from '../../carbonio-ui-commons/constants/folders'; import { isSystemFolder } from '../../carbonio-ui-commons/helpers/folders'; import type { Folder } from '../../carbonio-ui-commons/types/folder'; import type { DragEnterAction, OnDropActionProps } from '../../carbonio-ui-commons/types/sidebar'; -import { LIST_LIMIT } from '../../constants'; +import { CONV_ACTION_CONSTRAINS, LIST_LIMIT } from '../../constants'; import { isDraft, isSpam } from '../../helpers/folders'; import { parseMessageSortingOptions } from '../../helpers/sorting'; import { useAppDispatch } from '../../hooks/redux'; @@ -147,7 +147,8 @@ const AccordionCustomComponent: FC<{ item: Folder }> = ({ item }) => { convAction({ operation: `move`, ids: convMsgsIds, - parent: item.id + parent: item.id, + constrains: CONV_ACTION_CONSTRAINS }) ).then((res) => { if (res.type.includes('fulfilled')) { From 7886f0640673165f1896337c46eb11d5f8b3672d Mon Sep 17 00:00:00 2001 From: Keshav Bhatt Date: Mon, 11 Nov 2024 17:02:14 +0530 Subject: [PATCH 2/3] chore: remove redundant casting --- src/store/actions/conv-action.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/store/actions/conv-action.ts b/src/store/actions/conv-action.ts index 03e67383e..54446654a 100644 --- a/src/store/actions/conv-action.ts +++ b/src/store/actions/conv-action.ts @@ -18,7 +18,7 @@ import type { export const convAction = createAsyncThunk( 'convAction', async ({ ids, operation, parent, tagName, constrains }) => { - const { action } = (await soapFetch('ConvAction', { + const { action } = await soapFetch('ConvAction', { _jsns: 'urn:zimbraMail', action: omitBy( @@ -31,7 +31,7 @@ export const convAction = createAsyncThunk Date: Mon, 11 Nov 2024 17:40:26 +0530 Subject: [PATCH 3/3] test: add test to assert presence of default constrains in SOAP API call --- src/types/soap/conv-action.ts | 1 + src/ui-actions/tests/move-conv-msg.test.tsx | 93 ++++++++++++++++++++- 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/src/types/soap/conv-action.ts b/src/types/soap/conv-action.ts index 7d1d2d43e..5ef6e675d 100644 --- a/src/types/soap/conv-action.ts +++ b/src/types/soap/conv-action.ts @@ -25,6 +25,7 @@ export type ConvActionRequest = ZimbraRequest & { op?: ConvActionOperation; tn?: string; l?: string; + tcon?: string; }; }; diff --git a/src/ui-actions/tests/move-conv-msg.test.tsx b/src/ui-actions/tests/move-conv-msg.test.tsx index 023fdc8d9..a68ba56ce 100644 --- a/src/ui-actions/tests/move-conv-msg.test.tsx +++ b/src/ui-actions/tests/move-conv-msg.test.tsx @@ -14,10 +14,17 @@ import { getFolder } from '../../carbonio-ui-commons/store/zustand/folder'; import { createSoapAPIInterceptor } from '../../carbonio-ui-commons/test/mocks/network/msw/create-api-interceptor'; import { populateFoldersStore } from '../../carbonio-ui-commons/test/mocks/store/folders'; import { makeListItemsVisible, setupTest } from '../../carbonio-ui-commons/test/test-setup'; -import { API_REQUEST_STATUS } from '../../constants'; +import { API_REQUEST_STATUS, CONV_ACTION_CONSTRAINS } from '../../constants'; +import { generateConversation } from '../../tests/generators/generateConversation'; import { generateMessage } from '../../tests/generators/generateMessage'; import { generateStore } from '../../tests/generators/store'; -import { MailMessage, MsgActionRequest, MsgActionResponse } from '../../types'; +import { + ConvActionRequest, + ConvActionResponse, + MailMessage, + MsgActionRequest, + MsgActionResponse +} from '../../types'; import MoveConvMessage from '../move-conv-msg'; describe('MoveConvMsg', () => { @@ -224,5 +231,87 @@ describe('MoveConvMsg', () => { expect(requestParameter.action.f).toBeUndefined(); expect(requestParameter.action.tn).toBeUndefined(); }); + + it('should call conv action api with default constrains when user clicks confirm', async () => { + populateFoldersStore({ view: FOLDER_VIEW.conversation }); + + const { children: inboxChildren } = getFolder(FOLDERS.INBOX) ?? {}; + const sourceFolderId = inboxChildren?.[0].id ?? ''; + const destinationFolder = FOLDERS.SENT; + + const conversation = generateConversation({ + folderId: sourceFolderId, + isSingleMessageConversation: false + }); + const msgIdsInConversation = conversation.messages.map((msg) => msg.id); + + const store = generateStore({ + conversations: { + currentFolder: sourceFolderId, + expandedStatus: { + [conversation.id]: API_REQUEST_STATUS.fulfilled + }, + searchedInFolder: {}, + conversations: { + [conversation.id]: conversation + }, + searchRequestStatus: API_REQUEST_STATUS.fulfilled + } + }); + + const interceptor = createSoapAPIInterceptor( + 'ConvAction', + { + action: { + id: conversation.id, + op: 'move' + } + } + ); + + const component = ( + + ); + + const { user } = setupTest(component, { store }); + makeListItemsVisible(); + + const inboxFolderListItem = await screen.findByTestId( + `folder-accordion-item-${destinationFolder}`, + {}, + { timeout: 10000 } + ); + + act(() => { + jest.advanceTimersByTime(1000); + }); + + await act(async () => { + await user.click(inboxFolderListItem); + }); + + const button = screen.getByRole('button', { + name: /Move/ + }); + + await act(async () => { + await user.click(button); + }); + + const requestParameter = await interceptor; + expect(requestParameter.action.id).toBe(msgIdsInConversation.join(',')); + expect(requestParameter.action.op).toBe('move'); + expect(requestParameter.action.l).toBe(destinationFolder); + expect(requestParameter.action.tcon).toBe(CONV_ACTION_CONSTRAINS); + expect(requestParameter.action.tn).toBeUndefined(); + }); }); });