You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+246-21
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ Easy enough.
14
14
make start
15
15
```
16
16
This starts a server on port 5000.
17
-
See the Makefile to change the number of `gunicorn` workers. (Default=17).
17
+
See the Makefile to change the number of `gunicorn` workers. (Default=5).
18
18
19
19
## Run tests
20
20
After installing dependencies in your environment, run
@@ -24,28 +24,253 @@ make test
24
24
25
25
26
26
## API
27
-
(see [the API design doc](design/api.md) for details)
27
+
(see [the API design doc](design/api.md) for details, also see below.)
28
28
### Data Structures
29
29
30
30
**Notification**
31
31
```
32
32
{
33
-
"id": string - a unique id for the notification
34
-
"actor": string - the actor who triggered the notification
35
-
"verb": string - the action represented by this notification (see list of verbs)
36
-
"object": string - the object of the notification
37
-
"target": list - the target(s) of the notification
38
-
39
-
* `id` - a unique id for the notification
40
-
* `actor`
41
-
* `type`
42
-
* `object`
43
-
* `target` - (optional)
44
-
* `source` - source service
45
-
* `level` - alert, error, warning, request
46
-
* `seen`
47
-
* `content` - (optional) free text content string
48
-
* `published` - ISO 8601 datestamp when the notification was originally published.
49
-
* `expires` - ISO 8601 datestamp when the notification will expire and should be removed.
50
-
```
51
-
`GET /api/V1/notifications`
33
+
"id": string - a unique id for the notification,
34
+
"actor": string - the actor who triggered the notification,
35
+
"verb": string - the action represented by this notification (see list of verbs below),
36
+
"object": string - the object of the notification,
37
+
"target": list - the target(s) of the notification,
38
+
"source": string - the source service that created the notification,
39
+
"level": string, one of alert, error, warning, request,
40
+
"seen": boolean, if true, then this has been seen before,
41
+
"created": int - number of milliseconds since the epoch, when the notification was created,
42
+
"expires": int - number of milliseconds since the epoch, when the notification will expire, and will no longer be seen.
43
+
"external_key": string - (optional) a external key that has meaning for the service that created the notification. Meant for use by other services.
44
+
"context": structure - (optional) a (mostly) freely open structure with meaning for the service that created it. The special keys `text` and `link` are intended to be used by the front end viewers. A `link` becomes a hyperlink that would link to some relevant place. `text` gets interpreted as the intended text of the notification, instead of automatically generating it.
45
+
}
46
+
```
47
+
48
+
### Service info
49
+
Returns some basic service info. The current time, the service name and version.
50
+
* Path: `/`
51
+
* Method: `GET`
52
+
* Required headers: none
53
+
* Returns:
54
+
```
55
+
{
56
+
"servertime": <millis since epoch>,
57
+
"service": "Notification Feeds Service",
58
+
"version": "1.0.0"
59
+
}
60
+
```
61
+
62
+
### Permissions
63
+
Returns the allowed endpoints based on the passed authentication header. This will vary, depending on the user or service making the call. For example, a user can only GET their notifications, while a Service can POST notifications.
64
+
* Path: `/permissions`
65
+
* Method: `GET`
66
+
* Required headers: either nothing, or `Authorization`
67
+
* Returns:
68
+
```
69
+
{
70
+
"token": {
71
+
"user": <user id>,
72
+
"service": null or the name of the service if it's a token with type = Service,
73
+
"admin": true if the user has the "FEEDS_ADMIN" custom role
74
+
},
75
+
"permissions": {
76
+
"GET": [ list of paths available with the GET method ],
77
+
"POST": [ list of paths available with the POST method ]
78
+
}
79
+
}
80
+
```
81
+
82
+
### List of API functions
83
+
Returns the visible endpoints for the feeds API.
84
+
* Path: `/api/V1`
85
+
* Method: `GET`
86
+
* Required headers: none
87
+
* Returns a key-value pair object where the keys give some semantic meaning to the paths, and the values are the paths themselves (without the required `/api/V1` part). E.g.:
88
+
```
89
+
{
90
+
"add_notification": "POST /notification",
91
+
"get_notifications": "GET /notifications",
92
+
... etc.
93
+
}
94
+
```
95
+
96
+
### Get a notification feed
97
+
Returns the feed for a single user. This feed is an ordered list of Notifications (see the structure above). It's separated into two parts that are returned at once - the global feed (global notifications set by admins that are intended for all users), and the user's feed with targeted notifications.
98
+
99
+
Options are included to filter by level, source, whether a notification has been seen or not, and the order in which it was created.
100
+
* Path: `/api/V1/notifications`
101
+
* Method: `GET`
102
+
* Required header: `Authorization`
103
+
* URL parameters:
104
+
*`n` - the maximum number of notifications to return. Should be a number > 0. `default 10`
105
+
*`rev` - reverse the chronological sort order if `1`, if `0`, returns with most recent first
106
+
*`l` - filter by the level. Allowed values are `alert`, `warning`, `error`, and `request`
107
+
*`v` - filter by the verb used. Allowed values are listed below under "Create a new notification", and include `invite`, `request`, `shared`, etc.
108
+
*`seen` - return all notifications that have also been seen by the user if this is set to `1`.
109
+
* Returns structure with 2 feeds:
110
+
```
111
+
{
112
+
"global": [ array of global notifications ],
113
+
"user": [ array of user's notifications ]
114
+
}
115
+
```
116
+
#### Examples
117
+
**Get 10 most recent notifications**
118
+
```sh
119
+
curl -X GET
120
+
-H "Authorization: <auth token>"
121
+
https://<service_url>/api/V1/notifications
122
+
```
123
+
returns
124
+
```
125
+
{
126
+
"global": [{note 1}, {note 2}, ...],
127
+
"user": [{note 1}, {note 2}, ... {note 10}]
128
+
}
129
+
```
130
+
(they all return a structure like that, so the return is omitted for the remaining examples)
131
+
132
+
**Get unseen notifications**
133
+
```sh
134
+
curl -X GET
135
+
-H "Authorization: <auth token>"
136
+
https://<service_url>/api/V1/notifications?seen=1
137
+
```
138
+
139
+
**Get up to 50 unseen notifications with verb "share" and level "warning"**
If you have the id of a notification and want to get its structure, just add it to the path.
148
+
* Path: `/api/V1/notification/<note_id>`
149
+
* Method: `GET`
150
+
* Required header: `Authorization`
151
+
* Returns: a single Notification
152
+
153
+
### Get global notifications
154
+
To just return the list of global notifications, use the global path. It returns only a list of notifications in descending chronological order (newest first).
155
+
* Path: `/api/V1/notifications/global`
156
+
* Method: `GET`
157
+
* Required header: none
158
+
* Returns: a list of Notifications
159
+
160
+
### Create a new notification
161
+
Only services (i.e. those Authorization tokens with type=Service, as told by the Auth service) can use this endpoint to create a new notification. This requires the body to be a JSON structure with the following available keys (pretty similar to the Notification structure above):
162
+
*`actor` - required, should be a kbase username
163
+
*`object` - required, the object of the notice (the workspace being shared, the group being invited to, etc.)
164
+
*`verb` - required, the action implied by this notice. Currently allowed verbs are:
165
+
* invite / invited
166
+
* accept / accepted
167
+
* reject / rejected
168
+
* share / shared
169
+
* unshare / unshared
170
+
* join / joined
171
+
* leave / left
172
+
* request / requested
173
+
* update / updated
174
+
*`level` - optional (default `alert`), the level of the request. Affects filtering and visual styling. Currently allowed values are:
175
+
* alert
176
+
* warning
177
+
* error
178
+
* request
179
+
*`target` - (*TODO: update this field*) - currently required, this is a list of user ids that are affected by this notification; and it is also the list of users who see the notification.
180
+
*`source` - (*TODO: update this field*) - currently required, this is the source service of the request.
181
+
*`expires` - optional, an expiration date for the notification in number of milliseconds since the epoch. Default is 30 days after creation.
182
+
*`external_key` - optional, a string that can be used to look up notifications from a service.
183
+
*`context` - optional, a key-value pair structure that can have some semantic meaning for the notification. "Special" keys are `text` - which is used to generate the viewed text in the browser (omitting this will autogenerate the text from the other attributes), and `link` - a URL used to craft a hyperlink in the browser.
184
+
185
+
**Usage:**
186
+
* Path: `/api/V1/notification`
187
+
* Method: `POST`
188
+
* Required header: `Authorization`
189
+
* Returns:
190
+
```
191
+
{"id": <the new notification id>}
192
+
```
193
+
**Example**
194
+
```python
195
+
import requests
196
+
note = {
197
+
"actor": "wjriehl",
198
+
"source": "workspace",
199
+
"verb": "shared",
200
+
"object": "30000",
201
+
"target": ["gaprice"],
202
+
"context": {
203
+
"text": "User wjriehl shared workspace 30000 with user gaprice."# this can also be auto-generated
204
+
}
205
+
}
206
+
r = requests.post("https://<service_url>/api/V1/notification", json=note, headers={"Authorization": auth_token})
207
+
```
208
+
would return:
209
+
```python
210
+
{"id": "some-uuid-for-the-notification"}
211
+
```
212
+
213
+
### Post a global notification
214
+
Functions just as a service would create a new notification, but specialized. This is intended for admins to create a notice that all users should see, whether it's for maintenance, or an upcoming webinar, or something else. As such, there's no target user group, as everyone should be targeted. Also, it requires that whoever posts this must have the custom auth role of "FEEDS_ADMIN" (see the [auth docs](https://github.com/kbase/auth2) for details). As above, it requires a JSON document as the body of the request, with the following fields:
215
+
* verb - required
216
+
* object - required
217
+
* level - required (default alert)
218
+
* context - optional, but `text` is STRONGLY recommended.
219
+
220
+
**Usage:**
221
+
* Path: `/api/V1/notification/global`
222
+
* Method: `POST`
223
+
* Required header: `Authorization` - must have the `FEEDS_ADMIN` role
224
+
* Returns:
225
+
```
226
+
{"id": <the new notification id>}
227
+
```
228
+
229
+
### Mark notifications as seen
230
+
Takes a list of notifications and marks them as seen for the user who submitted the request (does not currently affect global notifications). If the user doesn't have access to a notification in the list, it is marked as unauthorized in the return structure, and nothing is done to it.
231
+
* Path: `/api/V1/notifications/see`
232
+
* Method: `POST`
233
+
* Required header: `Authorization`
234
+
* Expected body:
235
+
```
236
+
{
237
+
"note_ids": [ list of notification ids ]
238
+
}
239
+
```
240
+
* Returns:
241
+
```
242
+
{
243
+
"seen_notes": [ list of seen notification ids ],
244
+
"unauthorized_notes": [ list of notification ids that the user doesn't have access to ]
245
+
}
246
+
```
247
+
248
+
### Mark notifications as unseen
249
+
Takes a list of notifications and marks them as unseen for the user who submitted the request (does not currently affect global notifications). If the user doesn't have access to a notification in the list, it is marked as unauthorized in the return structure, and nothing is done to it.
250
+
* Path: `/api/V1/notifications/unsee`
251
+
* Method: `POST`
252
+
* Required header: `Authorization`
253
+
* Expected body:
254
+
```
255
+
{
256
+
"note_ids": [ list of notification ids ]
257
+
}
258
+
```
259
+
* Returns:
260
+
```
261
+
{
262
+
"unseen_notes": [ list of seen notification ids ],
263
+
"unauthorized_notes": [ list of notification ids that the user doesn't have access to ]
264
+
}
265
+
```
266
+
267
+
### Expire a notification right away
268
+
This effectively deletes notifications by pushing their expiration time up to the time this request is made.
269
+
* Path: `/api/V1/notification/expire`
270
+
* Method: `POST`
271
+
* Required header: `Authorization` - requires a service token.
272
+
* URL Parameters: one of the following:
273
+
*`id` = the notification id
274
+
*`external_key` = the external key
275
+
If both parameters are present, a 400 Bad Request error will be returned.
276
+
Also note that services can only expire their own notifications.
0 commit comments