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
[WIP] Speed up assets and accounts pages #988
Open
victorgarcia98
wants to merge
25
commits into
main
Choose a base branch
from
feature/crud/get-from-index-endpoint
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
0a1b890
Testing doing 1 single request instead of one request per account. Th…
victorgarcia98 70c5ff8
Merge branch 'main' into feature/crud/get-from-index-endpoint
victorgarcia98 7f43acf
check permissions
victorgarcia98 ecd4f91
Merge branch 'main' into feature/crud/get-from-index-endpoint
victorgarcia98 2acfb7f
Merge remote-tracking branch 'origin/feature/crud/get-from-index-endp…
victorgarcia98 31a5803
Merge remote-tracking branch 'origin/main' into feature/crud/get-from…
Flix6x 3d3bece
Merge remote-tracking branch 'origin/main' into feature/crud/get-from…
Flix6x 4ab2eea
Merge remote-tracking branch 'origin/main' into feature/crud/get-from…
Flix6x fa54b6c
fix: harmless, but redundant plus
Flix6x 6c84bd3
fix: no dumb children
Flix6x 88086a6
feature: create Asset objects faster by selecting from db, while stil…
Flix6x 021bd79
style: black
Flix6x 67a0d60
Merge branch 'main' into feature/crud/get-from-index-endpoint
victorgarcia98 38f0f11
Merge remote-tracking branch 'origin' into feature/crud/get-from-inde…
victorgarcia98 096921a
add public assets to the call and fix tests
victorgarcia98 02ac27e
add future
victorgarcia98 fc00b72
Merge branch 'main' into feature/crud/get-from-index-endpoint
victorgarcia98 f1f5ac0
add `all_accessible` to get all the accessible assets by a certain ac…
victorgarcia98 7fcb4a5
Merge remote-tracking branch 'origin/feature/crud/get-from-index-endp…
victorgarcia98 eec4ad4
Improve docstring.
victorgarcia98 a99e5cb
Merge branch 'main' into feature/crud/get-from-index-endpoint
victorgarcia98 e98dc72
raise if the account is provided and all_accessible=True
victorgarcia98 5b9a2b3
Merge remote-tracking branch 'origin/feature/crud/get-from-index-endp…
victorgarcia98 012983d
Merge branch 'main' into feature/crud/get-from-index-endpoint
victorgarcia98 edeb490
Merge branch 'main' into feature/crud/get-from-index-endpoint
victorgarcia98 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Owned or accessible? I think by now this index endpoint morphed into the latter. In which case, should we include the public assets? Unless an account is passed, of course.
The docstring would need a rewrite, too.
Technically, it's also a breaking change in the API. We could maintain backwards compatibility if we add a new optional field that signals the caller wants to get all accessible accounts instead of the assets their own account owns. Or a new endpoint, but I don't favour that option, because it's still an asset index endpoint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, good point. I've included the parameter
all_accessible
(default=False).This parameter signals if we want to get all the assets that the requesting user has read permissions or, by default, the ones that it owns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What might nicely round this up would be to revise
check_access
to accept anas_account
argument that defaults to the current user, in combination with putting back the permissions decorator.So then we'd have the following four cases:
account
is passed, andall_accessible=false
: caller wants to list their own assetsaccount
is passed, andall_accessible=true
: caller wants to list all assets that they can accessaccount
is passed, andall_accessible=false
: caller wants to list some other account's assetsaccount
is passed, andall_accessible=true
: caller wants to list all assets that some other account can access. Caller requires read access on the passed account (checked using the decorator) and the passed account requires read access on the assets (to be checked using the revisedcheck_access
I suggested above).One open point would be whether we should implicitly assume that, if the caller has access to
account
, it also has access to all accounts thataccount
has access to. That is, we assume consultant permissions propagate.Alternatively, we could call
check_access
on the assets for both the caller and theaccount
(in case they are not the same). That is, we do not assume consultant permissions propagate.Propagation has my preference. Whichever the case, we also might want to mention the choice of policy explicitly in the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An unlikely case but possible is the user to have
consultancy
role but noread
role. Thus, I think we can't really bringpermission_required_for_context
back. Perhaps, iflen(accounts) == 0
, we should raiseForbidden
orUnauthorized
.Regarding the changes to the
check_access
, to my (superficial) understanding, they are already covered by the authorization policy:Given that account is not passed, the marshmallow field will default to
AccountIdField.load_current
andcheck_access
will make sure that the current user has read permissions for the account.In this scenario, the user could or couldn't have
read
access to his/her own account. Yet, it could have aconsultant
role and have access over the accounts that have theconsultant_account_id
set to the user's account.check_access
make sure that the requesting user hasread
permissions to its own account.Here probably we should raise if the current user has no
read
permissions for its own account even if it has consultant role.This is an interesting point, indeed. I think we should open a new issue for this and handle that on the Account
__acl__
method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this touches auth policies I want to make sure we get @nhoening 's opinion, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting solution!
/public
endpoint (as we can return public endpoints here), but if one * only* wants public assets, that would require loading a potentially long list and parsing the result. Or we add another parameteronly_public
.check_access
where it is right now)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the case that a user has consultant roles but no doesn't have the
read
. This means that it can read their client's account but not his/her.I agree, currently we don't need to check what a user belonging to a different account can list. Also, If we were to implement this, it gets more complex because the user roles + account roles + consultancy relationship determine if a user can read an asset.