Skip to content

fix(avatars): expose photo update and delete in the console SDK - #14055

Merged
Meldiron merged 2 commits into
mainfrom
fix-photo-sdk-console-platform
Oct 1, 2026
Merged

Meldiron merged 2 commits into
mainfrom
fix-photo-sdk-console-platform

Conversation

@Meldiron

@Meldiron Meldiron commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

avatars.updatePhoto (PUT /v1/avatars/photo) and avatars.deletePhoto (DELETE /v1/avatars/photo) declare auth: [AuthType::SESSION, AuthType::JWT]. The specs task derives each route's SDK platforms from its auth types (AuthType::getPlatform(): SESSION → client, JWT/KEY → server, ADMIN → console), so both routes are generated for the client SDK only. The console SDK (@appwrite.io/console) gets getPhoto but neither write route, which blocks the Console from offering a profile photo upload on the account page.

This adds AuthType::ADMIN to both routes, matching how the other "current user" session routes are declared (account.get, account.updateName: [ADMIN, SESSION, JWT]). No KEY: an API key has no current user.

Metadata only. Handlers, avatars.write scope, events, audits, and abuse limits are untouched. avatars.write is already in the console $member and $admins scope lists in app/config/roles.php, so console sessions could call these routes before; they just had no generated method.

It also adds e2e coverage for the console flow, which previously existed only for a custom project session (AvatarsCustomClientTest) and for API keys (AvatarsCustomServerTest, 401).

Test Plan

  • New in AvatarsConsoleClientTest (console project, console user session), mirroring the custom-project tests:
    • testUpdatePhotoWithConsoleSession: upload with the console session, then the photo is served for the session user, for userId=current(), and for the user's ID from another console user's session (how organization member lists render); the other user's own avatar stays on initials.
    • testDeletePhotoWithConsoleSession: 204, falls back to initials, deleting again is a no-op.
    • testUpdatePhotoUnauthorized: PUT/DELETE without a session on the console project → 401.
    • The photo helpers (createPhotoUser, createImage, createNoiseImage, uploadPhoto, getPhoto, assertSamePhoto) moved from AvatarsCustomClientTest into the shared AvatarsBase trait; the custom-project tests are unchanged in behavior.
  • vendor/bin/pint --test and vendor/bin/phpstan analyse (level 4) on the changed route and test files: pass.
  • vendor/bin/phpunit tests/unit/SDK: 28 pass; the 15 errors are Class "Swoole\Http\Response" not found on a machine without the Swoole extension and are identical on main.
  • I could not run the e2e suite locally (no Docker on this machine); relying on the CI Avatars job.
  • Confirmed the gap on a Cloud SDK preview built from a server-ce ref that already includes feat: custom user avatar upload and delete #13949: the console preview's types/services/avatars.d.ts and dist/esm/sdk.js contain only getPhoto, while the client preview from the same build has getPhoto, updatePhoto, deletePhoto. After merge, the next @appwrite.io/console build should declare updatePhoto(params: { file, onProgress? }) and deletePhoto(); I'll verify on the Cloud preview and pin it in the Console.

Related PRs and Issues

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? (Specs stopped being tracked in git in 8d82bc8; SDK examples are produced by the SDK generation pipeline, so there is nothing to commit here.)

🤖 Generated with Claude Code

`updatePhoto` and `deletePhoto` declared `auth: [SESSION, JWT]`, and the
specs task derives SDK platforms from the auth types (SESSION -> client,
JWT/KEY -> server, ADMIN -> console), so both routes were generated for
the client SDK only. The console needs them for the account profile
photo, the same way the account routes (`account.get`, `updateName`)
declare ADMIN alongside SESSION and JWT.

Add `AuthType::ADMIN` to both routes. No behavior change: the scope,
abuse limits, and handlers are untouched; only the SDK/spec metadata
gains the console platform.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@ghost

ghost commented Oct 1, 2026 •

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

