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


Ignore:
Timestamp:
Aug 27, 2012, 5:05:38 PM (12 years ago)
Author:
casties
Branch:
default
Message:

new version of annotator.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • annotator_files/lib/plugin/annotateitpermissions.js

    r3 r4  
     1// Generated by CoffeeScript 1.3.3
    12var __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; };
    56
    67Annotator.Plugin.AnnotateItPermissions = (function(_super) {
    78
    89  __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  }
    921
    1022  AnnotateItPermissions.prototype.options = {
     
    1628      consumer: 'group:__consumer__'
    1729    },
     30    userId: function(user) {
     31      return user.userId;
     32    },
    1833    userString: function(user) {
    19       return user;
     34      return user.userId;
    2035    },
    21     userAuthorize: function(action, annotation, user, consumer) {
    22       var action_field, permissions, _ref, _ref2, _ref3, _ref4;
     36    userAuthorize: function(action, annotation, user) {
     37      var action_field, permissions, _ref, _ref1, _ref2, _ref3;
    2338      permissions = annotation.permissions || {};
    2439      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) {
    2944          return true;
    30         } else if (user === annotation.user && consumer === annotation.consumer) {
     45        } else if (_ref1 = this.groups.authenticated, __indexOf.call(action_field, _ref1) >= 0) {
    3146          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)) {
    3348          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)) {
    3550          return true;
    36         } else if (consumer === annotation.consumer && __indexOf.call(action_field, user) >= 0) {
     51        } else if (user.consumerKey === annotation.consumer && user.admin) {
    3752          return true;
    3853        } else {
     
    4156      }
    4257    },
    43     user: '',
    44     consumer: 'annotateit',
    4558    permissions: {
    4659      'read': ['group:__world__'],
     
    5164  };
    5265
    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 
    7866  AnnotateItPermissions.prototype.addFieldsToAnnotation = function(annotation) {
    7967    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    }
    8171  };
    8272
     
    8575    field = $(field).show();
    8676    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    })) {
    8984      return input.attr('checked', 'checked');
    9085    } else {
     
    9590  AnnotateItPermissions.prototype.updateAnnotationPermissions = function(type, field, annotation) {
    9691    var dataKey;
    97     if (!annotation.permissions) annotation.permissions = this.options.permissions;
     92    if (!annotation.permissions) {
     93      annotation.permissions = this.options.permissions;
     94    }
    9895    dataKey = type + '-permissions';
    9996    if ($(field).find('input').is(':checked')) {
     
    105102
    106103  AnnotateItPermissions.prototype._setAuthFromToken = function(token) {
    107     AnnotateItPermissions.__super__._setAuthFromToken.apply(this, arguments);
    108     return this.setConsumer(token.consumerKey);
     104    return this.setUser(token);
    109105  };
    110106
Note: See TracChangeset for help on using the changeset viewer.