如何设置Hubot基本权限? [英] How to setup Hubot basic permissions?

查看:88
本文介绍了如何设置Hubot基本权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置基本用户权限,以使用户无法运行"Hubot die"或"Hubot show storage"之类的命令?

How do I setup basic user permissions so users can't run commands like "Hubot die" or "Hubot show storage"?

我可以看到有一个名为hubot-auth的脚本,但这似乎是在其他脚本中实现该脚本,而不是控制现有命令.

I can see there is a script called hubot-auth but that seems to be for implementing it in other scripts and not controlling existing commands.

推荐答案

使用Hubot进行自动化和监控一书(无耻的插件).摘录:

There is a small chapter about it in Automation and Monitoring with Hubot book (shameless plug). Excerpt:

只有管理员用户可以分配角色.分配之前无需创建角色.所有你有 要做的是告诉Hubot谁在使用hubot <user> has <role> role.而且您不再需要使用 那些神秘的ID:

Only Admin users can assign roles. You don't have to create a role before assigning. All you have to do is tell Hubot who is who using hubot <user> has <role> role. And you no longer have to use those cryptic IDs anymore:

Tomas     hubot Jesse Pinkman has developer role
Hubot     Tomas: Ok, Jesse Pinkman has the 'developer' role.

使用hubot what roles does <user> have?检查分配的角色:

Tomas     hubot what roles does Jesse Pinkman have?  
Hubot     Tomas: Jesse Pinkman has the following roles: developer.

要从某人中删除该角色,请使用hubot <user> does not have <role> role:

To remove the role from somebody, use hubot <user> does not have <role> role:

Tomas     hubot Jesse Pinkman does not have developer role
Hubot     Tomas: Ok, Jesse Pinkman doesn't have the 'developer' role.

您可以将多个角色分配给多个用户.

You can assign multiple roles to multiple users.

现在,该坏消息了.虽然Hubot Auth非常灵活,但是您必须编辑自己的 脚本来应用这些角色.幸运的是,编辑的内容不多.有一个简单的功能 检查用户是否具有角色-robot.Auth.hasRole(msg.envelope.user, '<role>'). 这是您在脚本中使用它的方式:

Now, time to break the bad news. While Hubot Auth is pretty flexible, you will have to edit your scripts to apply those roles. Luckily, there is not much to edit. There is a simple function that checks if user has a role - robot.Auth.hasRole(msg.envelope.user, '<role>'). This is how you use it in a script:

module.exports = (robot) ->
  robot.respond /do dangerous stuff/i, (msg) ->
    if robot.auth.hasRole(msg.envelope.user, 'developer')
      doDangerousStuff(msg)
    else
      msg.reply "Sorry, you don't have 'developer' role"

  doDangerousStuff = (msg) ->
    msg.send "Doing dangerous stuff"

这篇关于如何设置Hubot基本权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