Changeset 4:6979313586cf in OKFNAnnotator (for Zope) for annotator_files/lib/plugin/annotateitpermissions.js
Legend:
- Unmodified
- Added
- Removed
-
annotator_files/lib/plugin/annotateitpermissions.js
r3 r4 1 // Generated by CoffeeScript 1.3.3 1 2 var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 2 __hasProp = Object.prototype.hasOwnProperty,3 __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; },4 __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };3 __hasProp = {}.hasOwnProperty, 4 __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; }, 5 __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; }; 5 6 6 7 Annotator.Plugin.AnnotateItPermissions = (function(_super) { 7 8 8 9 __extends(AnnotateItPermissions, _super); 10 11 function AnnotateItPermissions() { 12 this._setAuthFromToken = __bind(this._setAuthFromToken, this); 13 14 this.updateAnnotationPermissions = __bind(this.updateAnnotationPermissions, this); 15 16 this.updatePermissionsField = __bind(this.updatePermissionsField, this); 17 18 this.addFieldsToAnnotation = __bind(this.addFieldsToAnnotation, this); 19 return AnnotateItPermissions.__super__.constructor.apply(this, arguments); 20 } 9 21 10 22 AnnotateItPermissions.prototype.options = { … … 16 28 consumer: 'group:__consumer__' 17 29 }, 30 userId: function(user) { 31 return user.userId; 32 }, 18 33 userString: function(user) { 19 return user ;34 return user.userId; 20 35 }, 21 userAuthorize: function(action, annotation, user , consumer) {22 var action_field, permissions, _ref, _ref 2, _ref3, _ref4;36 userAuthorize: function(action, annotation, user) { 37 var action_field, permissions, _ref, _ref1, _ref2, _ref3; 23 38 permissions = annotation.permissions || {}; 24 39 action_field = permissions[action] || []; 25 if ( !(user && consumer)) {26 return _ref = this.groups.world, __indexOf.call(action_field, _ref) >= 0;27 } else {28 if ( _ref2 = this.groups.world, __indexOf.call(action_field, _ref2) >= 0) {40 if (_ref = this.groups.world, __indexOf.call(action_field, _ref) >= 0) { 41 return true; 42 } else if ((user != null) && (user.userId != null) && (user.consumerKey != null)) { 43 if (user.userId === annotation.user && user.consumerKey === annotation.consumer) { 29 44 return true; 30 } else if ( user === annotation.user && consumer === annotation.consumer) {45 } else if (_ref1 = this.groups.authenticated, __indexOf.call(action_field, _ref1) >= 0) { 31 46 return true; 32 } else if ( _ref3 = this.groups.authenticated, __indexOf.call(action_field, _ref3) >= 0) {47 } else if (user.consumerKey === annotation.consumer && (_ref2 = this.groups.consumer, __indexOf.call(action_field, _ref2) >= 0)) { 33 48 return true; 34 } else if ( consumer === annotation.consumer && (_ref4 = this.groups.consumer, __indexOf.call(action_field, _ref4) >= 0)) {49 } else if (user.consumerKey === annotation.consumer && (_ref3 = user.userId, __indexOf.call(action_field, _ref3) >= 0)) { 35 50 return true; 36 } else if ( consumer === annotation.consumer && __indexOf.call(action_field, user) >= 0) {51 } else if (user.consumerKey === annotation.consumer && user.admin) { 37 52 return true; 38 53 } else { … … 41 56 } 42 57 }, 43 user: '',44 consumer: 'annotateit',45 58 permissions: { 46 59 'read': ['group:__world__'], … … 51 64 }; 52 65 53 function AnnotateItPermissions(element, options) {54 this._setAuthFromToken = __bind(this._setAuthFromToken, this);55 this.updateAnnotationPermissions = __bind(this.updateAnnotationPermissions, this);56 this.updatePermissionsField = __bind(this.updatePermissionsField, this);57 this.addFieldsToAnnotation = __bind(this.addFieldsToAnnotation, this); AnnotateItPermissions.__super__.constructor.apply(this, arguments);58 if (this.options.consumer) {59 this.setConsumer(this.options.consumer);60 delete this.options.consumer;61 }62 }63 64 AnnotateItPermissions.prototype.setConsumer = function(consumer) {65 return this.consumer = consumer;66 };67 68 AnnotateItPermissions.prototype.authorize = function(action, annotation, user, consumer) {69 if (user === void 0) user = this.user;70 if (consumer === void 0) consumer = this.consumer;71 if (this.options.userAuthorize) {72 return this.options.userAuthorize.call(this.options, action, annotation, user, consumer);73 } else {74 return true;75 }76 };77 78 66 AnnotateItPermissions.prototype.addFieldsToAnnotation = function(annotation) { 79 67 AnnotateItPermissions.__super__.addFieldsToAnnotation.apply(this, arguments); 80 if (annotation && this.consumer) return annotation.consumer = this.consumer; 68 if (annotation && this.user) { 69 return annotation.consumer = this.user.consumerKey; 70 } 81 71 }; 82 72 … … 85 75 field = $(field).show(); 86 76 input = field.find('input').removeAttr('disabled'); 87 if (!this.authorize('admin', annotation)) field.hide(); 88 if (this.authorize(action, annotation || {}, '__nonexistentuser__')) { 77 if (!this.authorize('admin', annotation)) { 78 field.hide(); 79 } 80 if (this.user && this.authorize(action, annotation || {}, { 81 userId: '__nonexistentuser__', 82 consumerKey: this.user.consumerKey 83 })) { 89 84 return input.attr('checked', 'checked'); 90 85 } else { … … 95 90 AnnotateItPermissions.prototype.updateAnnotationPermissions = function(type, field, annotation) { 96 91 var dataKey; 97 if (!annotation.permissions) annotation.permissions = this.options.permissions; 92 if (!annotation.permissions) { 93 annotation.permissions = this.options.permissions; 94 } 98 95 dataKey = type + '-permissions'; 99 96 if ($(field).find('input').is(':checked')) { … … 105 102 106 103 AnnotateItPermissions.prototype._setAuthFromToken = function(token) { 107 AnnotateItPermissions.__super__._setAuthFromToken.apply(this, arguments); 108 return this.setConsumer(token.consumerKey); 104 return this.setUser(token); 109 105 }; 110 106
Note: See TracChangeset
for help on using the changeset viewer.