From e34a0d6e93d6be1864103c82072d8e56f2c779fe Mon Sep 17 00:00:00 2001 From: Ilya Bondar Date: Mon, 26 Aug 2024 16:56:30 +0200 Subject: [PATCH 1/2] feat(chat): add opportunity to configure the role field name (Issue #1971) (#1972) --- apps/chat/.env.development | 1 + apps/chat/README.md | 1 + apps/chat/environment.d.ts | 1 + apps/chat/index.d.ts | 2 +- apps/chat/src/utils/auth/auth-callbacks.ts | 11 ++++++----- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/chat/.env.development b/apps/chat/.env.development index 049ed953af..83c5086134 100644 --- a/apps/chat/.env.development +++ b/apps/chat/.env.development @@ -84,6 +84,7 @@ PUBLICATION_FILTERS="title,job title,role,dial_roles" # DIAL roles settings ADMIN_ROLE_NAMES="admin" +DIAL_ROLES_FIELD="dial_roles" # Themes # THEMES_CONFIG_HOST="" diff --git a/apps/chat/README.md b/apps/chat/README.md index 59fe752172..b31da1635a 100644 --- a/apps/chat/README.md +++ b/apps/chat/README.md @@ -113,6 +113,7 @@ AI DIAL Chat uses environment variables for configuration. All environment varia | `ENABLED_FEATURES` | No | Features enabled in the AI DIAL Chat application | Refer to [Features](../../libs/shared/src/types/features.ts) to view all the available features. | | | `PUBLICATION_FILTERS` | No | Defines types of publications that can be retrieved from the database | Any string. Values must be separated by a comma. | `title,role` | | `ADMIN_ROLE_NAMES` | No | Defines the name of the administrator role | Any string. Values must be separated by a comma. | `admin` | +| `DIAL_ROLES_FIELD` | No | Defines the name of the roles field in JWT token | Any string | `dial_roles` | | `NEXT_PUBLIC_APP_NAME` | No | Application name | Any string | `AI Dial` | | `NEXT_PUBLIC_DEFAULT_SYSTEM_PROMPT` | No | Default system prompt | Any string | | | `NEXT_PUBLIC_DEFAULT_TEMPERATURE` | No | Default temperature | 0 to 1 | | diff --git a/apps/chat/environment.d.ts b/apps/chat/environment.d.ts index 28b7134778..82ba6abf1e 100644 --- a/apps/chat/environment.d.ts +++ b/apps/chat/environment.d.ts @@ -17,6 +17,7 @@ declare global { ENABLED_FEATURES?: string; PUBLICATION_FILTERS?: string; ADMIN_ROLE_NAMES?: string; + DIAL_ROLES_FIELD?: string; NEXT_PUBLIC_APP_NAME?: string; NEXT_PUBLIC_DEFAULT_SYSTEM_PROMPT?: string; NEXT_PUBLIC_DEFAULT_TEMPERATURE?: string; diff --git a/apps/chat/index.d.ts b/apps/chat/index.d.ts index 0e25de91b1..275bcb111d 100644 --- a/apps/chat/index.d.ts +++ b/apps/chat/index.d.ts @@ -18,6 +18,6 @@ declare module 'next-auth' { declare module 'next-auth/jwt' { interface JWT extends DefaultJWT { - user: { dial_roles?: string[] }; + user: Record; } } diff --git a/apps/chat/src/utils/auth/auth-callbacks.ts b/apps/chat/src/utils/auth/auth-callbacks.ts index 3747e88313..1c61f3cd22 100644 --- a/apps/chat/src/utils/auth/auth-callbacks.ts +++ b/apps/chat/src/utils/auth/auth-callbacks.ts @@ -182,15 +182,16 @@ export const callbacks: Partial< (options.session as Session & { error?: unknown }).error = options.token.error; } - - if (options.session.user && options.token.user.dial_roles) { + const roleFieldName = process.env.DIAL_ROLES_FIELD ?? 'dial_roles'; + const dialRoles = options?.token?.user?.[roleFieldName]; + if (options.session.user && dialRoles) { + const roles = Array.isArray(dialRoles) ? dialRoles : [dialRoles]; const adminRoleNames = (process.env.ADMIN_ROLE_NAMES || 'admin').split( ',', ); - options.session.user.isAdmin = adminRoleNames.some((role) => - options.token.user.dial_roles?.includes(role), - ); + options.session.user.isAdmin = + roles.length > 0 && adminRoleNames.some((role) => roles.includes(role)); } return options.session; From 61015aecfb0696b7e32baf4698db967cf5659f02 Mon Sep 17 00:00:00 2001 From: Denys_Kolomiitsev <143205282+denys-kolomiitsev@users.noreply.github.com> Date: Tue, 27 Aug 2024 10:18:00 +0200 Subject: [PATCH 2/2] feat(chat): allow modal windows to be closed only on 'x' or cancel (Issue #1918) (#1961) --- apps/chat-e2e/src/tests/prompts.test.ts | 5 ++--- apps/chat/src/components/Chat/AddonsDialog.tsx | 1 + apps/chat/src/components/Chat/ModelsDialog.tsx | 1 + apps/chat/src/components/Chat/ShareModal.tsx | 1 + apps/chat/src/components/Chatbar/ExportModal.tsx | 1 + apps/chat/src/components/Common/ConfirmDialog.tsx | 2 +- apps/chat/src/components/Common/Modal.tsx | 2 +- .../chat/src/components/Common/SelectFolder/SelectFolder.tsx | 2 +- apps/chat/src/components/Files/AttachLinkDialog.tsx | 1 + apps/chat/src/components/Files/FileManagerModal.tsx | 2 +- apps/chat/src/components/Files/PreUploadModal.tsx | 2 +- apps/chat/src/components/Settings/SettingDialog.tsx | 2 +- 12 files changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/chat-e2e/src/tests/prompts.test.ts b/apps/chat-e2e/src/tests/prompts.test.ts index 95d9a125b3..7400bb9ab5 100644 --- a/apps/chat-e2e/src/tests/prompts.test.ts +++ b/apps/chat-e2e/src/tests/prompts.test.ts @@ -325,7 +325,6 @@ dialTest( dataInjector, promptDropdownMenu, promptModalDialog, - promptBar, setTestIds, }) => { setTestIds('EPMRTC-953'); @@ -337,8 +336,8 @@ dialTest( await prompts.openEntityDropdownMenu(prompt.name); await promptDropdownMenu.selectMenuOption(MenuOptions.edit); await promptModalDialog.fillPromptDetails(newName, newDescr, newValue); - // eslint-disable-next-line playwright/no-force-option - await promptBar.click({ force: true }); + + await promptModalDialog.closeButton.click(); await expect .soft( diff --git a/apps/chat/src/components/Chat/AddonsDialog.tsx b/apps/chat/src/components/Chat/AddonsDialog.tsx index 6796eddc2c..7dd07a10bc 100644 --- a/apps/chat/src/components/Chat/AddonsDialog.tsx +++ b/apps/chat/src/components/Chat/AddonsDialog.tsx @@ -180,6 +180,7 @@ export const AddonsDialog: FC = ({ state={isOpen ? ModalState.OPENED : ModalState.CLOSED} hideClose containerClassName="flex h-fit max-h-full h-[700px] w-full grow justify-between flex-col gap-4 divide-tertiary py-4 md:grow-0 xl:max-w-[720px] 2xl:max-w-[780px]" + dismissProps={{ outsidePress: true }} >
{t('Addons (max 10)')} diff --git a/apps/chat/src/components/Chat/ModelsDialog.tsx b/apps/chat/src/components/Chat/ModelsDialog.tsx index c8fe13f5d7..0df30ba114 100644 --- a/apps/chat/src/components/Chat/ModelsDialog.tsx +++ b/apps/chat/src/components/Chat/ModelsDialog.tsx @@ -153,6 +153,7 @@ export const ModelsDialog: FC = ({ state={isOpen ? ModalState.OPENED : ModalState.CLOSED} hideClose containerClassName="m-auto flex size-full grow flex-col gap-4 divide-tertiary overflow-y-auto py-4 md:grow-0 xl:max-w-[720px] 2xl:max-w-[780px]" + dismissProps={{ outsidePress: true }} >
{t('Talk to')} diff --git a/apps/chat/src/components/Chat/ShareModal.tsx b/apps/chat/src/components/Chat/ShareModal.tsx index 670170c9a2..d9568a4837 100644 --- a/apps/chat/src/components/Chat/ShareModal.tsx +++ b/apps/chat/src/components/Chat/ShareModal.tsx @@ -84,6 +84,7 @@ export default function ShareModal() { state={modalState} onClose={handleClose} heading={`${t('Share')}: ${shareResourceName?.trim()}`} + dismissProps={{ outsidePress: true }} >

diff --git a/apps/chat/src/components/Chatbar/ExportModal.tsx b/apps/chat/src/components/Chatbar/ExportModal.tsx index 138763b330..fa6ca6e521 100644 --- a/apps/chat/src/components/Chatbar/ExportModal.tsx +++ b/apps/chat/src/components/Chatbar/ExportModal.tsx @@ -19,6 +19,7 @@ export const ExportModal = ({ onExport, onClose, isOpen }: Props) => { state={isOpen ? ModalState.OPENED : ModalState.CLOSED} portalId="theme-main" containerClassName="inline-block max-w-[350px] w-full px-3 py-4 rounded" + dismissProps={{ outsidePress: true }} >

{t('Export')}

diff --git a/apps/chat/src/components/Common/ConfirmDialog.tsx b/apps/chat/src/components/Common/ConfirmDialog.tsx index 9bb2fdddd5..503ed36ebf 100644 --- a/apps/chat/src/components/Common/ConfirmDialog.tsx +++ b/apps/chat/src/components/Common/ConfirmDialog.tsx @@ -34,7 +34,7 @@ export const ConfirmDialog = ({ onClose={() => onClose(false)} dataQa="confirmation-dialog" containerClassName="inline-block w-full min-w-[90%] px-3 py-4 md:p-6 text-center md:min-w-[300px] md:max-w-[500px]" - dismissProps={{ outsidePressEvent: 'mousedown' }} + dismissProps={{ outsidePressEvent: 'mousedown', outsidePress: true }} hideClose heading={heading} headingClassName={headingClassName} diff --git a/apps/chat/src/components/Common/Modal.tsx b/apps/chat/src/components/Common/Modal.tsx index fdad6159af..68d7104946 100644 --- a/apps/chat/src/components/Common/Modal.tsx +++ b/apps/chat/src/components/Common/Modal.tsx @@ -69,7 +69,7 @@ function ModalView({ onOpenChange: onClose, }); const role = useRole(context); - const dismiss = useDismiss(context, dismissProps); + const dismiss = useDismiss(context, { outsidePress: false, ...dismissProps }); const { getFloatingProps } = useInteractions([role, dismiss]); const handleClose = useCallback( diff --git a/apps/chat/src/components/Common/SelectFolder/SelectFolder.tsx b/apps/chat/src/components/Common/SelectFolder/SelectFolder.tsx index ccb3358740..27137a0168 100644 --- a/apps/chat/src/components/Common/SelectFolder/SelectFolder.tsx +++ b/apps/chat/src/components/Common/SelectFolder/SelectFolder.tsx @@ -33,7 +33,7 @@ export const SelectFolder = ({ onClose={onClose} dataQa={modalDataQa} containerClassName="flex flex-col gap-4 md:min-w-[425px] w-[525px] sm:w-[525px] max-w-full" - dismissProps={{ outsidePressEvent: 'mousedown' }} + dismissProps={{ outsidePressEvent: 'mousedown', outsidePress: true }} >
diff --git a/apps/chat/src/components/Files/AttachLinkDialog.tsx b/apps/chat/src/components/Files/AttachLinkDialog.tsx index 83d5504f0d..198a783ac3 100644 --- a/apps/chat/src/components/Files/AttachLinkDialog.tsx +++ b/apps/chat/src/components/Files/AttachLinkDialog.tsx @@ -59,6 +59,7 @@ export const AttachLinkDialog = ({ onClose }: Props) => { overlayClassName="fixed inset-0" containerClassName="inline-block w-full overflow-y-auto px-3 py-4 align-bottom transition-all md:p-6 xl:max-h-[800px] xl:max-w-[720px] 2xl:max-w-[780px]" heading={t('Attach link')} + dismissProps={{ outsidePress: true }} >
diff --git a/apps/chat/src/components/Files/FileManagerModal.tsx b/apps/chat/src/components/Files/FileManagerModal.tsx index 5bbec58bde..47bcb3b681 100644 --- a/apps/chat/src/components/Files/FileManagerModal.tsx +++ b/apps/chat/src/components/Files/FileManagerModal.tsx @@ -570,7 +570,7 @@ export const FileManagerModal = ({ onClose={() => onClose(false)} dataQa="file-manager-modal" containerClassName="flex flex-col gap-4 sm:w-[525px] w-full" - dismissProps={{ outsidePressEvent: 'mousedown' }} + dismissProps={{ outsidePressEvent: 'mousedown', outsidePress: true }} >
diff --git a/apps/chat/src/components/Files/PreUploadModal.tsx b/apps/chat/src/components/Files/PreUploadModal.tsx index f4db5bc350..3eed1d07fc 100644 --- a/apps/chat/src/components/Files/PreUploadModal.tsx +++ b/apps/chat/src/components/Files/PreUploadModal.tsx @@ -360,7 +360,7 @@ export const PreUploadDialog = ({ dataQa="pre-upload-modal" state={isOpen ? ModalState.OPENED : ModalState.CLOSED} onClose={() => onClose(false)} - dismissProps={{ outsidePressEvent: 'mousedown' }} + dismissProps={{ outsidePressEvent: 'mousedown', outsidePress: true }} >
diff --git a/apps/chat/src/components/Settings/SettingDialog.tsx b/apps/chat/src/components/Settings/SettingDialog.tsx index d620e9376e..d43cf3ccfc 100644 --- a/apps/chat/src/components/Settings/SettingDialog.tsx +++ b/apps/chat/src/components/Settings/SettingDialog.tsx @@ -130,7 +130,7 @@ export const SettingDialog: FC = ({ open, onClose }) => { state={open ? ModalState.OPENED : ModalState.CLOSED} onClose={handleClose} initialFocus={saveBtnRef} - dismissProps={{ outsidePressEvent: 'mousedown' }} + dismissProps={{ outsidePressEvent: 'mousedown', outsidePress: true }} >