Skip to content

Commit

Permalink
fix: add option for another class of auth - readers - since hubot-aut…
Browse files Browse the repository at this point in the history
…h no longer works as it should. hubot-archive#42
  • Loading branch information
sondremare committed Aug 30, 2016
1 parent 6447ea8 commit 283a40f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/auth.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

config =
admin_list: process.env.HUBOT_AUTH_ADMIN
read_list: process.env.HUBOT_AUTH_READ

module.exports = (robot) ->

Expand All @@ -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?
Expand All @@ -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
Expand Down

0 comments on commit 283a40f

Please sign in to comment.