Skip to content

Commit

Permalink
packages/core: add permission management module
Browse files Browse the repository at this point in the history
Permissions have been long ignored in Halibot, largely because there hasn't
been a convenient way to manipulate them. This commit adds a core module
to expose some commands for runtime permission management.
  • Loading branch information
richteer committed Oct 1, 2018
1 parent f4a4898 commit 6f62e03
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

from .help import Help
from .perm import PermissionManager
31 changes: 31 additions & 0 deletions packages/core/perm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from halibot import CommandModule
from halibot.halauth import hasPermission

class PermissionManager(CommandModule):
def init(self):
self.commands = {
"grant": self.grant_,
"revoke": self.revoke_,
}

@hasPermission("PERM_GRANT", reply=True)
def grant_(self, argv, msg=None):
try:
ri, identity, perm = argv.split(" ")
except:
self.reply(msg, body="Must be in the form '<ri> <identity> <perm>'")
return

if self._hal.auth.grantPermission(ri, identity, perm):
self._hal.auth.write_perms()

@hasPermission("PERM_REVOKE", reply=True)
def revoke_(self, argv, msg=None):
try:
ri, identity, perm = argv.split(" ")
except:
self.reply(msg, body="Must be in the form '<ri> <identity> <perm>'")
return

if self._hal.auth.revokePermission(ri, identity, perm):
self._hal.auth.write_perms()

0 comments on commit 6f62e03

Please sign in to comment.