From 75c4dc535d4904a496d5145e1f1e02d83760681d Mon Sep 17 00:00:00 2001 From: Marek Libra Date: Thu, 18 Jan 2024 15:08:26 +0100 Subject: [PATCH] fix(notifications): a few fixes when adding the pkgs to the show-case (#1077) * fix(notifications): make openapi.yaml location relative * chore(notifications): update README for POST example * fix(notifications): add workaround for missing SQLite "ilike" * chore: sidebar item can be provided with a className --- plugins/notifications-backend/README.md | 6 +----- plugins/notifications-backend/package.json | 3 ++- plugins/notifications-backend/src/service/handlers.ts | 4 +++- plugins/notifications-backend/src/service/router.ts | 6 +++++- .../src/components/NotificationsSidebarItem.tsx | 3 +++ 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/plugins/notifications-backend/README.md b/plugins/notifications-backend/README.md index 73862fd554..172dc9ca69 100644 --- a/plugins/notifications-backend/README.md +++ b/plugins/notifications-backend/README.md @@ -204,11 +204,7 @@ A notification without target users or groups is considered a system notificatio Request (User message and then system message): ```bash -curl -X POST http://localhost:7007/api/notifications/notifications -H "Content-Type: application/json" -d '{"title": "My message title", "message": "I have nothing to say", "origin": "my-origin", "targetUsers": ["jdoe"], "targetGroups": ["jdoe"], "actions": [{"title": "my-title", "url": "http://foo.bar"}, {"title": "another action", "url": "https://foo.foo.bar"}]}' -``` - -```bash -curl -X POST http://localhost:7007/api/notifications/notifications -H "Content-Type: application/json" -d '{"title": "My message title", "message": "I have nothing to say", "origin": "my-origin", "actions": [{"title": "my-title", "url": "http://foo.bar"}, {"title": "another action", "url": "https://foo.foo.bar"}]}' +curl -X POST http://localhost:7007/api/notifications/notifications -H "Content-Type: application/json" -d '{"title": "My message title", "message": "I have nothing to say", "origin": "my-origin", "topic":"my topic", "targetUsers": ["default/guest"], "actions": [{"title": "my-title", "url": "http://foo.bar"}, {"title": "another action", "url": "https://foo.foo.bar"}]}' ``` Optionally add `-H "Authorization: Bearer eyJh.....` with a valid JWT token if the service-to-service authorization is enabled (see above). diff --git a/plugins/notifications-backend/package.json b/plugins/notifications-backend/package.json index 808f0d3e94..0e70a8f065 100644 --- a/plugins/notifications-backend/package.json +++ b/plugins/notifications-backend/package.json @@ -55,6 +55,7 @@ "supertest": "6.3.3" }, "files": [ - "dist" + "dist", + "src/openapi.yaml" ] } diff --git a/plugins/notifications-backend/src/service/handlers.ts b/plugins/notifications-backend/src/service/handlers.ts index 50ea662df9..de1401f508 100644 --- a/plugins/notifications-backend/src/service/handlers.ts +++ b/plugins/notifications-backend/src/service/handlers.ts @@ -353,7 +353,9 @@ function createQuery( // filter by text if (filter.containsText) { query.andWhere(function () { - this.whereILike('title', `%${filter.containsText}%`).orWhereILike( + // case-insensitive "whereILike" should be used instead but + // there is bug for SQLite around this: https://github.com/knex/knex/issues/5604 + this.whereLike('title', `%${filter.containsText}%`).orWhereLike( 'message', `%${filter.containsText}%`, ); diff --git a/plugins/notifications-backend/src/service/router.ts b/plugins/notifications-backend/src/service/router.ts index 677067ce6c..074f6305eb 100644 --- a/plugins/notifications-backend/src/service/router.ts +++ b/plugins/notifications-backend/src/service/router.ts @@ -19,6 +19,10 @@ import { } from './permissions'; import { RouterOptions } from './types'; +// TODO: fix filename resolving +const OPENAPI_ROOT = + '../../node_modules/@janus-idp/plugin-notifications-backend/src'; + export async function createRouter( options: RouterOptions, ): Promise { @@ -38,7 +42,7 @@ export async function createRouter( formats: fullFormats, // open issue: https://github.com/openapistack/openapi-backend/issues/280 }, validate: true, - definition: '../../plugins/notifications-backend/src/openapi.yaml', + definition: `${OPENAPI_ROOT}/openapi.yaml`, }); await api.init(); diff --git a/plugins/notifications/src/components/NotificationsSidebarItem.tsx b/plugins/notifications/src/components/NotificationsSidebarItem.tsx index 1c0fc5d38b..d777255ced 100644 --- a/plugins/notifications/src/components/NotificationsSidebarItem.tsx +++ b/plugins/notifications/src/components/NotificationsSidebarItem.tsx @@ -32,6 +32,7 @@ export type NotificationsSidebarItemProps = { * Example: 5000 */ pollingInterval?: number; + className?: string; }; const useStyles = makeStyles(_theme => ({ @@ -42,6 +43,7 @@ const useStyles = makeStyles(_theme => ({ export const NotificationsSidebarItem = ({ pollingInterval, + className, }: NotificationsSidebarItemProps) => { const styles = useStyles(); const notificationsApi = useApi(notificationsApiRef); @@ -88,6 +90,7 @@ export const NotificationsSidebarItem = ({ return ( <>