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
+44-12
Original file line number
Diff line number
Diff line change
@@ -30,16 +30,38 @@ make test
30
30
(see [the API design doc](design/api.md) for details, also see below.)
31
31
### Data Structures
32
32
33
+
**Entity**
34
+
An Entity structure defines, loosely, an entity related to a notification. This will make more sense below in the Notification object, but Entities are all of the actors in the notifications, the objects of each notification, users who receive the notification, and targets of the notification. For example, in the notification defined by the phrase:
35
+
```
36
+
User "wjriehl" invited user "some_other_user" to join the group "Bill's Fancy Group".
37
+
```
38
+
There are 3 entities:
39
+
1. wjriehl is an entity of type user
40
+
2. some_other_user is an entity of type user
41
+
3. Bill's Fancy Group is an entity of type group
42
+
These are used as a vocabulary to strictly control what's meant in the notification structure.
43
+
44
+
The types currently supported are:
45
+
* user - id should be a user id
46
+
* group - id should be a group id
47
+
* workspace - id should be a workspace id
48
+
* narrative - id should be a workspace id (maybe an UPA if needed)
49
+
* job - id should be a job id string
50
+
{
51
+
"id": string - an id for this notification, defined by context,
52
+
"type": string - what type of entity this is. Allowed values below.
53
+
"name": string (optional) - the full name of this entity (not stored, as its possible it could change)
54
+
}
55
+
```
56
+
33
57
**Notification**
34
58
```
35
59
{
36
60
"id": string - a unique id for the notification,
37
-
"actor": string - the id of the actor who triggered the notification,
38
-
"actor_name": string - the real name (whether group or user) of the actor,
39
-
"actor_type": string - (one of group, user) - type of the actor,
61
+
"actor": Entity - the Entity who triggered the notification (mostly a user),
40
62
"verb": string - the action represented by this notification (see list of verbs below),
41
-
"object": string - the object of the notification,
42
-
"target": list - the target(s) of the notification,
63
+
"object": Entity - the object of the notification,
64
+
"target": list(Entity) - the target(s) of the notification,
43
65
"source": string - the source service that created the notification,
44
66
"level": string, one of alert, error, warning, request,
45
67
"seen": boolean, if true, then this has been seen before,
@@ -190,7 +212,7 @@ This is meant for services to debug their use of external keys. A service that c
190
212
### Create a new notification
191
213
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):
192
214
*`source` - required, this is the source service of the request.
193
-
*`actor` - required, should be a kbase username
215
+
*`actor` - required, should be a valid Entity
194
216
*`object` - required, the object of the notice (the workspace being shared, the group being invited to, etc.)
195
217
*`verb` - required, the action implied by this notice. Currently allowed verbs are:
196
218
* invite / invited
@@ -207,10 +229,11 @@ Only services (i.e. those Authorization tokens with type=Service, as told by the
207
229
* warning
208
230
* error
209
231
* request
210
-
*`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.
232
+
*`target` - optional, but if present should be a list of Entities - the targets of the notification
211
233
*`expires` - optional, an expiration date for the notification in number of milliseconds since the epoch. Default is 30 days after creation.
212
234
*`external_key` - optional, a string that can be used to look up notifications from a service.
213
235
*`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.
236
+
*`users` - optional, a list of Entities that should receive the notification (limited to users and groups). This list will be automatically augmented by the service if necessary. E.g. if a workspace is the object of the notification, then the workspace admins will be notified.
214
237
215
238
**Usage:**
216
239
* Path: `/api/V1/notification`
@@ -224,20 +247,29 @@ Only services (i.e. those Authorization tokens with type=Service, as told by the
224
247
```python
225
248
import requests
226
249
note = {
227
-
"actor": "wjriehl",
250
+
"actor": {
251
+
"id": "wjriehl",
252
+
"type": "user"
253
+
},
228
254
"source": "workspace",
229
255
"verb": "shared",
230
-
"object": "30000",
231
-
"target": ["gaprice"],
256
+
"object": {
257
+
"id": "30000",
258
+
"type": "workspace"
259
+
},
260
+
"target": [{
261
+
"id": "gaprice",
262
+
"type": "user"
263
+
}],
232
264
"context": {
233
-
"text": "User wjriehl shared workspace 30000 with user gaprice."# this can also be auto-generated
265
+
"text": "User wjriehl shared workspace 30000 with user gaprice."# this can also be auto-generated by the UI.
234
266
}
235
267
}
236
268
r = requests.post("https://<service_url>/api/V1/notification", json=note, headers={"Authorization": auth_token})
0 commit comments