Update NotificationCreateRequest definition

Make sure the API endpoint supports the asynchronous mode too.
This commit is contained in:
davelopez
2024-04-16 17:06:14 +02:00
parent 13d9fef42a
commit d29f6db83c
6 changed files with 62 additions and 54 deletions
+1 -1
View File
@@ -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"];
+40 -42
View File
@@ -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 */
@@ -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";
+4 -1
View File
@@ -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."""
@@ -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)
@@ -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).