Skip to content

## What does this PR do? #15895

Open
Open

Description

@heyrapto

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.

Originally posted by @heyrapto in #15736

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions