-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Update users endpoint with subquery filtering #10306
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
base: 1.7.x
Are you sure you want to change the base?
Update users endpoint with subquery filtering #10306
Conversation
…users Co-authored-by: jakeb994 <jakeb994@gmail.com>
Cursor Agent can help with this pull request. Just |
Security Scan Results for PRDocker Image Scan Results
Source Code Scan Results🎉 No vulnerabilities found! |
app/controllers/api/users.php
Outdated
// Define attributes that have subQueryX filters | ||
$subQueryAttributes = [ | ||
'authenticators' => 'subQueryAuthenticators', | ||
'sessions' => 'subQuerySessions', | ||
'tokens' => 'subQueryTokens', | ||
'challenges' => 'subQueryChallenges', | ||
'memberships' => 'subQueryMemberships', | ||
'targets' => 'subQueryTargets' | ||
]; |
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.
@cursor Don't hardcore these, pull from the collection config with Cofig::getParam and filter the ones that have subqueries
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.
app/controllers/api/users.php
Outdated
]; | ||
|
||
// Process select queries and identify subQueryX attributes | ||
$skipFilters = ['subQueryAuthenticators', 'subQuerySessions', 'subQueryTokens', 'subQueryChallenges', 'subQueryMemberships', 'subQueryTargets']; |
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.
@cursor Don't skip subQueryTargets
if targets
is in the select query. Based on the attribute from the config.
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.
I refined the GET /v1/users
endpoint to correctly process subQueryX
attributes when explicitly selected. This ensures that if a subquery attribute is requested via a select
query, its corresponding filter is no longer skipped, allowing the subquery data to be included in the response.
- I modified the
App::get('/v1/users')
route handler inapp/controllers/api/users.php
to adjust howskipFilters
are managed. - I changed the logic so that
skipFilters
initially contains allsubQueryAttributes
values, meaning all subQuery filters are skipped by default. - I introduced
requestedSubQueryAttributes
to track specificsubQueryX
attributes that are explicitly requested in aselect
query. - I updated the final
skipFilters
calculation usingarray_diff($skipFilters, $requestedSubQueryAttributes)
. This removes any requested subQuery filters from theskipFilters
list, ensuring their data is fetched.
Learn more about Cursor Agents
Co-authored-by: jakeb994 <jakeb994@gmail.com>
Co-authored-by: jakeb994 <jakeb994@gmail.com>
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
✨ Benchmark results
⚡ Benchmark Comparison
|
Co-authored-by: jakeb994 <jakeb994@gmail.com>
Co-authored-by: jakeb994 <jakeb994@gmail.com>
Co-authored-by: jakeb994 <jakeb994@gmail.com>
…c implementation Co-authored-by: jakeb994 <jakeb994@gmail.com>
Co-authored-by: jakeb994 <jakeb994@gmail.com>
Co-authored-by: jakeb994 <jakeb994@gmail.com>
…fied Co-authored-by: jakeb994 <jakeb994@gmail.com>
Co-authored-by: jakeb994 <jakeb994@gmail.com>
What does this PR do?
This PR enables the use of
Query::select
for the users list endpoint (/v1/users
), allowing users to specify which attributes they want to retrieve.It introduces a new
Select
validator tosrc/Appwrite/Utopia/Database/Validator/Queries/Base.php
to validateselect
queries. Additionally, it adds logic toapp/controllers/api/users.php
to specifically handle attributes that correspond tosubQueryX
filters (e.g.,sessions
,tokens
). If such an attribute is requested viaselect
, it is removed from theselect
query and its correspondingsubQueryX
filter (e.g.,subQuerySessions
) is added to theskipFilters
array. This ensures that complex related data is handled correctly by the database layer, preventing errors and maintaining performance, while still allowing users to specify their desired data.Test Plan
Query::select
with regular attributes:/v1/users
withqueries[] = Query::select(['$id', 'name', 'email'])
.$id
,name
, andemail
attributes for each user.Query::select
withsubQueryX
attributes:/v1/users
withqueries[] = Query::select(['$id', 'name', 'sessions', 'tokens'])
.$id
andname
.sessions
andtokens
are not directly present in the user document, but the underlyingsubQuerySessions
andsubQueryTokens
filters were correctly applied (meaning the related data would be available if not explicitly skipped by other means).Query::select
with mixed attributes:/v1/users
withqueries[] = Query::select(['name', 'email', 'memberships'])
.name
andemail
are returned, andmemberships
is handled viaskipFilters
.Query::select
with onlysubQueryX
attributes:/v1/users
withqueries[] = Query::select(['sessions', 'challenges'])
.select
query is passed to the database (i.e., all attributes are returned as if noselect
was applied, butsubQuerySessions
andsubQueryChallenges
are inskipFilters
).select
attributes:/v1/users
withqueries[] = Query::select(['nonExistentAttribute'])
.Related PRs and Issues
Checklist