diff --git a/client/src/api/notifications.ts b/client/src/api/notifications.ts index 2cfaafed696..c5c0fcab813 100644 --- a/client/src/api/notifications.ts +++ b/client/src/api/notifications.ts @@ -25,7 +25,7 @@ export type NewSharedItemNotificationContentItemType = type UserNotificationUpdateRequest = components["schemas"]["UserNotificationUpdateRequest"]; -type NotificationCreateRequest = components["schemas"]["NotificationCreateRequest"]; +export type NotificationCreateRequest = components["schemas"]["NotificationCreateRequestBody"]; type NotificationResponse = components["schemas"]["NotificationResponse"]; diff --git a/client/src/api/schema/schema.ts b/client/src/api/schema/schema.ts index 8202790f40b..e5ef8683f46 100644 --- a/client/src/api/schema/schema.ts +++ b/client/src/api/schema/schema.ts @@ -5391,6 +5391,40 @@ export interface components { /** Tags */ tags?: string[] | null; }; + /** GenericNotificationCreateRequest[Annotated[int, BeforeValidator, BeforeValidator, PlainSerializer, WithJsonSchema, WithJsonSchema]] */ + GenericNotificationCreateRequest_Annotated_int__BeforeValidator__BeforeValidator__PlainSerializer__WithJsonSchema__WithJsonSchema__: { + /** + * Notification + * @description The notification to create. The structure depends on the category. + */ + notification: components["schemas"]["NotificationCreateData"]; + /** + * Recipients + * @description The recipients of the notification. Can be a combination of users, groups and roles. + */ + recipients: components["schemas"]["GenericNotificationRecipients_Annotated_int__BeforeValidator__BeforeValidator__PlainSerializer__WithJsonSchema__WithJsonSchema__"]; + }; + /** GenericNotificationRecipients[Annotated[int, BeforeValidator, BeforeValidator, PlainSerializer, WithJsonSchema, WithJsonSchema]] */ + GenericNotificationRecipients_Annotated_int__BeforeValidator__BeforeValidator__PlainSerializer__WithJsonSchema__WithJsonSchema__: { + /** + * Group IDs + * @description The list of encoded group IDs of the groups that should receive the notification. + * @default [] + */ + group_ids?: string[]; + /** + * Role IDs + * @description The list of encoded role IDs of the roles that should receive the notification. + * @default [] + */ + role_ids?: string[]; + /** + * User IDs + * @description The list of encoded user IDs of the users that should receive the notification. + * @default [] + */ + user_ids?: string[]; + }; /** * GroupCreatePayload * @description Payload schema for creating a group. @@ -9628,22 +9662,8 @@ export interface components { */ variant: components["schemas"]["NotificationVariant"]; }; - /** - * NotificationCreateRequest - * @description Contains the recipients and the notification to create. - */ - NotificationCreateRequest: { - /** - * Notification - * @description The notification to create. The structure depends on the category. - */ - notification: components["schemas"]["NotificationCreateData"]; - /** - * Recipients - * @description The recipients of the notification. Can be a combination of users, groups and roles. - */ - recipients: components["schemas"]["NotificationRecipients"]; - }; + /** NotificationCreateRequestBody */ + NotificationCreateRequestBody: components["schemas"]["GenericNotificationCreateRequest_Annotated_int__BeforeValidator__BeforeValidator__PlainSerializer__WithJsonSchema__WithJsonSchema__"]; /** NotificationCreatedResponse */ NotificationCreatedResponse: { /** @@ -9657,30 +9677,6 @@ export interface components { */ total_notifications_sent: number; }; - /** - * NotificationRecipients - * @description The recipients of a notification. Can be a combination of users, groups and roles. - */ - NotificationRecipients: { - /** - * Group IDs - * @description The list of encoded group IDs of the groups that should receive the notification. - * @default [] - */ - group_ids?: string[]; - /** - * Role IDs - * @description The list of encoded role IDs of the roles that should receive the notification. - * @default [] - */ - role_ids?: string[]; - /** - * User IDs - * @description The list of encoded user IDs of the users that should receive the notification. - * @default [] - */ - user_ids?: string[]; - }; /** * NotificationResponse * @description Basic common fields for all notification responses. @@ -19976,14 +19972,16 @@ export interface operations { }; requestBody: { content: { - "application/json": components["schemas"]["NotificationCreateRequest"]; + "application/json": components["schemas"]["NotificationCreateRequestBody"]; }; }; responses: { /** @description Successful Response */ 200: { content: { - "application/json": components["schemas"]["NotificationCreatedResponse"]; + "application/json": + | components["schemas"]["NotificationCreatedResponse"] + | components["schemas"]["AsyncTaskResultSummary"]; }; }; /** @description Validation Error */ diff --git a/client/src/components/admin/Notifications/NotificationForm.vue b/client/src/components/admin/Notifications/NotificationForm.vue index 027649bc067..c053b5c260a 100644 --- a/client/src/components/admin/Notifications/NotificationForm.vue +++ b/client/src/components/admin/Notifications/NotificationForm.vue @@ -7,7 +7,7 @@ import { computed, type Ref, ref } from "vue"; import { useRouter } from "vue-router/composables"; import { getAllGroups } from "@/api/groups"; -import { sendNotification } from "@/api/notifications"; +import { NotificationCreateRequest, sendNotification } from "@/api/notifications"; import { getAllRoles } from "@/api/roles"; import { type components } from "@/api/schema"; import { getAllUsers } from "@/api/users"; @@ -25,7 +25,6 @@ library.add(faInfoCircle); type SelectOption = [string, string]; type NotificationCreateData = components["schemas"]["NotificationCreateData"]; -type NotificationCreateRequest = components["schemas"]["NotificationCreateRequest"]; interface MessageNotificationCreateData extends NotificationCreateData { category: "message"; diff --git a/lib/galaxy/schema/notifications.py b/lib/galaxy/schema/notifications.py index 43baa23e426..f78624e1120 100644 --- a/lib/galaxy/schema/notifications.py +++ b/lib/galaxy/schema/notifications.py @@ -299,11 +299,14 @@ class GenericNotificationCreateRequest(Model, Generic[DatabaseIdT]): ) -NotificationCreateRequestEncoded = GenericNotificationCreateRequest[DecodedDatabaseIdField] NotificationCreateRequest = GenericNotificationCreateRequest[int] NotificationRecipients = GenericNotificationRecipients[int] +class NotificationCreateRequestBody(RootModel): + root: GenericNotificationCreateRequest[DecodedDatabaseIdField] + + class BroadcastNotificationCreateRequest(NotificationCreateData): """A notification create request specific for broadcasting.""" diff --git a/lib/galaxy/webapps/galaxy/api/notifications.py b/lib/galaxy/webapps/galaxy/api/notifications.py index c62312a63a1..dd23fa05031 100644 --- a/lib/galaxy/webapps/galaxy/api/notifications.py +++ b/lib/galaxy/webapps/galaxy/api/notifications.py @@ -3,7 +3,10 @@ API operations on Notification objects. """ import logging -from typing import Optional +from typing import ( + Optional, + Union, +) from fastapi import ( Body, @@ -19,7 +22,7 @@ from galaxy.schema.notifications import ( BroadcastNotificationResponse, NotificationBroadcastUpdateRequest, NotificationCreatedResponse, - NotificationCreateRequest, + NotificationCreateRequestBody, NotificationsBatchRequest, NotificationsBatchUpdateResponse, NotificationStatusSummary, @@ -30,6 +33,7 @@ from galaxy.schema.notifications import ( UserNotificationsBatchUpdateRequest, UserNotificationUpdateRequest, ) +from galaxy.schema.schema import AsyncTaskResultSummary from galaxy.schema.types import OffsetNaiveDatetime from galaxy.webapps.galaxy.api.common import NotificationIdPathParam from galaxy.webapps.galaxy.services.notifications import NotificationService @@ -219,8 +223,8 @@ class FastAPINotifications: def send_notification( self, trans: ProvidesUserContext = DependsOnTrans, - payload: NotificationCreateRequest = Body(), - ) -> NotificationCreatedResponse: + payload: NotificationCreateRequestBody = Body(), + ) -> Union[NotificationCreatedResponse, AsyncTaskResultSummary]: """Sends a notification to a list of recipients (users, groups or roles).""" return self.service.send_notification(sender_context=trans, payload=payload) diff --git a/lib/galaxy/webapps/galaxy/services/notifications.py b/lib/galaxy/webapps/galaxy/services/notifications.py index a1b82e0fe18..70d35c92ed4 100644 --- a/lib/galaxy/webapps/galaxy/services/notifications.py +++ b/lib/galaxy/webapps/galaxy/services/notifications.py @@ -22,10 +22,10 @@ from galaxy.schema.notifications import ( BroadcastNotificationCreateRequest, BroadcastNotificationListResponse, BroadcastNotificationResponse, - GenericNotificationCreateRequest, NotificationBroadcastUpdateRequest, NotificationCreatedResponse, NotificationCreateRequest, + NotificationCreateRequestBody, NotificationResponse, NotificationsBatchUpdateResponse, NotificationStatusSummary, @@ -48,7 +48,7 @@ class NotificationService(ServiceBase): self.notification_manager = notification_manager def send_notification( - self, sender_context: ProvidesUserContext, payload: NotificationCreateRequest + self, sender_context: ProvidesUserContext, payload: NotificationCreateRequestBody ) -> Union[NotificationCreatedResponse, AsyncTaskResultSummary]: """Sends a notification to a list of recipients (users, groups or roles). @@ -56,10 +56,14 @@ class NotificationService(ServiceBase): """ self.notification_manager.ensure_notifications_enabled() self._ensure_user_can_send_notifications(sender_context) - return self.send_notification_internal(payload) + request = NotificationCreateRequest.model_construct( + notification=payload.root.notification, + recipients=payload.root.recipients, + ) + return self.send_notification_internal(request) def send_notification_internal( - self, request: GenericNotificationCreateRequest + self, request: NotificationCreateRequest ) -> Union[NotificationCreatedResponse, AsyncTaskResultSummary]: """Sends a notification to a list of recipients (users, groups or roles).