OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add API documentation for notifications
Oliver Günther6a5bfc292a82
diff --git a/docs/api/apiv3/components/schemas/list_notifications_model.yml b/docs/api/apiv3/components/schemas/list_notifications_model.ymlnew file mode 100644index 00000000000..fe717d66ce1--- /dev/null+++ b/docs/api/apiv3/components/schemas/list_notifications_model.yml@@ -0,0 +1,47 @@+# Schema: List_notificationsModel+---+type: object+example:+ _type: Collection+ _embedded:+ elements:+ - _links:+ readIAN:+ href: "/api/v3/notifications/1/read_ian"+ method: "post"+ actor:+ href: "/api/v3/users/2"+ title: Peggie Feeney+ activity:+ href: "/api/v3/activities/1234"+ project:+ href: "/api/v3/projects/1"+ title: Seeded Project+ self:+ href: "/api/v3/notifications/1"+ _type: Notification+ createdAt: "2021-07-20T08:32:18Z"+ updatedAt: "2021-07-20T08:33:19Z"+ details:+ format: markdown+ raw: "<mention class=\"mention\" data-id=\"90\" data-type=\"user\" data-text=\"@Recipeint User\">@Recipient User</mention> test"+ html: "<p class=\"op-uc-p\"><a class=\"user-mention op-uc-link\" title=\"User Recipient User\" href=\"/users/90\">Recipient User</a> test</p>"+ id: 1+ reason: mentioned+ subject: "You have been mentioned in Task #1234 An important task"+ _links:+ changeSize:+ href: "/api/v3/notifications?offset=1&pageSize=%7Bsize%7D"+ templated: true+ jumpTo:+ href: "/api/v3/notifications?offset=%7Boffset%7D&pageSize=2"+ templated: true+ nextByOffset:+ href: "/api/v3/notifications?offset=2&pageSize=2"+ self:+ href: "/api/v3/notifications?offset=1&pageSize=2"+ _type: Collection+ count: 1+ offset: 1+ pageSize: 50+ total: 1diff --git a/docs/api/apiv3/components/schemas/notification_model.yml b/docs/api/apiv3/components/schemas/notification_model.ymlnew file mode 100644index 00000000000..5f52cb478c2--- /dev/null+++ b/docs/api/apiv3/components/schemas/notification_model.yml@@ -0,0 +1,117 @@+# Schema: NotificationModel+---+type: object+properties:+ id:+ type: integer+ description: Notification id+ readOnly: true+ minimum: 0+ exclusiveMinimum: true+ subject:+ type: string+ description: The subject of the notification+ readOnly: true+ details:+ type: Array+ description: An array of formattable details+ readOnly: true+ reason:+ type: string+ description: The reason for the notification (such as mentioned, involved, watched)+ readOnly: true+ readIAN:+ type: boolean+ description: Whether the notification is marked as read+ readOnly: true+ createdAt:+ type: string+ format: date-time+ description: The time the notification was created at+ readOnly: true+ updatedAt:+ type: string+ format: date-time+ description: The time the notification was last updated+ readOnly: true+ _links:+ type: object+ required:+ - self+ - project+ - actor+ properties:+ self:+ allOf:+ - "$ref": "./link.yml"+ - description: |-+ This notification++ **Resource**: Notification+ readOnly: true+ project:+ allOf:+ - "$ref": "./link.yml"+ - description: |-+ The project the notification originated in++ **Resource**: Project+ readOnly: true+ actor:+ allOf:+ - "$ref": "./link.yml"+ - description: |-+ The user that caused the notification++ **Resource**: User+ readOnly: true+ resource:+ allOf:+ - "$ref": "./link.yml"+ - description: |-+ The linked resource of the notification, if any.++ **Resource**: Polymorphic+ readOnly: true+ activity:+ allOf:+ - "$ref": "./link.yml"+ - description: |-+ The journal activity, if the notification originated from a journal entry++ **Resource**: Activity+ readOnly: true+example:+ _type: News+ id: 1+ title: asperiores possimus nam doloribus ab+ summary: Celebrer spiculum colo viscus claustrum atque. Id nulla culpa sumptus.+ Comparo crapula depopulo demonstro.+ description:+ format: markdown+ raw: Videlicet deserunt aequitas cognatus. Concedo quia est quia pariatur vorago+ vallum. Calco autem atavus accusamus conscendo cornu ulterius. Tam patria ago+ consectetur ventito sustineo nihil caecus. Supra officiis eos velociter somniculosus+ tonsor qui. Suffragium aduro arguo angustus cogito quia tolero vulnus. Supplanto+ sortitus cresco apud vestrum qui.+ html: "<p>Videlicet deserunt aequitas cognatus. Concedo quia est quia pariatur+ vorago vallum. Calco autem atavus accusamus conscendo cornu ulterius. Tam patria+ ago consectetur ventito sustineo nihil caecus. Supra officiis eos velociter+ somniculosus tonsor qui. Suffragium aduro arguo angustus cogito quia tolero+ vulnus. Supplanto sortitus cresco apud vestrum qui.</p>"+ createdAt: '2015-03-20T12:57:01Z'+ _links:+ self:+ href: "/api/v3/news/1"+ title: asperiores possimus nam doloribus ab+ project:+ href: "/api/v3/projects/1"+ title: A project+ author:+ href: "/api/v3/users/2"+ title: Peggie Feeney+ _embedded:+ project:+ _type: Project...+ author:+ _type: User...diff --git a/docs/api/apiv3/openapi-spec.yml b/docs/api/apiv3/openapi-spec.ymlindex 618f49bf742..941330064df 100644--- a/docs/api/apiv3/openapi-spec.yml+++ b/docs/api/apiv3/openapi-spec.yml@@ -201,6 +201,10 @@ paths:"$ref": "./paths/news.yml""/api/v3/news/{id}":"$ref": "./paths/news_item.yml"+ "/api/v3/notifications":+ "$ref": "./paths/notifications.yml"+ "/api/v3/notifications/{id}":+ "$ref": "./paths/notifications_item.yml""/api/v3/posts/{id}":"$ref": "./paths/post.yml""/api/v3/posts/{id}/attachments":@@ -511,6 +515,8 @@ components:"$ref": "./components/schemas/list_memberships_model.yml"List_of_NewsModel:"$ref": "./components/schemas/list_of_news_model.yml"+ List_notificationsModel:+ "$ref": "./components/schemas/list_notifications_model.yml"List_projectsModel:"$ref": "./components/schemas/list_projects_model.yml"List_projects_by_versionModel:@@ -531,6 +537,8 @@ components:"$ref": "./components/schemas/membership_update_form.yml"NewsModel:"$ref": "./components/schemas/news_model.yml"+ NotificationModel:+ "$ref": "./components/schemas/notification_model.yml"Offset_based_pagination:"$ref": "./components/schemas/offset_based_pagination.yml"Plain_Text:@@ -736,6 +744,7 @@ tags:- "$ref": "./tags/help_texts.yml"- "$ref": "./tags/memberships.yml"- "$ref": "./tags/news.yml"+- "$ref": "./tags/notifications.yml"- "$ref": "./tags/posts.yml"- "$ref": "./tags/principals.yml"- "$ref": "./tags/priorities.yml"diff --git a/docs/api/apiv3/paths/notifications.yml b/docs/api/apiv3/paths/notifications.ymlnew file mode 100644index 00000000000..1421063bbde--- /dev/null+++ b/docs/api/apiv3/paths/notifications.yml@@ -0,0 +1,152 @@+# /api/v3/notifications+---+get:+ parameters:+ - description: Page number inside the requested collection.+ example: '25'+ in: query+ name: offset+ required: false+ schema:+ default: 1+ type: integer+ - description: Number of elements to display per page.+ example: '25'+ in: query+ name: pageSize+ required: false+ schema:+ type: integer+ - description: |-+ JSON specifying sort criteria.+ Accepts the same format as returned by the [queries](https://www.openproject.org/docs/api/endpoints/queries/) endpoint. Currently supported sorts are:++ + id: Sort by primary key++ + reason: Sort by notification reason++ + readIAN: Sort by read status+ example: '[["reason", "asc"]]'+ in: query+ name: sortBy+ required: false+ schema:+ type: string+ - 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:++ + readIAN: Filter by read status+ + id: Filter by primary key+ example: '[{ "readIAN": { "operator": "=", "values": ["t"] } }]'+ in: query+ name: filters+ required: false+ schema:+ type: string+ responses:+ '200':+ content:+ application/hal+json:+ examples:+ response:+ value:+ _embedded:+ elements:+ - _links:+ readIAN:+ href: "/api/v3/notifications/1/read_ian"+ method: "post"+ actor:+ href: "/api/v3/users/2"+ title: Peggie Feeney+ activity:+ href: "/api/v3/activities/1234"+ project:+ href: "/api/v3/projects/1"+ title: Seeded Project+ self:+ href: "/api/v3/notifications/1"+ _type: Notification+ createdAt: "2021-07-20T08:32:18Z"+ updatedAt: "2021-07-20T08:33:19Z"+ details:+ format: markdown+ raw: "<mention class=\"mention\" data-id=\"90\" data-type=\"user\" data-text=\"@Recipeint User\">@Recipient User</mention> test"+ html: "<p class=\"op-uc-p\"><a class=\"user-mention op-uc-link\" title=\"User Recipient User\" href=\"/users/90\">Recipient User</a> test</p>"+ id: 1+ reason: mentioned+ subject: "You have been mentioned in Task #1234 An important task"+ - _links:+ readIAN:+ href: "/api/v3/notifications/1/read_ian"+ method: "post"+ actor:+ href: "/api/v3/users/2"+ title: Peggie Feeney+ activity:+ href: "/api/v3/activities/1234"+ project:+ href: "/api/v3/projects/1"+ title: Seeded Project+ self:+ href: "/api/v3/notifications/1"+ _type: Notification+ createdAt: "2021-07-20T08:32:18Z"+ updatedAt: "2021-07-20T08:33:19Z"+ details:+ format: markdown+ raw: "<mention class=\"mention\" data-id=\"90\" data-type=\"user\" data-text=\"@Recipeint User\">@Recipient User</mention> test"+ html: "<p class=\"op-uc-p\"><a class=\"user-mention op-uc-link\" title=\"User Recipient User\" href=\"/users/90\">Recipient User</a> test</p>"+ id: 1+ reason: mentioned+ subject: "You have been mentioned in Task #1234 An important task"+ _links:+ changeSize:+ href: "/api/v3/notifications?offset=1&pageSize=%7Bsize%7D"+ templated: true+ jumpTo:+ href: "/api/v3/notifications?offset=%7Boffset%7D&pageSize=2"+ templated: true+ nextByOffset:+ href: "/api/v3/notifications?offset=2&pageSize=2"+ self:+ href: "/api/v3/notifications?offset=1&pageSize=2"+ _type: Collection+ count: 1+ offset: 1+ pageSize: 50+ total: 1+ schema:+ "$ref": "../components/schemas/list_notifications_model.yml"+ description: OK+ headers: { }+ '400':+ content:+ application/hal+json:+ examples:+ response:+ value:+ _type: Error+ errorIdentifier: urn:openproject-org:api:v3:errors:InvalidQuery+ message:+ - Filters Invalid filter does not exist.+ description: Returned if the client sends invalid request parameters e.g. filters+ headers: { }+ '403':+ content:+ application/hal+json:+ examples:+ response:+ value:+ _type: Error+ errorIdentifier: urn:openproject-org:api:v3:errors:MissingPermission+ message: You are not authorized to view this resource.+ description: Returned if the client is not logged in and login is required.+ headers: { }+ tags:+ - Notifications+ description: Lists available in-app notifications. The notifications returned depend on the provided parameters and+ also on the requesting user's permissions.+ operationId: List_Notifications+ summary: List Notificationsdiff --git a/docs/api/apiv3/paths/notifications_item.yml b/docs/api/apiv3/paths/notifications_item.ymlnew file mode 100644index 00000000000..b4f60b36607--- /dev/null+++ b/docs/api/apiv3/paths/notifications_item.yml@@ -0,0 +1,99 @@+# /api/v3/notifications/{id}+---+get:+ parameters:+ - description: notification id+ example: '1'+ in: path+ name: id+ required: true+ schema:+ type: integer+ responses:+ '200':+ content:+ application/hal+json:+ examples:+ response:+ value:+ _embedded:+ actor:+ _type: 'User'+ id: 2+ name: "Peggie Feeney"+ project:+ _type: 'Project'+ id: 1+ name: "Seeded project"+ identifier: "seeded-project"+ resource:+ _type: 'WorkPackage'+ id: 55+ subject: "An important task"+ activity:+ _type: "Activity::Comment"+ id: 1234+ comment:+ format: markdown+ raw: "<mention class=\"mention\" data-id=\"90\" data-type=\"user\" data-text=\"@Recipeint User\">@Recipient User</mention> test"+ html: "<p class=\"op-uc-p\"><a class=\"user-mention op-uc-link\" title=\"User Recipient User\" href=\"/users/90\">Recipient User</a> test</p>"+ details: []+ version: 8+ createdAt: "2021-07-20T08:32:18Z"+ _links:+ self:+ href: "/api/v3/activities/1234"+ workPackage:+ href: "/api/v3/work_packages/55"+ user:+ href: "/api/v3/users/2"+ update:+ href: "/api/v3/activities/1234"+ method: patch+ _links:+ readIAN:+ href: "/api/v3/notifications/1/read_ian"+ method: "post"+ actor:+ href: "/api/v3/users/2"+ title: Peggie Feeney+ activity:+ href: "/api/v3/activities/1234"+ project:+ href: "/api/v3/projects/1"+ title: Seeded Project+ self:+ href: "/api/v3/notifications/1"+ _type: Notification+ createdAt: "2021-07-20T08:32:18Z"+ updatedAt: "2021-07-20T08:33:19Z"+ details:+ format: markdown+ raw: "<mention class=\"mention\" data-id=\"90\" data-type=\"user\" data-text=\"@Recipeint User\">@Recipient User</mention> test"+ html: "<p class=\"op-uc-p\"><a class=\"user-mention op-uc-link\" title=\"User Recipient User\" href=\"/users/90\">Recipient User</a> test</p>"+ id: 1+ reason: mentioned+ subject: "You have been mentioned in Task #1234 An important task"+ schema:+ "$ref": "../components/schemas/notification_model.yml"+ description: OK+ headers: {}+ '404':+ content:+ application/hal+json:+ examples:+ response:+ value:+ _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+ headers: {}+ tags:+ - Notifications+ description: ''+ operationId: View_notification+ summary: View notificationdiff --git a/docs/api/apiv3/tags/notifications.yml b/docs/api/apiv3/tags/notifications.ymlnew file mode 100644index 00000000000..5d2bba84772--- /dev/null+++ b/docs/api/apiv3/tags/notifications.yml@@ -0,0 +1,29 @@+---+description: |-+ Notifications are created through notifiable actions in OpenProject.+ This endpoint only returns in-app notifications.++ ## Actions++ None yet++ ## Linked Properties++ | Link | Description | Type | Constraints | Supported operations | Condition |+ | :-----------: | ---------------------------------------- | -------------- | --------------------- | -------------------- | ----------------------------------------- |+ | self | This notification | Notification | not null | READ | |+ | project | The project containng the resource | Project | not null | READ | |+ | actor | The user that caused the notification | User | not null | READ | |+ | resource | The resource the notification belongs to | Polymorphic | not null | READ | |+ | activity | The journal the notification belongs to | Polymorphic | | READ | optional |++ ## Local Properties++ | Property | Description | Type | Constraints | Supported operations | Condition |+ | :----------: | --------------------------------------------------------- | -------- | ---------------------------------------------------- | -------------------- | ----------------------------------------------------------- |+ | id | Primary key | Integer | | READ | |+ | subject | The subject of the notification | String | | READ | |+ | details | Array of formattable details | []Formattable | | READ | |+ | reason | The reason causing the notification | String | | READ | |+ | readIAN | Whether the notification is read | Boolean | | READ | |+name: Notificationsdiff --git a/lib/api/open_api.rb b/lib/api/open_api.rbindex 6d618e92cc3..279282603e5 100644--- a/lib/api/open_api.rb+++ b/lib/api/open_api.rb@@ -27,6 +27,8 @@ module APIspec = YAML.safe_load File.read(file_path.to_s)substitute_refs(spec, path: file_path.parent, root_path: file_path.parent)+ rescue Psych::SyntaxError => e+ raise "Failed to load #{file_path}: #{e.class} #{e.message}"enddef substitute_refs(spec, path:, root_path:, root_spec: spec)@@ -49,6 +51,8 @@ module APIelsespec.transform_values { |v| substitute_refs(v, path: path, root_path: root_path, root_spec: root_spec) }end+ rescue Psych::SyntaxError => e+ raise "Failed to load #{ref_path}: #{e.class} #{e.message}"enddef resolve_refs(spec, path:, root_path:, root_spec:)