I would like the username that created a record to be associated with that record. This ought to happen on the server and not via the originating client connection. The only place I see on the server to access the username is in canPerformAction. Is it possible to rewrite a message to insert the username before the record is created/updated in the storage connector? And even if I were to write my own storage connector, the username is not passed to the storage connector API. Can you give me any other options or guidance?
Asked
Active
Viewed 151 times
1 Answers
3
Usernames (as well as any other data) can be added to outgoing messages using dataTransform functions. Please find an in-depth explanation here:
http://deepstream.io/tutorials/transforming-data.html
Passing usernames to the storage connector is a bit trickier since there is no 1:1 relationship between a record and a user. If you'd like to create a private record I’d rather make the username part of the record name, e.g.
private-johndoe/iam7f3vy-2mgd656jrx3di
and use the permissionHandler’s canPerformAction
method to make sure that all recordnames that start with ‘private-‘ continue with the name of the user that's interacting with them
canPerformAction: function( username, message, callback ) {
if( message.topic === C.TOPIC.RECORD ) {
var recordName = message.data[ 0 ];
if( recordName.substring( 0, 8 ) === 'private-' ) {
var providedUsername = recordName.substring( 8, recordName.indexOf( '/' ) );
callback( null, providedUsername === username );
}
} else {
callback( null, true );
}
}

wolframhempel
- 1,094
- 10
- 12