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

Create permissions for a locked down user role #314

Merged
merged 9 commits into from
Dec 28, 2022

Conversation

msm-code
Copy link
Contributor

Your checklist for this pull request

  • I've read the contributing guideline.
  • I've tested my changes by building and running mquery, and testing changed functionality (if applicable)
  • I've added automated tests for my change (if applicable, optional)
  • I've updated documentation to reflect my change (if applicable)

What is the current behaviour?
There is no way to give more fine-grained permissions - everyone is
either an admin or a regulra user.

What is the new behaviour?
As documented in docs/users.md, the user role now is split into four sub-roles

  • can_view_queries: Can view a query with a given ID, and matched files.
  • can_manage_queries: Can create, stop, and delete queries.
  • can_list_queries: Can list queries (for "recent jobs" tab).
  • can_download_files: Can download matched file contents.

That list of sub-permissions is not considered stable yet - in future PR
I may decide to rename, remove or add some of them.

Test plan

Closing issues

fixes #302

docs/users.md Outdated Show resolved Hide resolved
docs/users.md Outdated Show resolved Hide resolved
docs/users.md Outdated

This role names are considered stable, and will continue to work in the future.

User permissions are then split in more fine-grained permissions:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
User permissions are then split in more fine-grained permissions:
User permissions are then split into more fine-grained permissions:

docs/users.md Outdated Show resolved Hide resolved
docs/users.md Outdated Show resolved Hide resolved
docs/users.md Outdated Show resolved Hide resolved
@@ -158,14 +158,14 @@ def __call__(self, user: User = Depends(current_user)):
default_roles = [
role.strip() for role in auth_default_roles.split(",")
]
all_user_roles = list(set(user_roles + default_roles))
all_roles = list(set(user_roles + default_roles))
all_roles = sum((expand_role(role) for role in all_roles), [])
Copy link
Member

Choose a reason for hiding this comment

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

Just making sure that the sum is here used on purpose? The usage looks super weird to me

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, this is basically concat (summing all the given lists). The idea is to get, well, list of all applicable permissions, instead a list of expanded permissions.

For example:

>>> test = [[1, 2, 3], [4, 5, 6], [7, 8]]
>>> sum(test, [])
[1, 2, 3, 4, 5, 6, 7, 8]

I'm not aware of a better idiom for concat in python. If that's unclear I can rewrite it to explicit for loop, or a bit complex list comprehension - I think this will work in this case too:

[perm for role in all_roles for perm in expand(role)]

src/app.py Outdated Show resolved Hide resolved
msm-code and others added 6 commits December 27, 2022 18:18
Co-authored-by: Michał Praszmo <[email protected]>
Co-authored-by: Michał Praszmo <[email protected]>
Co-authored-by: Michał Praszmo <[email protected]>
Co-authored-by: Michał Praszmo <[email protected]>
Co-authored-by: Michał Praszmo <[email protected]>
Co-authored-by: Michał Praszmo <[email protected]>
src/app.py Outdated Show resolved Hide resolved
Co-authored-by: Sharon Yankovich <[email protected]>
@msm-code msm-code merged commit 7a21bfc into master Dec 28, 2022
@msm-code msm-code deleted the feature/limited-user-role branch December 28, 2022 19:33
@msm-code msm-code mentioned this pull request Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a limited user role
3 participants