Skip to content

Commit deb8b23

Browse files
committed
Rejig auth module for Slack
The hubot-auth module doesn't work very well in combination with hubot-slack, mainly because of slackapi/hubot-slack#326 We don't make extensive use of hubot-auth roles, so replace them with a thin wrapper over the user profile data provided by Slack so that we can distinguish between admins/non-admins and staff/guests.
1 parent e89bdfc commit deb8b23

File tree

5 files changed

+25
-36
lines changed

5 files changed

+25
-36
lines changed

external-scripts.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[
2-
"hubot-auth",
32
"hubot-redis-brain",
43
"hubot-tell"
54
]

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"dependencies": {
2424
"geocoder": "^0.2.2",
2525
"hubot": "^2.19.0",
26-
"hubot-auth": "^2.0.0",
2726
"hubot-help": "^0.1.1",
2827
"hubot-redis-brain": "0.0.2",
2928
"hubot-slack": "^4.2.2",

scripts/auth.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Description:
2+
// Provide easy access to Slack user info.
3+
//
4+
// Author:
5+
// Nick Stenning
6+
7+
'use strict';
8+
9+
class Auth {
10+
isAdmin(user) {
11+
return user.is_admin
12+
}
13+
14+
isStaff(user) {
15+
return !(user.is_restricted || user.is_ultra_restricted)
16+
}
17+
}
18+
19+
module.exports = function (robot) {
20+
robot.auth = new Auth();
21+
};

scripts/github.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Description:
22
// Fetch titles and links to GitHub issues
33
//
4-
// Configuration:
5-
// HUBOT_GITHUB_ADMIN_ROLE - Who can edit GitHub data
6-
//
74
// Commands:
85
// repo#nr - Get title and link to this issue
96
// hubot add repo <name> - Add repo to stored repository list
@@ -12,10 +9,6 @@
129
// hubot compare <repo> <compare> - Get GitHub compare link
1310
//
1411

15-
var config = {
16-
adminRole: process.env.HUBOT_GITHUB_ADMIN_ROLE || 'staff'
17-
};
18-
1912
var VALID_REPO_NAME = /^[^\s\/]+\/[^\s\/]+$/;
2013

2114

@@ -141,9 +134,8 @@ var getRepos = function (brain) {
141134
module.exports = function (robot) {
142135
robot.respond(/add repo ([^\s]+)$/i, function (msg) {
143136
var repo = msg.match[1].toLowerCase();
144-
if (!robot.auth.hasRole(msg.envelope.user, config.adminRole)) {
145-
msg.send("You need the " + config.adminRole + " role to do that! " +
146-
"Ask an admin.");
137+
if (!robot.auth.isStaff(msg.message.user)) {
138+
msg.send("You need to be a staff member to do that, sorry!");
147139
return;
148140
}
149141
if (!validRepoName(repo)) {
@@ -163,9 +155,8 @@ module.exports = function (robot) {
163155

164156
robot.respond(/remove repo ([^\s]+)$/i, function (msg) {
165157
var repo = msg.match[1];
166-
if (!robot.auth.hasRole(msg.envelope.user, config.adminRole)) {
167-
msg.send("You need the " + config.adminRole + " role to do that! " +
168-
"Ask an admin.");
158+
if (!robot.auth.isStaff(msg.message.user)) {
159+
msg.send("You need to be a staff member to do that, sorry!");
169160
return;
170161
}
171162
var repos = getRepos(robot.brain),

scripts/victim.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)