Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

richteer
Copy link
Contributor

@richteer richteer commented Oct 1, 2018

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 and PERM_REVOKE be merged into a single PERM_EDIT permission?

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.
@richteer richteer added the RFC label Oct 1, 2018
@richteer richteer requested a review from sjrct October 1, 2018 21:51
@richteer richteer added this to the v0.3.0 milestone Oct 1, 2018
@coveralls
Copy link

coveralls commented Oct 1, 2018

Coverage Status

Coverage increased (+0.1%) to 94.821% when pulling 6f62e03 on core-perm-module into e033e85 on master.

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.
def wrapper(self, *args, **kwargs):
msg = None
for i in list(args) + list(kwargs.values()):
if i.__class__ == Message:
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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?

Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants