Repository navigation
Description
What does this PR do?
Adds the standard Query API (queries) to both session list endpoints:
GET /v1/account/sessionsGET /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
totalnow comes fromcount()over the same filters instead ofcount($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 onexpireowns the time window and can read expired sessions. - Default limit: when no
limitis supplied,APP_LIMIT_SUBQUERY(1000) is applied, preserving the previous subquery cap for callers that do not paginate. - Cursors are resolved against the
sessionscollection and must belong to the target user; otherwisegeneral_cursor_not_foundis returned. - Response enrichment is unchanged:
current,countryName,userName, and the existing sensitive/credential handling. - SDK compatibility:
queriesis declared aftertotalso released positional SDK calls keep working.app/config/sdks/parameters.lock.jsonis updated forclient,console, andserver.
Test Plan
Added
tests/unit/Utopia/Database/Validator/Queries/SessionsTest.php: allowed and disallowed attributes for the new validator.testListAccountSessionsQueriesintests/e2e/Services/Account/AccountCustomClientTest.php.testListUserSessionsQueriesintests/e2e/Services/Users/UsersBase.php.
Both e2e tests cover:
- Success: default list, filter, order/limit/offset, cursor,
expirewindows,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=testListUserSessionsQueriesNote: 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/factorsis 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.jsonis updated; generated SDK specs and docs are produced by the release process.
Activity