-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement a PermissionManager core module #116
base: master
Are you sure you want to change the base?
Conversation
The `@hasPermission` decorator was intended to be simple to use for module developers. As it turns out however, it is completely incompatible with modules that subclass CommandModule. Considering this is also a class intended to make life easier, something had to be fixed. Thus, a compromise was reached: have the decorator search for the `Message` object *somewhere* in the target function's parameters. Rather than require it to be the first positional argument, it will instead use the identity/ri information from the *first* `Message` object in the parameter list.
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.
04011ef
to
6f62e03
Compare
def wrapper(self, *args, **kwargs): | ||
msg = None | ||
for i in list(args) + list(kwargs.values()): | ||
if i.__class__ == Message: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about subclasses of Message
? I think we should be checking for those too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it should be checking if the class chain has Message
.
|
||
t = (ri, identity, perm) | ||
if t not in self.perms: | ||
self.perms.append(t) | ||
return True | ||
return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NB: Should we raise an exception here instead of returning false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably. I have a lot of return bools in here, most of those should probably be exceptions. Too much C
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.
There is a bit of a chicken-and-egg problem with this, as you need to grant yourself the permission to edit permissions first. This is a prime candidate for a future CLI-enabled module, but I figured it was better to release this first while #113 is still up in the air.
This branch depends on #115 , since it needs the fixed decorator thanks to the previous implementation's incompatibility with
CommandModule
.Question: Should
PERM_GRANT
andPERM_REVOKE
be merged into a singlePERM_EDIT
permission?