-
Notifications
You must be signed in to change notification settings - Fork 32
♻️ web-server: Refactor users domain for improved layer separation and upgrading to asyncpg
#6937
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
Merged
pcrespov
merged 126 commits into
ITISFoundation:master
from
pcrespov:is1779/refactor-users
Dec 16, 2024
Merged
Changes from 94 commits
Commits
Show all changes
126 commits
Select commit
Hold shift + click to select a range
497dc84
first round
pcrespov c0f3318
fixes engines
pcrespov 529c28f
handlers and mvs models
pcrespov 3120ff7
cleanup
pcrespov 42030b4
cleanup
pcrespov 410a651
rename
pcrespov 7c252d2
minor
pcrespov 76a4a5f
updating db in api module
pcrespov d37149b
mypy
pcrespov a2859ef
rename
pcrespov b4f6ce1
moves schemas to models_library
pcrespov ed59622
moves users
pcrespov 396eb7a
moves users
pcrespov 0b73497
common
pcrespov aad32e7
moves to models-library
pcrespov e3ffe7d
annotated
pcrespov 9e3c9fa
some rename
pcrespov 44261bf
rest shcmeas
pcrespov a008fd6
tokens update
pcrespov 57fb63c
tokens
pcrespov e4a0b5e
tokens tests
pcrespov 43c4250
fixes
pcrespov 832db9e
utils mixin
pcrespov 1bf60ee
asyncpg version of aggregation
pcrespov 18a68ab
cleanup
pcrespov 3562640
cleanup
pcrespov c02392a
rm async
pcrespov 401282b
adds tests
pcrespov 256214e
mypy
pcrespov 0fb7368
_common rename
pcrespov a0c6c05
isolated tests
pcrespov 3e37a1b
bad merge
pcrespov 4a694da
mv api -> service
pcrespov 835b8d8
cleanup
pcrespov f570190
bad import
pcrespov c8a9e7e
drop unnecesary dependencies
pcrespov 7a30cc6
cleanup
pcrespov 12fc813
renames
pcrespov f2d28d3
error handling
pcrespov 2b7c40e
doc
pcrespov 5725250
update OAS
pcrespov 9541669
first round
pcrespov 37b580e
fixes engines
pcrespov d99ed9f
handlers and mvs models
pcrespov 4862222
cleanup
pcrespov 48bf359
cleanup
pcrespov de6c58d
rename
pcrespov b4f1c04
minor
pcrespov ada1d77
updating db in api module
pcrespov bcca9de
mypy
pcrespov 4eb69ce
rename
pcrespov 8b2fa18
moves schemas to models_library
pcrespov 71380f2
moves users
pcrespov 10d6c20
moves users
pcrespov fa1299b
common
pcrespov 8265042
moves to models-library
pcrespov f0edcc0
annotated
pcrespov c8f89f7
some rename
pcrespov e4cc55e
rest shcmeas
pcrespov 669318f
tokens update
pcrespov 0bfa09c
tokens
pcrespov f2fa971
tokens tests
pcrespov 8a2be67
fixes
pcrespov 9036079
utils mixin
pcrespov 5a23555
asyncpg version of aggregation
pcrespov ce52ed5
cleanup
pcrespov b5a8a40
cleanup
pcrespov bd4458c
rm async
pcrespov 228c9f3
adds tests
pcrespov 142950e
mypy
pcrespov 2c81839
_common rename
pcrespov 2da7901
isolated tests
pcrespov 9a4ed7c
bad merge
pcrespov f5fe90d
mv api -> service
pcrespov 38bbedc
cleanup
pcrespov e64bdfc
bad import
pcrespov efa59d0
drop unnecesary dependencies
pcrespov 079b2de
cleanup
pcrespov 21ac861
renames
pcrespov 7326f20
error handling
pcrespov 80a2426
Merge branch 'is1779/refactor-users' of github.com:pcrespov/osparc-si…
pcrespov e8d4782
cleanup
pcrespov ef7e409
tests users pass
pcrespov 24ffb2a
fixes
pcrespov c857488
tools
pcrespov d198d56
models
pcrespov ed38767
model adapters
pcrespov dd0dcc5
utils testing
pcrespov 24d3711
rename
pcrespov dd95af0
fixes
pcrespov 7dcf156
updates OAS
pcrespov 93846e7
doc
pcrespov 78cf56e
udo Docker
pcrespov b7b1dd1
doc
pcrespov da56d35
@GitHK review: rename and doc
pcrespov 38d29f2
@sanderegg review: mv to dict_tools
pcrespov 58428b1
@sanderegg review: mv to dict_tools
pcrespov 1f4153a
@GitHK review: sentinel
pcrespov e62814b
mypy
pcrespov afecd8d
tests
pcrespov a0b47ec
Merge branch 'master' into is1779/refactor-users
pcrespov 1503da4
fixing test
pcrespov 5e993f7
fixing test
pcrespov 6f077d3
@sanderegg review: rename
pcrespov a9b48dc
@sanderegg review: await
pcrespov 50cd075
pylint
pcrespov dec6270
Merge branch 'master' into is1779/refactor-users
pcrespov ba14597
cleanup
pcrespov aee07f9
cleanup
pcrespov f00c127
renameing groups
pcrespov 057a032
undo function
pcrespov 5f093bb
annotated test
pcrespov 6c4f709
fixes
pcrespov 9e0a825
fixes front-end
pcrespov 2906201
minor
pcrespov 2371638
minor
pcrespov 2937250
Merge branch 'master' into is1779/refactor-users
pcrespov c745d26
minor
pcrespov 2151a15
update
pcrespov e853393
Merge branch 'master' into is1779/refactor-users
pcrespov c530f93
drop uuids from tokens
pcrespov 1319a38
OM front-end
pcrespov 53cc350
Merge branch 'master' into is1779/refactor-users
pcrespov 76cbf58
Merge branch 'is1779/refactor-users' of github.com:pcrespov/osparc-si…
pcrespov 4d4351f
mypy
pcrespov 56ea4f7
fixes tokens
pcrespov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| from enum import Enum | ||
| from functools import total_ordering | ||
|
|
||
| _USER_ROLE_TO_LEVEL = { | ||
| "ANONYMOUS": 0, | ||
| "GUEST": 10, | ||
| "USER": 20, | ||
| "TESTER": 30, | ||
| "PRODUCT_OWNER": 40, | ||
| "ADMIN": 100, | ||
| } | ||
|
|
||
|
|
||
| @total_ordering | ||
| class UserRole(Enum): | ||
| """SORTED enumeration of user roles | ||
|
|
||
| A role defines a set of privileges the user can perform | ||
| Roles are sorted from lower to highest privileges | ||
| USER is the role assigned by default A user with a higher/lower role is denoted super/infra user | ||
|
|
||
| ANONYMOUS : The user is not logged in | ||
| GUEST : Temporary user with very limited access. Main used for demos and for a limited amount of time | ||
| USER : Registered user. Basic permissions to use the platform [default] | ||
| TESTER : Upgraded user. First level of super-user with privileges to test the framework. | ||
| Can use everything but does not have an effect in other users or actual data | ||
| ADMIN : Framework admin. | ||
|
|
||
| See security_access.py | ||
| """ | ||
|
|
||
| ANONYMOUS = "ANONYMOUS" | ||
| GUEST = "GUEST" | ||
| USER = "USER" | ||
| TESTER = "TESTER" | ||
| PRODUCT_OWNER = "PRODUCT_OWNER" | ||
| ADMIN = "ADMIN" | ||
|
|
||
| @property | ||
| def privilege_level(self) -> int: | ||
| return _USER_ROLE_TO_LEVEL[self.name] | ||
|
|
||
| def __lt__(self, other: "UserRole") -> bool: | ||
| if self.__class__ is other.__class__: | ||
| return self.privilege_level < other.privilege_level | ||
| return NotImplemented | ||
|
|
||
|
|
||
| class UserStatus(str, Enum): | ||
| # This is a transition state. The user is registered but not confirmed. NOTE that state is optional depending on LOGIN_REGISTRATION_CONFIRMATION_REQUIRED | ||
| CONFIRMATION_PENDING = "CONFIRMATION_PENDING" | ||
| # This user can now operate the platform | ||
| ACTIVE = "ACTIVE" | ||
| # This user is inactive because it expired after a trial period | ||
| EXPIRED = "EXPIRED" | ||
| # This user is inactive because he has been a bad boy | ||
| BANNED = "BANNED" | ||
| # This user is inactive because it was marked for deletion | ||
| DELETED = "DELETED" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # pylint: disable=no-value-for-parameter | ||
| # pylint: disable=redefined-outer-name | ||
| # pylint: disable=unused-argument | ||
| # pylint: disable=unused-variable | ||
|
|
||
|
|
||
| from common_library.users_enums import _USER_ROLE_TO_LEVEL, UserRole | ||
|
|
||
|
|
||
| def test_user_role_to_level_map_in_sync(): | ||
| # If fails, then update _USER_ROLE_TO_LEVEL map | ||
| assert set(_USER_ROLE_TO_LEVEL.keys()) == set(UserRole.__members__.keys()) | ||
|
|
||
|
|
||
| def test_user_roles_compares_to_admin(): | ||
| assert UserRole.ANONYMOUS < UserRole.ADMIN | ||
| assert UserRole.GUEST < UserRole.ADMIN | ||
| assert UserRole.USER < UserRole.ADMIN | ||
| assert UserRole.TESTER < UserRole.ADMIN | ||
| assert UserRole.PRODUCT_OWNER < UserRole.ADMIN | ||
| assert UserRole.ADMIN == UserRole.ADMIN | ||
|
|
||
|
|
||
| def test_user_roles_compares_to_product_owner(): | ||
| assert UserRole.ANONYMOUS < UserRole.PRODUCT_OWNER | ||
| assert UserRole.GUEST < UserRole.PRODUCT_OWNER | ||
| assert UserRole.USER < UserRole.PRODUCT_OWNER | ||
| assert UserRole.TESTER < UserRole.PRODUCT_OWNER | ||
| assert UserRole.PRODUCT_OWNER == UserRole.PRODUCT_OWNER | ||
| assert UserRole.ADMIN > UserRole.PRODUCT_OWNER | ||
|
|
||
|
|
||
| def test_user_roles_compares_to_tester(): | ||
| assert UserRole.ANONYMOUS < UserRole.TESTER | ||
| assert UserRole.GUEST < UserRole.TESTER | ||
| assert UserRole.USER < UserRole.TESTER | ||
| assert UserRole.TESTER == UserRole.TESTER | ||
| assert UserRole.PRODUCT_OWNER > UserRole.TESTER | ||
| assert UserRole.ADMIN > UserRole.TESTER | ||
|
|
||
|
|
||
| def test_user_roles_compares_to_user(): | ||
| assert UserRole.ANONYMOUS < UserRole.USER | ||
| assert UserRole.GUEST < UserRole.USER | ||
| assert UserRole.USER == UserRole.USER | ||
| assert UserRole.TESTER > UserRole.USER | ||
| assert UserRole.PRODUCT_OWNER > UserRole.USER | ||
| assert UserRole.ADMIN > UserRole.USER | ||
|
|
||
|
|
||
| def test_user_roles_compares_to_guest(): | ||
| assert UserRole.ANONYMOUS < UserRole.GUEST | ||
| assert UserRole.GUEST == UserRole.GUEST | ||
| assert UserRole.USER > UserRole.GUEST | ||
| assert UserRole.TESTER > UserRole.GUEST | ||
| assert UserRole.PRODUCT_OWNER > UserRole.GUEST | ||
| assert UserRole.ADMIN > UserRole.GUEST | ||
|
|
||
|
|
||
| def test_user_roles_compares_to_anonymous(): | ||
| assert UserRole.ANONYMOUS == UserRole.ANONYMOUS | ||
| assert UserRole.GUEST > UserRole.ANONYMOUS | ||
| assert UserRole.USER > UserRole.ANONYMOUS | ||
| assert UserRole.TESTER > UserRole.ANONYMOUS | ||
| assert UserRole.PRODUCT_OWNER > UserRole.ANONYMOUS | ||
| assert UserRole.ADMIN > UserRole.ANONYMOUS | ||
|
|
||
|
|
||
| def test_user_roles_compares(): | ||
| # < and > | ||
| assert UserRole.TESTER < UserRole.ADMIN | ||
| assert UserRole.ADMIN > UserRole.TESTER | ||
|
|
||
| # >=, == and <= | ||
| assert UserRole.TESTER <= UserRole.ADMIN | ||
| assert UserRole.ADMIN >= UserRole.TESTER | ||
|
|
||
| assert UserRole.ADMIN <= UserRole.ADMIN | ||
| assert UserRole.ADMIN == UserRole.ADMIN |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.