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

Add a constraint that matches to room permission level #1083

Open
Cadair opened this issue Sep 27, 2019 · 4 comments
Open

Add a constraint that matches to room permission level #1083

Cadair opened this issue Sep 27, 2019 · 4 comments

Comments

@Cadair
Copy link
Contributor

Cadair commented Sep 27, 2019

Quite often you only want certain actions to be able to be taken by users who have a given permission level in a room.

In matrix (which I am most familiar with) you would have an integer number represent the power level:

@constrain_room_permissions(100)
def my_skill():

I am not clear on what a cross-connector solution for this would look like.

@jacobtomlinson
Copy link
Member

jacobtomlinson commented Sep 27, 2019

I think this is one of the areas that we are going to find wildly different models between connectors and therefore trying to write a universal constraint will be hard/impossible.

I would be tempted to just try and namespace the import and write a matrix specific one. E.g

from opsdroid.connectors.matrix.constraints import constrain_room_permissions

@constrain_room_permissions(100)
def my_skill(*args, **kwargs):
    pass

Or a slack specific one. E.g

from opsdroid.connectors.slack.constraints import constrain_workspace_admin, constrain_workspace_owner

@constrain_workspace_admin
def my_skill(*args, **kwargs):
    pass

@constrain_workspace_owner
def my_other_skill(*args, **kwargs):
    pass

Similar to the connector specific events.

I guess if you wanted to try and also implement a universal contrain_connector_admin style constraint which tries to sensibly constrain to admin users of the connector then that might be helpful. But it's not going to give you the flexibility that you might want with power levels in matrix.

@jacobtomlinson
Copy link
Member

Heh looking at the Slack API there are some fun things we could do with this and #1085.

from opsdroid.skill import Skill
from opsdroid.matchers import match_parse
from opsdroid.connectors.slack.constraints import constrain_has_2fa, constrain_workspace_admin

class MySkill(Skill):

    @match_parse('do some admin thing!')
    @constrain_workspace_admin
    @constrain_has_2fa(invert=True)
    async def admin_thing(self, message):
        await message.respond("Pfft you might be an admin but you don't have 2FA turned on, how do I know it's really you!")

@SolarDrew
Copy link
Contributor

Of these I think the per-connector approach is better for the flexibility. I think for a few things we might be able to wrap connector-specific things in a more generic core constraint, but I don't know how much that would really benefit us.

@stale
Copy link

stale bot commented Oct 27, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 27, 2019
@stale stale bot closed this as completed Nov 3, 2019
@Cadair Cadair added help wanted and removed stale labels Jun 7, 2023
@Cadair Cadair reopened this Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants