Configure relationship change notification
A relationship exists between two managed objects. By default, when a relationship changes (when it is created, updated, or deleted), the managed objects on either side of the relationship are not notified of that change. This means that the state of each object with respect to that relationship field is not recalculated until the object is read. This default behavior improves performance, especially in the case where many objects are affected by a single relationship change.
For roles, a special kind of relationship, change notification is configured by default. The purpose of this default configuration is to notify managed users when any of the relationships that link users, roles, and assignments are manipulated. For more information about relationship change notification in the specific case of managed roles, see Roles and relationship change notification.
To change the default configuration, or to set up notification for other relationship changes, use the notify* properties in the relationship definition, as described in this section.
A relationship exists between an origin object and a referenced object. These terms reflect which managed object is specified in the URL (for example managed/user/psmith), and which object is referenced by the relationship (_ref*) properties. For more information about the relationship properties, see Create a relationship between two objects.
In the previous example, a PUT on managed/user/psmith with "manager" : {_ref : "managed/user/bjensen"}, causes managed/user/psmith to be the origin object, and managed/user/bjensen to be the referenced object for that relationship, as shown in the following illustration:
Note that for the reverse relationship (a PUT on managed/user/bjensen with "reports" : [{_ref = "managed/user/psmith"}]) managed/user/bjensen would be the origin object, and managed/user/psmith would be the referenced object.
By default, when a relationship changes, neither the origin object nor the referenced object is notified of the change. So, with the PUT on managed/user/psmith with "manager" : {_ref : "managed/user/bjensen"}, neither psmith’s object nor bjensen’s object is notified.
|
Auditing is not tied to relationship change notification and is always triggered when a relationship changes. Therefore, relationship changes are audited, regardless of the |
To configure relationship change notification, set the notify and notifySelf properties in your managed object schema. These properties specify whether objects that reference relationships are notified of a relationship change:
notifySelf-
Notifies the origin object of the relationship change.
In our example, if the
managerdefinition includes"notifySelf" : true, and if the relationship is changed through a URL that references psmith, then psmith’s object would be notified of the change. For example, for a CREATE, UPDATE or DELETE request on thepsmith/manager, psmith would be notified, but the managed object referenced by this relationship (bjensen) would not be notified.If the relationship were manipulated through a request to
bjensen/reports, then bjensen would only be notified if thereportsrelationship specified"notifySelf" : true. notify-
Notifies the referenced object of the relationship change. Set this property on the
resourceCollectionof the relationship property.In our example, assume that the
managerdefinition has aresourceCollectionwith apathofmanaged/user, and that this object specifies"notify" : true. If the relationship changes through a CREATE, UPDATE, or DELETE on the URLpsmith/manager, then the reference object (managed/user/bjensen) would be notified of the change to the relationship. notifyRelationships-
This property controls the propagation of notifications out of a managed object when one of its properties changes through an update or patch, or when that object receives a notification through one of these fields.
The
notifyRelationshipsproperty takes an array of relationships as a value; for example,"notifyRelationships" : ["relationship1", "relationship2"]. The relationships specified here are fields defined on the managed object type (which might itself be a relationship).Notifications are propagated according to the recipient’s
notifyRelationshipsconfiguration. If a managed object type is notified of a change through one if its relationship fields, the notification is done according to the configuration of the recipient object. To illustrate, look at theattributesproperty in the defaultmanaged/assignmentobject:{ "name" : "assignment", "schema" : { ... "properties" : { ... "attributes" : { "description" : "The attributes operated on by this assignment.", "title" : "Assignment Attributes", ... "notifyRelationships" : ["roles"] }, ...This configuration means that if an assignment is updated or patched, and the assignment’s
attributeschange in some way, all therolesconnected to that assignment are notified. Because therolemanaged object has"notifyRelationships" : ["members"]defined on itsassignmentsfield, the notification that originated from the change to the assignment attribute is propagated to the connectedroles, and then out to themembersof those roles.So, the
roleis notified through itsassignmentsfield because anattributein the assignment changed. This notification is propagated out of themembersfield because the role definition has"notifyRelationships" : ["members"]on itsassignmentsfield.
By default, roles, assignments, and members use relationship change notification to ensure that relationship changes are accurately provisioned.
For example, the default user object includes a roles property with notifySelf set to true:
{
"name" : "user",
...
"schema" : {
...
"properties" : {
...
"roles" : {
"description" : "Provisioning Roles",
...
"items" : {
"type" : "relationship",
...
"reverseRelationship" : true,
"reversePropertyName" : "members",
"notifySelf" : true,
...
}
...
In this case, notifySelf indicates the origin or user object. If any changes are made to a relationship referencing a role through a URL that includes a user, the user will be notified of the change. For example, if there is a CREATE on managed/user/psmith/roles which specifies a set of references to existing roles, user psmith will be notified of the change.
Similarly, the role object includes a members property. That property includes the following schema definition:
{
"name" : "role",
...
"schema" : {
...
"properties" : {
...
"members" : {
...
"items" : {
"type" : "relationship",
...
"properties" : {
...
"resourceCollection" : [
{
"notify" : true,
"path" : "managed/user",
"label" : "User",
...
}
]
}
...
Notice the "notify" : true setting on the resourceCollection. This setting indicates that if the relationship is created, updated, or deleted through a URL that references that role, all objects in that resource collection (in this case, managed/user objects) that are identified as members of that role must be notified of the change.
|