Closed ianjevans closed 9 years ago
Added some debug statements to make sure the user is set.
app.include(annotator.storage.debug);
app.start()
.then(function () {
app.ident.identity = username;
console.log("user is " + app.ident.who());
app.annotations.load({uri: window.location.href});
});
This seems correct:
But user is not being included when the annotation is created:
You're correct. It seems this functionality, which was part of the Permissions plugin in v1.2.x, was never ported over.
We could do so. I'm not sure exactly where / how we would want to do this automatically as v2 is on track to enforce few or no requirements about the annotation properties.
You can do it yourself like this, though:
app.include(function() {
return {
beforeAnnotationCreated: (annotation) {
annotation.user = app.ident.who();
}
}
});
If you don't need to have the user set client-side before the annotation is saved you can also add it server-side. You should do this anyway to enforce that the client can't set whatever user it wants without the server enforcing that it matches the JWT.
I think in 2.0 you've split out the identity and permissions, and include the SimpleIdentityPolicy class to provide similar functionality to 1.2.x. I feel that SimpleIdentityPolicy should allow you to set the user client-side (similar to 1.2.x), and that any server-side identity should be in a different, custom policy.
So, this change to identity.js allows you to set the user on new annotations as I expected.
/**
* function:: simple()
*
* A module that configures and registers an instance of
* :class:`annotator.identity.SimpleIdentityPolicy`.
*/
exports.simple = function simple() {
var identity = new SimpleIdentityPolicy();
return {
configure: function (registry) {
registry.registerUtility(identity, 'identityPolicy');
},
beforeAnnotationCreated: function (annotation) {
annotation.user = identity.identity;
}
};
};
I can create a pull request if you'd like.
Ah, yes! I had forgotten that there was an extension module for the identity policy like this. Yes, the simple identity policy should have such a beforeAnnotationCreated function.
Please, open a PR! That would be lovely. Thanks!
Fixed on master.
I'm testing 2.0 master with our internal docs review system, and it appears that the identity module is not properly setting the user property of the annotation when creating it.
Here is our setup:
Note that I'm logging the username to the browser's console.
The store is based on annotator-store, and is a Flask app. Here's the POST method, where I'm logging the user from the request.
Annotations are being created, but the user property is always None. E.g.
Despite the console showing that username is being properly set: