Skip to content

Commit

Permalink
Merge branch 'development' of github.com:epam/ai-dial-chat into devel…
Browse files Browse the repository at this point in the history
…opment
  • Loading branch information
irinakartun committed Aug 27, 2024
2 parents ad52731 + 61015ae commit e5621b4
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 15 deletions.
5 changes: 2 additions & 3 deletions apps/chat-e2e/src/tests/prompts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ dialTest(
dataInjector,
promptDropdownMenu,
promptModalDialog,
promptBar,
setTestIds,
}) => {
setTestIds('EPMRTC-953');
Expand All @@ -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(
Expand Down
1 change: 1 addition & 0 deletions apps/chat/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand Down
1 change: 1 addition & 0 deletions apps/chat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | |
Expand Down
1 change: 1 addition & 0 deletions apps/chat/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ declare module 'next-auth' {

declare module 'next-auth/jwt' {
interface JWT extends DefaultJWT {
user: { dial_roles?: string[] };
user: Record<string, string[]>;
}
}
1 change: 1 addition & 0 deletions apps/chat/src/components/Chat/AddonsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export const AddonsDialog: FC<Props> = ({
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 }}
>
<div className="flex h-fit justify-between px-3 md:px-5">
{t('Addons (max 10)')}
Expand Down
1 change: 1 addition & 0 deletions apps/chat/src/components/Chat/ModelsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export const ModelsDialog: FC<ModelsDialogProps> = ({
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 }}
>
<div className="flex justify-between px-3 md:px-5">
{t('Talk to')}
Expand Down
1 change: 1 addition & 0 deletions apps/chat/src/components/Chat/ShareModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export default function ShareModal() {
state={modalState}
onClose={handleClose}
heading={`${t('Share')}: ${shareResourceName?.trim()}`}
dismissProps={{ outsidePress: true }}
>
<div className="flex flex-col justify-between gap-2">
<p className="text-sm text-secondary">
Expand Down
1 change: 1 addition & 0 deletions apps/chat/src/components/Chatbar/ExportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
>
<h4 className="mb-3 text-base font-semibold">{t('Export')}</h4>
<div className="flex flex-col items-start">
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/components/Common/ConfirmDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/components/Common/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
>
<div className="flex flex-col gap-2 overflow-auto">
<div className="flex justify-between px-3 pt-4 md:px-6">
Expand Down
1 change: 1 addition & 0 deletions apps/chat/src/components/Files/AttachLinkDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
>
<form onSubmit={handleSubmit(onSubmit)}>
<div className="mb-4">
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/components/Files/FileManagerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
>
<div className="flex flex-col gap-2 overflow-auto px-3 py-4 md:p-6">
<div className="flex justify-between">
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/components/Files/PreUploadModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
>
<div className="flex flex-col gap-2 overflow-auto">
<div className="flex justify-between">
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/components/Settings/SettingDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const SettingDialog: FC<Props> = ({ open, onClose }) => {
state={open ? ModalState.OPENED : ModalState.CLOSED}
onClose={handleClose}
initialFocus={saveBtnRef}
dismissProps={{ outsidePressEvent: 'mousedown' }}
dismissProps={{ outsidePressEvent: 'mousedown', outsidePress: true }}
>
<button
className="absolute right-2 top-2 rounded text-secondary hover:text-accent-primary"
Expand Down
11 changes: 6 additions & 5 deletions apps/chat/src/utils/auth/auth-callbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e5621b4

Please sign in to comment.