Comments (2)
Suggested API.
Plugin Options
user: A string or object to represent the current user. This will be
attached to the `annotation.user` property.
permissions: An object of permissions, each permission can have an array
of tokens that will be validated against the user object.
By default the permission will be an empty array meaning
anyone can edit it.
Available permissions are as follows:
read: Can the user view the annotation.
update: Can the user edit the annotation.
destroy: Can the user delete the annotation.
admin: Can the user edit the annotation.permissions object.
userId: A callback function that receives the `user` object and returns
a unique id for that user. By default it just returns `user`
userDisplay: A callback function that returns a display name for the user.
By default it just returns `user`
authorize: A callback function that receives the `user` object and a
permissions `token`. The function should return true if the
`user` can perform the action. By default the function will
check to see if `user` === `token`.
Example Usage (Basic)
// All annotations will be world editable but will have a user.
annotator.addPlugin('Permissions', {
user: 'Alice'
});
Example Usage (With Permissions)
A simple permissions model. By default the Permissions plugin will check
the contents of the permissions array for each action to see if it contains
the current user as it does now.
// Anyone can read the annotations but only "Alice" can modify them.
annotator.addPlugin('Permissions', {
user: 'Alice',
permissions: {
'read': [],
'update': ['Alice'],
'destroy': ['Alice'],
'admin': ['Alice']
}
});
Example Usage (Complex With Permissions)
Here we extend the current idea of providing callbacks via the options to allow
complex permission logic such as groups without having to complicate the
Annotator itself.
annotator.addPlugin('Permissions', {
// A user object for the current user.
user: { id: 'alice', name: 'Alice' },
// Object of permissions for the annotation. By default these will be set to
// an empty array. Meaning anyone can edit.
permissions: {
'read': [],
'update': ['alice', 'bob', 'group:logged-in', 'group:admin'],
'destroy': ['alice', 'group:admin'],
'admin': ['alice', 'group:admin']
},
// Function to return the id for a user.
// Allows custom user objects to be used.
userId: function (user) {
return user.id;
},
// Function to return the display name for the user.
userDisplay: function (user) {
return user.name;
},
// Callback function returns true if user matches the token. This allows
// complex logic such as groups to be implemented without complicating
// the annotator.
authorize: function (user, token) {
var group;
if (token.indexOf('group:') === 0) {
group = token.replace('group:', '');
// Local function to check whether this user is in the group. Not
// part of the Annotator.
if (userInGroup(user, group)) {
return true;
}
}
else if (user.id === permission) {
return true;
}
return false;
}
});
from annotator.
The above has been implemented as of 544f9f2, by default Permissions#authorize()
will match simple permission tokens as described in the "simple example" above.
from annotator.
Related Issues (20)
- Dynamic content. How to update ranges?
- Does anyone else have a problem with deleting/updating an annotation? HOT 4
- Is it possible to remove loaded annotations in 2. HOT 1
- Which search key is used? HOT 1
- Documentation for stable/1.2x missing ? HOT 3
- jQuery data is visible only in some stack frames HOT 1
- adjust the z-index
- How to save annotations with store plugin? HOT 20
- Does not display annotations in a pdf document. HOT 2
- viewer: new annotations for the same word
- Store plugin: how to send variable values in annotationData HOT 6
- Unable to console.log store pluggin output getting following error ---- Could not load Tags plugin. Have you included the appropriate <script> tag?
- Uncaught TypeError: Cannot read property 'nodeType' of undefined
- Uncaught TypeError: Cannot read property 'hide' of null
- active forks HOT 2
- Sorry, I don't know how to display the saved data to the page
- Page loading two times when i added annotations to body tag
- i cannot see highlight tags on screen when i loaded annotators (json format)
- this doesn't work. HOT 1
- why jquery is not defined >?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from annotator.