From 0a629440ad3f5d7804a659bd9e0da9e28be72d7b Mon Sep 17 00:00:00 2001 From: Eric Schubert Date: Tue, 12 Apr 2022 17:24:37 +0200 Subject: [PATCH] [#40196] added missing endpoints - removed subject from notification representer --- .../components/schemas/notification_model.yml | 8 +++- docs/api/apiv3/openapi-spec.yml | 8 ++++ docs/api/apiv3/paths/notification_read.yml | 33 +++++++++++++ docs/api/apiv3/paths/notification_unread.yml | 33 +++++++++++++ docs/api/apiv3/paths/notifications_read.yml | 47 +++++++++++++++++++ docs/api/apiv3/paths/notifications_unread.yml | 47 +++++++++++++++++++ .../notifications/notification_representer.rb | 3 -- 7 files changed, 174 insertions(+), 5 deletions(-) create mode 100644 docs/api/apiv3/paths/notification_read.yml create mode 100644 docs/api/apiv3/paths/notification_unread.yml create mode 100644 docs/api/apiv3/paths/notifications_read.yml create mode 100644 docs/api/apiv3/paths/notifications_unread.yml diff --git a/docs/api/apiv3/components/schemas/notification_model.yml b/docs/api/apiv3/components/schemas/notification_model.yml index 22a1a1c6f6..776d7f93a5 100644 --- a/docs/api/apiv3/components/schemas/notification_model.yml +++ b/docs/api/apiv3/components/schemas/notification_model.yml @@ -45,7 +45,6 @@ properties: type: object required: - self - - readIAN - project - actor - activity @@ -62,7 +61,12 @@ properties: allOf: - "$ref": "./link.yml" - description: |- - Request to mark the notification as read. + Request to mark the notification as read. Only available if the notification is currently unread. + unreadIAN: + allOf: + - "$ref": "./link.yml" + - description: |- + Request to mark the notification as unread. Only available if the notification is currently read. project: allOf: - "$ref": "./link.yml" diff --git a/docs/api/apiv3/openapi-spec.yml b/docs/api/apiv3/openapi-spec.yml index bd9611685a..74dddb4bbd 100644 --- a/docs/api/apiv3/openapi-spec.yml +++ b/docs/api/apiv3/openapi-spec.yml @@ -222,8 +222,16 @@ paths: "$ref": "./paths/news_item.yml" "/api/v3/notifications": "$ref": "./paths/notifications.yml" + "/api/v3/notifications/read_ian": + "$ref": "./paths/notifications_read.yml" + "/api/v3/notifications/unread_ian": + "$ref": "./paths/notifications_unread.yml" "/api/v3/notifications/{id}": "$ref": "./paths/notification.yml" + "/api/v3/notifications/{id}/read_ian": + "$ref": "./paths/notification_read.yml" + "/api/v3/notifications/{id}/unread_ian": + "$ref": "./paths/notification_unread.yml" "/api/v3/posts/{id}": "$ref": "./paths/post.yml" "/api/v3/posts/{id}/attachments": diff --git a/docs/api/apiv3/paths/notification_read.yml b/docs/api/apiv3/paths/notification_read.yml new file mode 100644 index 0000000000..8da2a3e44f --- /dev/null +++ b/docs/api/apiv3/paths/notification_read.yml @@ -0,0 +1,33 @@ +# /api/v3/notifications/{id}/read_ian +--- +post: + summary: Read notification + operationId: Read_Notification + tags: + - Notifications + description: |- + Marks the given notification as read. + parameters: + - name: id + in: path + description: notification id + example: '1' + required: true + schema: + type: integer + responses: + '204': + description: OK + '404': + content: + application/hal+json: + schema: + $ref: '../components/schemas/error_response.yml' + example: + _type: Error + errorIdentifier: urn:openproject-org:api:v3:errors:NotFound + message: The requested resource could not be found. + description: |- + Returned if the notification does not exist or if the user does not have permission to view it. + + **Required permission** being recipient of the notification diff --git a/docs/api/apiv3/paths/notification_unread.yml b/docs/api/apiv3/paths/notification_unread.yml new file mode 100644 index 0000000000..1a9cddeaf3 --- /dev/null +++ b/docs/api/apiv3/paths/notification_unread.yml @@ -0,0 +1,33 @@ +# /api/v3/notifications/{id}/unread_ian +--- +post: + summary: Unread notification + operationId: Unread_Notification + tags: + - Notifications + description: |- + Marks the given notification as unread. + parameters: + - name: id + in: path + description: notification id + example: '1' + required: true + schema: + type: integer + responses: + '204': + description: OK + '404': + content: + application/hal+json: + schema: + $ref: '../components/schemas/error_response.yml' + example: + _type: Error + errorIdentifier: urn:openproject-org:api:v3:errors:NotFound + message: The requested resource could not be found. + description: |- + Returned if the notification does not exist or if the user does not have permission to view it. + + **Required permission** being recipient of the notification diff --git a/docs/api/apiv3/paths/notifications_read.yml b/docs/api/apiv3/paths/notifications_read.yml new file mode 100644 index 0000000000..87f5288caf --- /dev/null +++ b/docs/api/apiv3/paths/notifications_read.yml @@ -0,0 +1,47 @@ +# /api/v3/notifications/read_ian +--- +post: + summary: Read all notifications + operationId: Read_Notification_Collection + tags: + - Notifications + description: |- + Marks the whole notification collection as read. The collection contains only elements the authenticated user can + see, and can be further reduced with filters. + parameters: + - name: filters + in: query + description: |- + JSON specifying filter conditions. + Accepts the same format as returned by the [queries](https://www.openproject.org/docs/api/endpoints/queries/) + endpoint. Currently supported filters are: + + + id: Filter by primary key + + + project: Filter by the project the notification was created in + + + reason: Filter by the reason, e.g. 'mentioned' or 'assigned' the notification was created because of + + + resourceId: Filter by the id of the resource the notification was created for. Ideally used together with the + `resourceType` filter. + + + resourceType: Filter by the type of the resource the notification was created for. Ideally used together with + the `resourceId` filter. + example: '[{ "reason": { "operator": "=", "values": ["mentioned"] } }]' + required: false + schema: + type: string + responses: + '204': + description: OK + '400': + description: Returned if the request is not properly formatted. + content: + application/hal+json: + schema: + $ref: '../components/schemas/error_response.yml' + example: + _type: Error + errorIdentifier: urn:openproject-org:api:v3:errors:InvalidQuery + message: + - Filters Invalid filter does not exist. diff --git a/docs/api/apiv3/paths/notifications_unread.yml b/docs/api/apiv3/paths/notifications_unread.yml new file mode 100644 index 0000000000..3107a96aaa --- /dev/null +++ b/docs/api/apiv3/paths/notifications_unread.yml @@ -0,0 +1,47 @@ +# /api/v3/notifications/unread_ian +--- +post: + summary: Unread all notifications + operationId: Unread_Notification_Collection + tags: + - Notifications + description: |- + Marks the whole notification collection as unread. The collection contains only elements the authenticated user can + see, and can be further reduced with filters. + parameters: + - name: filters + in: query + description: |- + JSON specifying filter conditions. + Accepts the same format as returned by the [queries](https://www.openproject.org/docs/api/endpoints/queries/) + endpoint. Currently supported filters are: + + + id: Filter by primary key + + + project: Filter by the project the notification was created in + + + reason: Filter by the reason, e.g. 'mentioned' or 'assigned' the notification was created because of + + + resourceId: Filter by the id of the resource the notification was created for. Ideally used together with the + `resourceType` filter. + + + resourceType: Filter by the type of the resource the notification was created for. Ideally used together with + the `resourceId` filter. + example: '[{ "reason": { "operator": "=", "values": ["mentioned"] } }]' + required: false + schema: + type: string + responses: + '204': + description: OK + '400': + description: Returned if the request is not properly formatted. + content: + application/hal+json: + schema: + $ref: '../components/schemas/error_response.yml' + example: + _type: Error + errorIdentifier: urn:openproject-org:api:v3:errors:InvalidQuery + message: + - Filters Invalid filter does not exist. diff --git a/lib/api/v3/notifications/notification_representer.rb b/lib/api/v3/notifications/notification_representer.rb index b2eb7b92fa..f7eb4a2347 100644 --- a/lib/api/v3/notifications/notification_representer.rb +++ b/lib/api/v3/notifications/notification_representer.rb @@ -34,10 +34,7 @@ module API include API::Decorators::LinkedResource extend API::Decorators::PolymorphicResource - self_link title_getter: ->(*) { represented.subject } - property :id - property :subject property :read_ian, as: :readIAN