1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-03 14:59:18 +02:00
epub.js/libs/annotator/lib/plugin/annotateitpermissions.js

116 lines
4.3 KiB
JavaScript

// Generated by CoffeeScript 1.6.3
var _ref,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
Annotator.Plugin.AnnotateItPermissions = (function(_super) {
__extends(AnnotateItPermissions, _super);
function AnnotateItPermissions() {
this._setAuthFromToken = __bind(this._setAuthFromToken, this);
this.updateAnnotationPermissions = __bind(this.updateAnnotationPermissions, this);
this.updatePermissionsField = __bind(this.updatePermissionsField, this);
this.addFieldsToAnnotation = __bind(this.addFieldsToAnnotation, this);
_ref = AnnotateItPermissions.__super__.constructor.apply(this, arguments);
return _ref;
}
AnnotateItPermissions.prototype.options = {
showViewPermissionsCheckbox: true,
showEditPermissionsCheckbox: true,
groups: {
world: 'group:__world__',
authenticated: 'group:__authenticated__',
consumer: 'group:__consumer__'
},
userId: function(user) {
return user.userId;
},
userString: function(user) {
return user.userId;
},
userAuthorize: function(action, annotation, user) {
var action_field, permissions, _ref1, _ref2, _ref3, _ref4;
permissions = annotation.permissions || {};
action_field = permissions[action] || [];
if (_ref1 = this.groups.world, __indexOf.call(action_field, _ref1) >= 0) {
return true;
} else if ((user != null) && (user.userId != null) && (user.consumerKey != null)) {
if (user.userId === annotation.user && user.consumerKey === annotation.consumer) {
return true;
} else if (_ref2 = this.groups.authenticated, __indexOf.call(action_field, _ref2) >= 0) {
return true;
} else if (user.consumerKey === annotation.consumer && (_ref3 = this.groups.consumer, __indexOf.call(action_field, _ref3) >= 0)) {
return true;
} else if (user.consumerKey === annotation.consumer && (_ref4 = user.userId, __indexOf.call(action_field, _ref4) >= 0)) {
return true;
} else if (user.consumerKey === annotation.consumer && user.admin) {
return true;
} else {
return false;
}
} else {
return false;
}
},
permissions: {
'read': ['group:__world__'],
'update': [],
'delete': [],
'admin': []
}
};
AnnotateItPermissions.prototype.addFieldsToAnnotation = function(annotation) {
if (annotation) {
annotation.permissions = this.options.permissions;
if (this.user) {
annotation.user = this.user.userId;
return annotation.consumer = this.user.consumerKey;
}
}
};
AnnotateItPermissions.prototype.updatePermissionsField = function(action, field, annotation) {
var input;
field = $(field).show();
input = field.find('input').removeAttr('disabled');
if (!this.authorize('admin', annotation)) {
field.hide();
}
if (this.user && this.authorize(action, annotation || {}, {
userId: '__nonexistentuser__',
consumerKey: this.user.consumerKey
})) {
return input.attr('checked', 'checked');
} else {
return input.removeAttr('checked');
}
};
AnnotateItPermissions.prototype.updateAnnotationPermissions = function(type, field, annotation) {
var dataKey;
if (!annotation.permissions) {
annotation.permissions = this.options.permissions;
}
dataKey = type + '-permissions';
if ($(field).find('input').is(':checked')) {
return annotation.permissions[type] = [type === 'read' ? this.options.groups.world : this.options.groups.consumer];
} else {
return annotation.permissions[type] = [];
}
};
AnnotateItPermissions.prototype._setAuthFromToken = function(token) {
return this.setUser(token);
};
return AnnotateItPermissions;
})(Annotator.Plugin.Permissions);
/*
//@ sourceMappingURL=annotateitpermissions.map
*/