feat(coderd): add inbox notifications endpoints (#16889)

This PR is part of the inbox notifications topic, and rely on previous
PRs merged - it adds :

- Endpoints to : 
  - WS : watch new inbox notifications
  - REST : list inbox notifications
  - REST : update the read status of a notification

Also, this PR acts as a follow-up PR from previous work and : 

- fix DB query issues
- fix DBMem logic to match DB
This commit is contained in:
Vincent Vielle
2025-03-18 00:02:47 +01:00
committed by GitHub
parent e85c92e7d5
commit 3ae55bbbf4
20 changed files with 2093 additions and 65 deletions
+162
View File
@@ -46,6 +46,168 @@ Status Code **200**
To perform this operation, you must be authenticated. [Learn more](authentication.md).
## List inbox notifications
### Code samples
```shell
# Example request using curl
curl -X GET http://coder-server:8080/api/v2/notifications/inbox \
-H 'Accept: application/json' \
-H 'Coder-Session-Token: API_KEY'
```
`GET /notifications/inbox`
### Parameters
| Name | In | Type | Required | Description |
|---------------|-------|--------|----------|-------------------------------------------------------------------------|
| `targets` | query | string | false | Comma-separated list of target IDs to filter notifications |
| `templates` | query | string | false | Comma-separated list of template IDs to filter notifications |
| `read_status` | query | string | false | Filter notifications by read status. Possible values: read, unread, all |
### Example responses
> 200 Response
```json
{
"notifications": [
{
"actions": [
{
"label": "string",
"url": "string"
}
],
"content": "string",
"created_at": "2019-08-24T14:15:22Z",
"icon": "string",
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"read_at": "string",
"targets": [
"497f6eca-6276-4993-bfeb-53cbbbba6f08"
],
"template_id": "c6d67e98-83ea-49f0-8812-e4abae2b68bc",
"title": "string",
"user_id": "a169451c-8525-4352-b8ca-070dd449a1a5"
}
],
"unread_count": 0
}
```
### Responses
| Status | Meaning | Description | Schema |
|--------|---------------------------------------------------------|-------------|----------------------------------------------------------------------------------------------|
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.ListInboxNotificationsResponse](schemas.md#codersdklistinboxnotificationsresponse) |
To perform this operation, you must be authenticated. [Learn more](authentication.md).
## Watch for new inbox notifications
### Code samples
```shell
# Example request using curl
curl -X GET http://coder-server:8080/api/v2/notifications/inbox/watch \
-H 'Accept: application/json' \
-H 'Coder-Session-Token: API_KEY'
```
`GET /notifications/inbox/watch`
### Parameters
| Name | In | Type | Required | Description |
|---------------|-------|--------|----------|-------------------------------------------------------------------------|
| `targets` | query | string | false | Comma-separated list of target IDs to filter notifications |
| `templates` | query | string | false | Comma-separated list of template IDs to filter notifications |
| `read_status` | query | string | false | Filter notifications by read status. Possible values: read, unread, all |
### Example responses
> 200 Response
```json
{
"notification": {
"actions": [
{
"label": "string",
"url": "string"
}
],
"content": "string",
"created_at": "2019-08-24T14:15:22Z",
"icon": "string",
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"read_at": "string",
"targets": [
"497f6eca-6276-4993-bfeb-53cbbbba6f08"
],
"template_id": "c6d67e98-83ea-49f0-8812-e4abae2b68bc",
"title": "string",
"user_id": "a169451c-8525-4352-b8ca-070dd449a1a5"
},
"unread_count": 0
}
```
### Responses
| Status | Meaning | Description | Schema |
|--------|---------------------------------------------------------|-------------|------------------------------------------------------------------------------------------|
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.GetInboxNotificationResponse](schemas.md#codersdkgetinboxnotificationresponse) |
To perform this operation, you must be authenticated. [Learn more](authentication.md).
## Update read status of a notification
### Code samples
```shell
# Example request using curl
curl -X PUT http://coder-server:8080/api/v2/notifications/inbox/{id}/read-status \
-H 'Accept: application/json' \
-H 'Coder-Session-Token: API_KEY'
```
`PUT /notifications/inbox/{id}/read-status`
### Parameters
| Name | In | Type | Required | Description |
|------|------|--------|----------|------------------------|
| `id` | path | string | true | id of the notification |
### Example responses
> 200 Response
```json
{
"detail": "string",
"message": "string",
"validations": [
{
"detail": "string",
"field": "string"
}
]
}
```
### Responses
| Status | Meaning | Description | Schema |
|--------|---------------------------------------------------------|-------------|--------------------------------------------------|
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.Response](schemas.md#codersdkresponse) |
To perform this operation, you must be authenticated. [Learn more](authentication.md).
## Get notifications settings
### Code samples
+125
View File
@@ -3016,6 +3016,40 @@ Git clone makes use of this by parsing the URL from: 'Username for "https://gith
|-------|--------|----------|--------------|-------------|
| `key` | string | false | | |
## codersdk.GetInboxNotificationResponse
```json
{
"notification": {
"actions": [
{
"label": "string",
"url": "string"
}
],
"content": "string",
"created_at": "2019-08-24T14:15:22Z",
"icon": "string",
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"read_at": "string",
"targets": [
"497f6eca-6276-4993-bfeb-53cbbbba6f08"
],
"template_id": "c6d67e98-83ea-49f0-8812-e4abae2b68bc",
"title": "string",
"user_id": "a169451c-8525-4352-b8ca-070dd449a1a5"
},
"unread_count": 0
}
```
### Properties
| Name | Type | Required | Restrictions | Description |
|----------------|----------------------------------------------------------|----------|--------------|-------------|
| `notification` | [codersdk.InboxNotification](#codersdkinboxnotification) | false | | |
| `unread_count` | integer | false | | |
## codersdk.GetUserStatusCountsResponse
```json
@@ -3251,6 +3285,61 @@ Git clone makes use of this by parsing the URL from: 'Username for "https://gith
| `refresh` | integer | false | | |
| `threshold_database` | integer | false | | |
## codersdk.InboxNotification
```json
{
"actions": [
{
"label": "string",
"url": "string"
}
],
"content": "string",
"created_at": "2019-08-24T14:15:22Z",
"icon": "string",
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"read_at": "string",
"targets": [
"497f6eca-6276-4993-bfeb-53cbbbba6f08"
],
"template_id": "c6d67e98-83ea-49f0-8812-e4abae2b68bc",
"title": "string",
"user_id": "a169451c-8525-4352-b8ca-070dd449a1a5"
}
```
### Properties
| Name | Type | Required | Restrictions | Description |
|---------------|-------------------------------------------------------------------------------|----------|--------------|-------------|
| `actions` | array of [codersdk.InboxNotificationAction](#codersdkinboxnotificationaction) | false | | |
| `content` | string | false | | |
| `created_at` | string | false | | |
| `icon` | string | false | | |
| `id` | string | false | | |
| `read_at` | string | false | | |
| `targets` | array of string | false | | |
| `template_id` | string | false | | |
| `title` | string | false | | |
| `user_id` | string | false | | |
## codersdk.InboxNotificationAction
```json
{
"label": "string",
"url": "string"
}
```
### Properties
| Name | Type | Required | Restrictions | Description |
|---------|--------|----------|--------------|-------------|
| `label` | string | false | | |
| `url` | string | false | | |
## codersdk.InsightsReportInterval
```json
@@ -3380,6 +3469,42 @@ Git clone makes use of this by parsing the URL from: 'Username for "https://gith
| `icon` | `chat` |
| `icon` | `docs` |
## codersdk.ListInboxNotificationsResponse
```json
{
"notifications": [
{
"actions": [
{
"label": "string",
"url": "string"
}
],
"content": "string",
"created_at": "2019-08-24T14:15:22Z",
"icon": "string",
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"read_at": "string",
"targets": [
"497f6eca-6276-4993-bfeb-53cbbbba6f08"
],
"template_id": "c6d67e98-83ea-49f0-8812-e4abae2b68bc",
"title": "string",
"user_id": "a169451c-8525-4352-b8ca-070dd449a1a5"
}
],
"unread_count": 0
}
```
### Properties
| Name | Type | Required | Restrictions | Description |
|-----------------|-------------------------------------------------------------------|----------|--------------|-------------|
| `notifications` | array of [codersdk.InboxNotification](#codersdkinboxnotification) | false | | |
| `unread_count` | integer | false | | |
## codersdk.LogLevel
```json