The existing minor finding remains unresolved: the new HTTP tests do not assert inclusion of either method in the generated console spec.

Adds ADMIN authentication metadata to the profile-photo update and delete routes so both methods are included in console SDK generation, without changing their handlers or runtime scopes. Adds console-session e2e coverage for uploading, resolving, and deleting photos, plus unauthenticated rejection, and shares photo-test helpers with the custom-client suite.

Latest changes: The newest commits move photo helpers into AvatarsBase and add console-session upload, retrieval, deletion, and unauthorized-request tests.

Verdict New comments Fixed Still open
✅ Approved 0 0 1
Fix with agent prompt
### Issue 1
src/Appwrite/Platform/Modules/Avatars/Http/Photo/Update.php:76
**Add regression coverage for console SDK method inclusion**

Neither changed route has a regression test asserting its inclusion in the console spec; the existing Avatars console suite exercises GET, and the write test only checks API-key rejection. Please add an automated generated-spec assertion for both `updatePhoto` and `deletePhoto`, covering the SDK-visible contract required by AGENTS.md so this omission cannot silently return.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
📂 Walkthrough · 5
File Change
src/Appwrite/Platform/Modules/Avatars/Http/Photo/Delete.php Adds ADMIN to deletePhoto SDK authentication metadata.
src/Appwrite/Platform/Modules/Avatars/Http/Photo/Update.php Adds ADMIN to updatePhoto SDK authentication metadata.
tests/e2e/Services/Avatars/AvatarsBase.php Hosts shared user, image, upload, retrieval, and photo-comparison helpers.
tests/e2e/Services/Avatars/AvatarsConsoleClientTest.php Tests console-session photo writes, user resolution, deletion fallback, and unauthenticated rejection.
tests/e2e/Services/Avatars/AvatarsCustomClientTest.php Uses shared trait helpers instead of local duplicates.
⏳ Still open from earlier reviews · 1

Reviewed the commits since 353486e · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost 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 · Looks good to merge. Summary

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-photo-sdk-console-platform (after).

Metric Before After Change
🚀 Requests/sec 208.79 214.58 ⚪ +2.8%
⏱️ Latency P50 82.24 ms 81.68 ms ⚪ -0.7%
⏱️ Latency P95 191.74 ms 186.02 ms ⚪ -3%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 81.68 186.02 13,680 214.58 -5.72
Account 153.8 279.55 720 12 -93.22
TablesDB 79.93 148.11 7,440 118.62 -10.11
Storage 72.35 156.4 3,600 59.35 -5.08
Functions 118.25 218.77 1,920 32.25 -12.61

Top API waits (after)

API request Max wait (ms)
tablesdb.rows.delete 416.54
account.prefs.update 399.75
account.name.update 392.3
functions.create 344.48
tablesdb.rows.create 344.14

The write routes were only exercised with a custom project session and
an API key. Add console-project coverage so the Console's own flow is
tested: a console user uploads and deletes their photo with their
console session, `current()` and a lookup by user ID from another
console user's session both serve the uploaded photo (how organization
member lists render), and a request without a session is refused.

Move the photo helpers (`createPhotoUser`, `createImage`,
`createNoiseImage`, `uploadPhoto`, `getPhoto`, `assertSamePhoto`) from
`AvatarsCustomClientTest` into the shared `AvatarsBase` trait so both
client scopes use the same code.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@Meldiron
Meldiron merged commit 79a77fd into main Oct 1, 2026
51 checks passed
imtia33 pushed a commit to imtia33/appwrite that referenced this pull request Oct 8, 2026
… deletePhoto

Cloud SDK preview built from appwrite-labs/cloud feat-assistant2-0@2e5b73d,
whose server-ce includes appwrite#14055. bun.lock regenerated with
bun 1.4 (CI's version). lint:sdk-pins fails on pkg.vc pins by design; swap
in the published release before merging.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
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