Skip to content

Commit

Permalink
Rejig auth module for Slack
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nickstenning committed Dec 10, 2016
1 parent e89bdfc commit deb8b23
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 36 deletions.
1 change: 0 additions & 1 deletion external-scripts.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[
"hubot-auth",
"hubot-redis-brain",
"hubot-tell"
]
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"dependencies": {
"geocoder": "^0.2.2",
"hubot": "^2.19.0",
"hubot-auth": "^2.0.0",
"hubot-help": "^0.1.1",
"hubot-redis-brain": "0.0.2",
"hubot-slack": "^4.2.2",
Expand Down
21 changes: 21 additions & 0 deletions scripts/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Description:
// Provide easy access to Slack user info.
//
// Author:
// Nick Stenning

'use strict';

class Auth {
isAdmin(user) {
return user.is_admin
}

isStaff(user) {
return !(user.is_restricted || user.is_ultra_restricted)
}
}

module.exports = function (robot) {
robot.auth = new Auth();
};
17 changes: 4 additions & 13 deletions scripts/github.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Description:
// Fetch titles and links to GitHub issues
//
// Configuration:
// HUBOT_GITHUB_ADMIN_ROLE - Who can edit GitHub data
//
// Commands:
// repo#nr - Get title and link to this issue
// hubot add repo <name> - Add repo to stored repository list
Expand All @@ -12,10 +9,6 @@
// hubot compare <repo> <compare> - Get GitHub compare link
//

var config = {
adminRole: process.env.HUBOT_GITHUB_ADMIN_ROLE || 'staff'
};

var VALID_REPO_NAME = /^[^\s\/]+\/[^\s\/]+$/;


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

robot.respond(/remove repo ([^\s]+)$/i, function (msg) {
var repo = msg.match[1];
if (!robot.auth.hasRole(msg.envelope.user, config.adminRole)) {
msg.send("You need the " + config.adminRole + " role to do that! " +
"Ask an admin.");
if (!robot.auth.isStaff(msg.message.user)) {
msg.send("You need to be a staff member to do that, sorry!");
return;
}
var repos = getRepos(robot.brain),
Expand Down
21 changes: 0 additions & 21 deletions scripts/victim.js

This file was deleted.

0 comments on commit deb8b23

Please sign in to comment.