From 283a40fd19b46d9b89ba2eb041013c4e464e8fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20M=C3=A6re=20Overskaug?= Date: Tue, 30 Aug 2016 14:13:28 +0200 Subject: [PATCH] fix: add option for another class of auth - readers - since hubot-auth no longer works as it should. https://github.com/hubot-scripts/hubot-auth/issues/42 --- src/auth.coffee | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/auth.coffee b/src/auth.coffee index aeba398..b8c5715 100644 --- a/src/auth.coffee +++ b/src/auth.coffee @@ -25,6 +25,7 @@ config = admin_list: process.env.HUBOT_AUTH_ADMIN + read_list: process.env.HUBOT_AUTH_READ module.exports = (robot) -> @@ -36,10 +37,18 @@ module.exports = (robot) -> else admins = [] + if config.read_list? + readers = config.read_list.split ',' + else + readers = [] + class Auth isAdmin: (user) -> user.id.toString() in admins + isReader: (user) -> + user.id.toString() in readers + hasRole: (user, roles) -> userRoles = @userRoles(user) if userRoles? @@ -59,6 +68,8 @@ module.exports = (robot) -> roles = [] if user? and robot.auth.isAdmin user roles.push('admin') + if user? and robot.auth.isReader user + roles.push('reader') if user.roles? roles = roles.concat user.roles roles