-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
packages/core: add permission management module
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
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
|
||
from .help import Help | ||
from .perm import PermissionManager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |