Skip to content

feat(account): add queries to session list endpoints - #15736

Open
heyrapto wants to merge 2 commits into
appwrite:mainfrom
heyrapto:feat/sessions-queries
Open

heyrapto wants to merge 2 commits into
appwrite:mainfrom
heyrapto:feat/sessions-queries

Conversation

@heyrapto

Copy link
Copy Markdown

What does this PR do?

Adds the standard Query API (queries) to both session list endpoints:

  • GET /v1/account/sessions
  • GET /v1/users/{userId}/sessions

Both endpoints now use a new Appwrite\Utopia\Database\Validator\Queries\Sessions validator (mirroring the existing Identities and Passkeys validators). They read from the sessions collection, filtered by userInternalId (index _key_user), instead of the embedded subQuerySessions attribute.

Callers can now filter, order, limit, offset, and cursor-paginate sessions on:

$id, $createdAt, $updatedAt, ip, countryCode, continentCode, provider, userAgent, osName, osCode, osVersion, clientType, clientName, clientCode, deviceName, deviceBrand, deviceModel, deviceId, expire, factors

Behavior notes

  • total now comes from count() over the same filters instead of count($sessions), so it reflects the whole result set rather than the current page.
  • Expired sessions are excluded by default (expire >= now). A caller that filters on expire owns the time window and can read expired sessions.
  • Default limit: when no limit is supplied, APP_LIMIT_SUBQUERY (1000) is applied, preserving the previous subquery cap for callers that do not paginate.
  • Cursors are resolved against the sessions collection and must belong to the target user; otherwise general_cursor_not_found is returned.
  • Response enrichment is unchanged: current, countryName, userName, and the existing sensitive/credential handling.
  • SDK compatibility: queries is declared after total so released positional SDK calls keep working. app/config/sdks/parameters.lock.json is updated for client, console, and server.

Test Plan

Added

  • tests/unit/Utopia/Database/Validator/Queries/SessionsTest.php: allowed and disallowed attributes for the new validator.
  • testListAccountSessionsQueries in tests/e2e/Services/Account/AccountCustomClientTest.php.
  • testListUserSessionsQueries in tests/e2e/Services/Users/UsersBase.php.

Both e2e tests cover:

  • Success: default list, filter, order/limit/offset, cursor, expire windows, total=false
  • Failure: unauthenticated, disallowed attribute, unknown cursor, cursor owned by another user

Run

docker compose exec appwrite test tests/unit/Utopia/Database/Validator/Queries/SessionsTest.php
docker compose exec appwrite test tests/e2e/Services/Account --filter=testListAccountSessionsQueries
docker compose exec appwrite test tests/e2e/Services/Users --filter=testListUserSessionsQueries

Note: these were not run in the authoring environment (no PHP runtime or Docker daemon available). The Account and Users CI lanes already cover the touched module paths in .github/ci/e2e.json.

Related PRs and Issues

  • Issue:
  • GET /v1/account/mfa/factors is out of scope and will be handled in a separate PR.

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?
    • app/config/sdks/parameters.lock.json is updated; generated SDK specs and docs are produced by the release process.

Add a queries parameter to GET /v1/account/sessions and
GET /v1/users/{userId}/sessions, validated by a Sessions query
validator over the sessions collection.

Sessions are now read from the sessions collection filtered by
userInternalId, with count-based totals and cursor validation scoped
to the target user. Expired sessions are excluded unless the caller
filters on expire, and the 1000-row default limit matches the old
subquery behavior when no limit is supplied.
@appwrite

appwrite Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The new fixture makes the expired-session behavior observable in both endpoint tests, and I found no issue in the incremental changes.

Adds the standard queries API to account and user session-list endpoints, using the sessions collection for filtering, ordering, pagination, cursor ownership checks, expiry handling, and filtered totals. The PR also adds a sessions query validator, updates SDK parameter locks, and adds unit and e2e coverage, including a helper that creates expired-session fixtures.

Latest changes: The latest commits add an ExpireSession e2e trait and use it in both endpoint tests to verify default exclusion of expired sessions and their visibility through an explicit expiry query.

Verdict New comments Fixed Still open
💬 Commented 0 1 0

Note

@heyrapto does not have write access to this repository, so Hansi does not approve automatically. A maintainer can review and approve.

📂 Walkthrough · 8
File Change
app/config/sdks/parameters.lock.json Adds the queries parameter to the account and user session-list SDK locks.
src/Appwrite/Platform/Modules/Account/Http/Account/Sessions/XList.php Lists account sessions using query filters, pagination, cursor ownership validation, expiry handling, and filtered totals.
src/Appwrite/Platform/Modules/Users/Http/Users/Sessions/XList.php Adds equivalent query-based listing behavior for a specified user's sessions.
src/Appwrite/Utopia/Database/Validator/Queries/Sessions.php Defines the session attributes accepted by list queries.
tests/e2e/Services/Account/AccountCustomClientTest.php Covers account session listing queries and expired-session visibility.
tests/e2e/Services/Users/UsersBase.php Covers user session listing queries and expired-session visibility.
tests/e2e/Traits/ExpireSession.php Adds a test helper to move a session's expiry into the past.
tests/unit/Utopia/Database/Validator/Queries/SessionsTest.php Tests allowed and disallowed attributes for the sessions query validator.
✅ Fixed since the last review · 1
  • Exercise expired-session visibility in the e2e tests · src/Appwrite/Platform/Modules/Account/Http/Account/Sessions/XList.php:118

Reviewed the commits since 715684a · Details · Comment @appwrite review to re-run, or mention @appwrite with a question.

@appwrite appwrite Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · See the inline comments. Summary

@appwrite appwrite Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

This branch has not been deployed

No deployments
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.

1 participant