source: OKFNAnnotator (for Zope)/annotator_files/lib/plugin/annotateitpermissions.js @ 4:6979313586cf

Last change on this file since 4:6979313586cf was 4:6979313586cf, checked in by casties, 12 years ago

new version of annotator.

File size: 4.2 KB
Line 
1// Generated by CoffeeScript 1.3.3
2var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
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; };
6
7Annotator.Plugin.AnnotateItPermissions = (function(_super) {
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  }
21
22  AnnotateItPermissions.prototype.options = {
23    showViewPermissionsCheckbox: true,
24    showEditPermissionsCheckbox: true,
25    groups: {
26      world: 'group:__world__',
27      authenticated: 'group:__authenticated__',
28      consumer: 'group:__consumer__'
29    },
30    userId: function(user) {
31      return user.userId;
32    },
33    userString: function(user) {
34      return user.userId;
35    },
36    userAuthorize: function(action, annotation, user) {
37      var action_field, permissions, _ref, _ref1, _ref2, _ref3;
38      permissions = annotation.permissions || {};
39      action_field = permissions[action] || [];
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) {
44          return true;
45        } else if (_ref1 = this.groups.authenticated, __indexOf.call(action_field, _ref1) >= 0) {
46          return true;
47        } else if (user.consumerKey === annotation.consumer && (_ref2 = this.groups.consumer, __indexOf.call(action_field, _ref2) >= 0)) {
48          return true;
49        } else if (user.consumerKey === annotation.consumer && (_ref3 = user.userId, __indexOf.call(action_field, _ref3) >= 0)) {
50          return true;
51        } else if (user.consumerKey === annotation.consumer && user.admin) {
52          return true;
53        } else {
54          return false;
55        }
56      }
57    },
58    permissions: {
59      'read': ['group:__world__'],
60      'update': [],
61      'delete': [],
62      'admin': []
63    }
64  };
65
66  AnnotateItPermissions.prototype.addFieldsToAnnotation = function(annotation) {
67    AnnotateItPermissions.__super__.addFieldsToAnnotation.apply(this, arguments);
68    if (annotation && this.user) {
69      return annotation.consumer = this.user.consumerKey;
70    }
71  };
72
73  AnnotateItPermissions.prototype.updatePermissionsField = function(action, field, annotation) {
74    var input;
75    field = $(field).show();
76    input = field.find('input').removeAttr('disabled');
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    })) {
84      return input.attr('checked', 'checked');
85    } else {
86      return input.removeAttr('checked');
87    }
88  };
89
90  AnnotateItPermissions.prototype.updateAnnotationPermissions = function(type, field, annotation) {
91    var dataKey;
92    if (!annotation.permissions) {
93      annotation.permissions = this.options.permissions;
94    }
95    dataKey = type + '-permissions';
96    if ($(field).find('input').is(':checked')) {
97      return annotation.permissions[type] = [type === 'read' ? this.options.groups.world : this.options.groups.consumer];
98    } else {
99      return annotation.permissions[type] = [];
100    }
101  };
102
103  AnnotateItPermissions.prototype._setAuthFromToken = function(token) {
104    return this.setUser(token);
105  };
106
107  return AnnotateItPermissions;
108
109})(Annotator.Plugin.Permissions);
Note: See TracBrowser for help on using the repository browser.