     return
 
   job = CONFIG[environment].job
-  users = CONFIG[environment].users
+  role = CONFIG[environment].role
   params = "BRANCH=#{branch}"
 
-  if user not in users and '*' not in users
-    msg.send "Access denied."
-    msg.send "Valid users are: #{(u for u in users)}"
-    return
+  if not userHasRole(user, role)
+     msg.send "Access denied."
+     msg.send "You must have this role to use this command: #{role}"
+     return
 
   # monkeypatch the msg.match object
   msg.match[1] = job


jenkinsDeploy = (msg, robot) ->
  CONFIG = JSON.parse process.env.HUBOT_DEPLOY_CONFIG

  if not robot.jenkins?.build?
    msg.send "Error: jenkins plugin not installed."

# Configuration:
#   HUBOT_DEPLOY_CONFIG
#
#   CONFIG should be in JSON i.e. '{ "foo": {"job": "deploy-foo", "role": "deploy" } }'
#
#   The "role" field uses the [auth.coffee][1] module for restricting access via user
#   configurable roles. You can set "role" to "*" if you don't care about restricting access.
#
#   [1]: https://github.com/github/hubot-scripts/blob/master/src/scripts/auth.coffee
#
# Commands:
#   hubot deploy <environment> <branch> - deploys the specified branch to the specified environment
