From e1288a67fbb386b3d81e0c68fe9461c3ee75546f Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Fri, 30 May 2014 16:42:30 -0700 Subject: [PATCH] Fixes for read/write ACLs on server and client side --- lib/models.py | 4 ++-- static/cosmopolite.js | 33 ++++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/lib/models.py b/lib/models.py index 853c0d0..48bd90a 100644 --- a/lib/models.py +++ b/lib/models.py @@ -290,10 +290,10 @@ class Subject(db.Model): } readable_only_by = Subject.readable_only_by.get_value_for_datastore(self) if readable_only_by: - ret['readable_only_by'] = readable_only_by + ret['readable_only_by'] = str(readable_only_by) writable_only_by = Subject.writable_only_by.get_value_for_datastore(self) if writable_only_by: - ret['writable_only_by'] = writable_only_by + ret['writable_only_by'] = str(writable_only_by) return ret diff --git a/static/cosmopolite.js b/static/cosmopolite.js index 47aa11c..b7137fb 100644 --- a/static/cosmopolite.js +++ b/static/cosmopolite.js @@ -264,7 +264,7 @@ Cosmopolite.prototype.subscribe = function(subject, opt_messages, opt_last_id) { /** @type {Cosmopolite.typeSubject} */ var canonicalSubject = this.canonicalSubject_(subject); /** @type {string} */ - var subjectString = JSON.stringify(canonicalSubject); + var subjectString = this.subjectString_(canonicalSubject); if (!(subjectString in this.subscriptions_)) { this.subscriptions_[subjectString] = { 'messages': [], @@ -316,7 +316,7 @@ Cosmopolite.prototype.unsubscribe = function(subject) { /** @type {Cosmopolite.typeSubject} */ var canonicalSubject = this.canonicalSubject_(subject); /** @type {string} */ - var subjectString = JSON.stringify(canonicalSubject); + var subjectString = this.subjectString_(canonicalSubject); delete this.subscriptions_[subjectString]; var args = { 'subject': canonicalSubject @@ -364,7 +364,7 @@ Cosmopolite.prototype.getMessages = function(subject) { /** @type {Cosmopolite.typeSubject} */ var canonicalSubject = this.canonicalSubject_(subject); /** @type {string} */ - var subjectString = JSON.stringify(canonicalSubject); + var subjectString = this.subjectString_(canonicalSubject); return this.subscriptions_[subjectString].messages; }; @@ -398,7 +398,7 @@ Cosmopolite.prototype.getPins = function(subject) { /** @type {Cosmopolite.typeSubject} */ var canonicalSubject = this.canonicalSubject_(subject); /** @type {string} */ - var subjectString = JSON.stringify(canonicalSubject); + var subjectString = this.subjectString_(canonicalSubject); return this.subscriptions_[subjectString].pins; }; @@ -546,6 +546,23 @@ Cosmopolite.prototype.canonicalSubject_ = function(subject) { }; +/** + * Stringify a subject for use as an object key. + * + * @param {Cosmopolite.typeSubject} subject + * @return {string} + * @const + * @private + */ +Cosmopolite.prototype.subjectString_ = function(subject) { + return [ + subject['name'], + subject['readable_only_by'], + subject['writable_only_by'] + ].toString(); +}; + + /** * Callback when a script loads. * @@ -1042,13 +1059,15 @@ Cosmopolite.prototype.onLogout_ = function(e) { */ Cosmopolite.prototype.onMessage_ = function(e) { /** @type {string} */ - var subjectString = JSON.stringify(e['subject']); + var subjectString = this.subjectString_(e['subject']); /** @type {Cosmopolite.typeSubscription_} */ var subscription = this.subscriptions_[subjectString]; if (!subscription) { console.log( this.loggingPrefix_(), 'message from unrecognized subject:', e); + console.log(this.subscriptions_); + console.log(subjectString); return; } /** @type {boolean} */ @@ -1088,7 +1107,7 @@ Cosmopolite.prototype.onMessage_ = function(e) { */ Cosmopolite.prototype.onPin_ = function(e) { /** @type {string} */ - var subjectString = JSON.stringify(e['subject']); + var subjectString = this.subjectString_(e['subject']); /** @type {Cosmopolite.typeSubscription_} */ var subscription = this.subscriptions_[subjectString]; if (!subscription) { @@ -1122,7 +1141,7 @@ Cosmopolite.prototype.onPin_ = function(e) { */ Cosmopolite.prototype.onUnpin_ = function(e) { /** @type {string} */ - var subjectString = JSON.stringify(e['subject']); + var subjectString = this.subjectString_(e['subject']); /** @type {Cosmopolite.typeSubscription_} */ var subscription = this.subscriptions_[subjectString]; if (!subscription) {