Add amOwner() and amWriter(). Reject sendMessage() if we lack write access.

This commit is contained in:
Ian Gulliver
2015-12-29 12:00:35 -08:00
parent 415c6ad1fd
commit 3b3755f7f5
2 changed files with 31 additions and 5 deletions

View File

@@ -413,7 +413,7 @@ Cosmopolite.prototype.sendMessage = function(subject, message) {
(subject['readable_only_by'] || subject['writable_only_by'])) {
console.log(this.loggingPrefix_(),
'local subjects can\'t have ACLs:', subject);
reject();
reject(new Error('Local subject with ACL'));
return;
}

View File

@@ -109,6 +109,22 @@ hogfather.PublicChat.prototype.getID = function() {
};
/**
* @return {boolean}
*/
hogfather.PublicChat.prototype.amOwner = function() {
return this.owners_.indexOf(this.cosmo_.currentProfile()) >= 0;
};
/**
* @return {boolean}
*/
hogfather.PublicChat.prototype.amWriter = function() {
return this.writers_.indexOf(this.cosmo_.currentProfile()) >= 0;
};
/**
* @private
* @param {Cosmopolite.typeMessage} message
@@ -162,10 +178,20 @@ hogfather.PublicChat.prototype.getMessages = function() {
* @return {Promise}
*/
hogfather.PublicChat.prototype.sendMessage = function(message) {
return this.cosmo_.sendMessage(this.subject_, {
type: 'message',
message: message,
});
return new Promise(function(resolve, reject) {
if (!this.amWriter()) {
reject(new Error('Write access denied'));
return;
}
this.cosmo_.sendMessage(this.subject_, {
type: 'message',
message: message,
}).then(function(msg) {
resolve(msg);
}).catch(function(err) {
reject(err);
});
}.bind(this));
};