Skip to content

Commit

Permalink
Fix generic types in notifications schema
Browse files Browse the repository at this point in the history
Workaround issues with generics auto-generated names when building the client schema.
  • Loading branch information
davelopez committed Apr 8, 2024
1 parent c86e785 commit 4575d1c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 39 deletions.
64 changes: 29 additions & 35 deletions client/src/api/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5394,40 +5394,6 @@ 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.
Expand Down Expand Up @@ -9673,7 +9639,14 @@ export interface components {
variant: components["schemas"]["NotificationVariant"];
};
/** NotificationCreateRequestBody */
NotificationCreateRequestBody: components["schemas"]["GenericNotificationCreateRequest_Annotated_int__BeforeValidator__BeforeValidator__PlainSerializer__WithJsonSchema__WithJsonSchema__"];
NotificationCreateRequestBody: {
/**
* Notification
* @description The notification to create. The structure depends on the category.
*/
notification: components["schemas"]["NotificationCreateData"];
recipients: components["schemas"]["NotificationRecipientsPayload"];
};
/** NotificationCreatedResponse */
NotificationCreatedResponse: {
/**
Expand All @@ -9687,6 +9660,27 @@ export interface components {
*/
total_notifications_sent: number;
};
/** NotificationRecipientsPayload */
NotificationRecipientsPayload: {
/**
* 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.
Expand Down
8 changes: 6 additions & 2 deletions lib/galaxy/schema/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,12 @@ class GenericNotificationCreateRequest(Model, Generic[DatabaseIdT]):
NotificationRecipients = GenericNotificationRecipients[int]


class NotificationCreateRequestBody(RootModel):
root: GenericNotificationCreateRequest[DecodedDatabaseIdField]
class NotificationRecipientsPayload(GenericNotificationRecipients[DecodedDatabaseIdField]):
pass


class NotificationCreateRequestBody(GenericNotificationCreateRequest[DecodedDatabaseIdField]):
recipients: NotificationRecipientsPayload


class BroadcastNotificationCreateRequest(NotificationCreateData):
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/webapps/galaxy/services/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def send_notification(
self.notification_manager.ensure_notifications_enabled()
self._ensure_user_can_send_notifications(sender_context)
request = NotificationCreateRequest.model_construct(
notification=payload.root.notification,
recipients=payload.root.recipients,
notification=payload.notification,
recipients=payload.recipients,
)
return self.send_notification_internal(request)

Expand Down

0 comments on commit 4575d1c

Please sign in to comment.