Skip to content

Overhaul Access System#135

Merged
kosayoda merged 12 commits intomainfrom
roles
Mar 20, 2022
Merged

Overhaul Access System#135
kosayoda merged 12 commits intomainfrom
roles

Conversation

@HassanAbouelela
Copy link
Copy Markdown
Contributor

This PR overhauls the forms access system to be more dynamic and malleable using discord roles. The PR adds utilities to interact with the discord API to fetch roles and member objects, as well as modified preexisting resources to work with the new system.

Important highlights of modified resources:

  • Discord Admins can now access all forms, instead of forms admins
  • Helpers can create forms
  • Forms can be modified by anyone in any role specified in the editors in the form object (except the everyone role).
  • Form responses can be viewed by anyone in any role specified in the response_readers in the form object (except the everyone role).

Signed-off-by: Hassan Abouelela <hassan@hassanamr.com>
Adds discord role support to the pre-existing scopes system to power
more complex access permissions.

Signed-off-by: Hassan Abouelela <hassan@hassanamr.com>
Adds a new property on forms to declare which roles are authorized to
access form responses.

Signed-off-by: Hassan Abouelela <hassan@hassanamr.com>
Adds the ability to specify who can edit forms using discord roles.

Signed-off-by: Hassan Abouelela <hassan@hassanamr.com>
Signed-off-by: Hassan Abouelela <hassan@hassanamr.com>
@HassanAbouelela HassanAbouelela added area: authentication Code relating to authentication with the backend service, typically for admin only routes. type: feature A new feature that should be added to the application. labels Feb 5, 2022
Signed-off-by: Hassan Abouelela <hassan@hassanamr.com>
Comment thread backend/authentication/user.py Outdated
Comment thread backend/discord.py
Comment thread backend/discord.py Outdated
Comment thread backend/discord.py
Comment thread backend/discord.py
Comment thread backend/models/discord_role.py
Comment thread backend/routes/discord.py
Comment thread backend/routes/forms/form.py Outdated
Co-authored-by: Bluenix <bluenixdev@gmail.com>
Signed-off-by: Hassan Abouelela <hassan@hassanamr.com>
Co-authored-by: Bluenix <bluenixdev@gmail.com>
Signed-off-by: Hassan Abouelela <hassan@hassanamr.com>
Copy link
Copy Markdown
Contributor

@kosayoda kosayoda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursory testing works fine so far, but I've haven't had the time to properly review

Comment thread backend/routes/forms/form.py
)

@requires(["authenticated", "admin"])
@requires(["authenticated", "Helpers"])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how this works, and I can't seem to find a reference. Is this tied to a role helper somewhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't tied to a constant, but rather the new access system fetches all the user's roles, and adds their names as scopes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this to a constant at the top of the file or in the constants file so that it is easily changed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need to be easily changed, or changed at all for that matter?

Comment thread backend/authentication/user.py
Signed-off-by: Hassan Abouelela <hassan@hassanamr.com>
Comment thread backend/discord.py Outdated
@Bluenix2
Copy link
Copy Markdown
Contributor

I tested this on my computer and it worked nicely! Not approving until the previous comments have been addressed though.

One thing I do want to bring up is perhaps using a prefix for the role scopes? I feel like we'll eliminate a potential issue with a role and an unrelated scope having matching names or similar. For example, just formatting role: in front of each name (role:Helpers for Helpers), could work nicely.

Copy link
Copy Markdown
Contributor

@kosayoda kosayoda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GET/PATCHing a form both through the frontend and through making requests manually to the backend fails with a 404 for me, which is fixed through the suggested changes and verified by checking the state of the form in the database. Not sure if this is just an issue on my end, since it seems to work fine in @Bluenix2's testing

Comment thread backend/discord.py Outdated
Comment thread backend/routes/forms/form.py Outdated
Comment thread backend/routes/forms/form.py Outdated
Comment thread backend/discord.py Outdated
HassanAbouelela and others added 2 commits March 14, 2022 08:06
Signed-off-by: Hassan Abouelela <hassan@hassanamr.com>
Co-authored-by: Kieran Siek <kieransiek@protonmail.com>
@Bluenix2
Copy link
Copy Markdown
Contributor

GET/PATCHing a form both through the frontend and through making requests manually to the backend fails with a 404 for me, which is fixed through the suggested changes and verified by checking the state of the form in the database. Not sure if this is just an issue on my end, since it seems to work fine in @Bluenix2's testing

I used to have similar issues. See this message in our internal channel where I touch on this. It just magically started working later on (with no code change) which made it possible for me to continue and test it. I shrugged it off as issues with me setting up the project.

PATCHing a form is submitting it yeah? I never did that because I got the form token I needed to make requests manually, testing my ability to create forms and get them when I removed and added roles back to myself.

Copy link
Copy Markdown
Contributor

@kosayoda kosayoda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I still haven't figured out why the Form id field aliasing does not work on my machine, after 27b0c38 it is no longer a blocker.

Namespacing discord roles with role: (or even discord:) suggested by @Bluenix2 could improve the robustness of the starlette permission handling, but it also isn't a blocker for merging this PR.

@kosayoda kosayoda merged commit 25fce5e into main Mar 20, 2022
@kosayoda kosayoda deleted the roles branch March 20, 2022 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: authentication Code relating to authentication with the backend service, typically for admin only routes. type: feature A new feature that should be added to the application.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants