Permalink
Browse files

Add ifAuthorized wrapper around status and delete.

  • Loading branch information...
1 parent 37e66b1 commit e59862f6a72014c4050414bdf2ebbd88367463d7 @mythmon mythmon committed Aug 8, 2012
Showing with 42 additions and 26 deletions.
  1. +2 −2 api.js
  2. +29 −24 standup-irc.js
  3. +11 −0 utils.js
View
4 api.js
@@ -12,7 +12,7 @@ exports.status = {
project = project.slice(1);
}
var data = {
- user: utils.canonicalUsername(user),
+ user: user,
project: project,
content: content,
api_key: CONFIG.standup.api_key
@@ -25,7 +25,7 @@ exports.status = {
*/
delete_: function(id, user) {
var data = {
- user: utils.canonicalUsername(user),
+ user: user,
api_key: CONFIG.standup.api_key
};
return utils.request('/api/v1/status/' + id + '/', 'DELETE', data);
View
53 standup-irc.js
@@ -61,7 +61,7 @@ logger = new (winston.Logger)({
});
// Global authentication manager
-auth = new auth.AuthManager();
+authman = new auth.AuthManager();
// This regex matches valid IRC nicks.
var NICK_RE = /[a-z_\-\[\]\\{}|`][a-z0-9_\-\[\]\\{}|`]*/;
@@ -132,11 +132,12 @@ client.on('message', function(user, channel, msg) {
client.on('notice', function(from, to, text) {
if (from === undefined) {
+ console.log('Service Notice: ' + text);
from = '';
}
from = from.toLowerCase();
if (from === 'nickserv') {
- auth.notice(from, text);
+ authman.notice(from, text);
}
});
@@ -148,32 +149,36 @@ var commands = {
/* Create a status. */
status: function(user, channel, message, args) {
- var project = args[0];
- if (project.charAt(0) == '#') {
- project = project.slice(1);
- }
- var ret = api.status.create(user, project, args.slice(1).join(' '));
- ret.on('ok', function(data) {
- client.say(channel, 'Ok, submitted status #' + data.id);
- });
- ret.on('error', function(err, data) {
- client.say(channel, 'Uh oh, something went wrong.');
+ utils.ifAuthorized(user, channel, function() {
+ var project = args[0];
+ if (project.charAt(0) == '#') {
+ project = project.slice(1);
+ }
+ var ret = api.status.create(user, project, args.slice(1).join(' '));
+ ret.on('ok', function(data) {
+ client.say(channel, 'Ok, submitted status #' + data.id);
+ });
+ ret.on('error', function(err, data) {
+ client.say(channel, 'Uh oh, something went wrong.');
+ });
});
},
/* Delete a status by id number. */
'delete': function(user, channel, message, args) {
- var ret = api.status.delete_(args[0], user);
- ret.on('ok', function(data) {
- client.say(channel, 'Ok, status #' + args + ' is no more!');
- });
- ret.on('error', function(code, data) {
- if (code === 403) {
- client.say(channel, "You don't have permissiont to do that. " +
- "Do you own that status?");
- } else {
- client.say(channel, "I'm a failure, I couldn't do it.");
- }
+ utils.ifAuthorized(user, channel, function() {
+ var ret = api.status.delete_(args[0], user);
+ ret.on('ok', function(data) {
+ client.say(channel, 'Ok, status #' + args + ' is no more!');
+ });
+ ret.on('error', function(code, data) {
+ if (code === 403) {
+ client.say(channel, "You don't have permissiont to do that. " +
+ "Do you own that status?");
+ } else {
+ client.say(channel, "I'm a failure, I couldn't do it.");
+ }
+ });
});
},
@@ -192,7 +197,7 @@ var commands = {
/* Check a user's authorization status. */
'trust': function(user, channel, message, args) {
- var a = auth.checkUser(args);
+ var a = authman.checkUser(args);
a.on('authorized', function() {
client.say(channel, 'I trust ' + args);
});
View
11 utils.js
@@ -51,3 +51,14 @@ function request(path, method, data, emitter) {
return emitter;
}
this.request = request;
+
+
+this.ifAuthorized = function(user, channel, func) {
+ var a = authman.checkUser(user);
+ a.on('authorized', func);
+ a.on('unauthorized', function() {
+ client.say(channel, "I don't trust you, " + user + ", " +
+ "are you identified with nickserv?");
+ });
+ return a;
+};

0 comments on commit e59862f

Please sign in to comment.