Skip to content

fix(projects): grant site screenshots to the team a project moves to - #15157

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix/screenshots-follow-project-team
Nov 1, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix/screenshots-follow-project-team

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Problem

After PATCH /v1/projects/:projectId/team, the new team gets 404 on every site deployment screenshot (GET /v1/storage/buckets/screenshots/files/<id>/preview?project=console).

Root cause

The screenshots worker stores each capture in the console screenshots bucket with read("team:<teamId at capture time>"). The team update re-grants the project, installations, repositories and VCS comments, but not these files.

Fix

After the move, read every site deployment's screenshotLight/screenshotDark from the project database and bulk-update those files to read("team:<new>"), in chunks of APP_DATABASE_QUERY_MAX_VALUES. Safe to repeat.

The screenshots worker also reads the project's team when it files a capture, instead of the copy carried on the queued message, so a capture finishing after the move does not go to the old team.

Test

SitesConsoleClientTest::testSiteScreenshotsMoveWithProjectTeam (group screenshots): deploy a static site, wait for both screenshots, move the project to a new team, assert both files carry read("team:<new>"). Without the fix they keep the old team.

Related: appwrite-labs/cloud#6673

Screenshots are files in the console screenshots bucket readable only by the team that owned the project when they were captured. Moving a project re-granted the project and its VCS records but not these files, so the new team could no longer preview any deployment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@luxor-code-review

luxor-code-review Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

  • 🟡 Screenshot batch can exceed APP_DATABASE_QUERY_MAX_VALUES — Update.php:156

This PR grants screenshot file permissions to the destination team when a project's team is transferred, by scanning the project's site deployments and bulk-updating permissions on the screenshots bucket files.

Files Change
src/Appwrite/Platform/Modules/Projects/Http/Projects/Team/Update.php Adds grantScreenshots(): validates the team, looks up the screenshots bucket, iterates deployments with a cursor, and batches permission updates on bucket_<sequence> for the new team.
tests/e2e/Services/Sites/SitesConsoleClientTest.php Adds a console e2e test asserting screenshot files are readable by the new team after transfer.

Reviewed commit: a5e27f3

@ghost

ghost commented Nov 1, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The latest worker change addresses the previously reported in-flight capture case, and I found no remaining issues in the incremental changes.

Project team transfers now grant the destination team read access to existing site deployment screenshots in bounded batches. Screenshot captures also use the project’s current team when creating files, and an E2E test verifies screenshot permissions after a transfer.

Latest changes: The new worker change reloads the project’s current team after screenshot capture so captures queued before a transfer create files with the updated team’s permission.

Verdict New comments Fixed Still open
✅ Approved 0 1 0
📂 Walkthrough · 3
File Change
src/Appwrite/Platform/Modules/Projects/Http/Projects/Team/Update.php Grant the destination team read access to existing site deployment screenshot files in bounded batches.
src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php Fetch the current project team before creating captured screenshot files.
tests/e2e/Services/Sites/SitesConsoleClientTest.php Verify both site screenshot files have destination-team permissions after a project transfer.
✅ Fixed since the last review · 1
  • In-flight captures can retain the previous team permission · src/Appwrite/Platform/Modules/Projects/Http/Projects/Team/Update.php:145

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

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@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 · See the inline comments. Summary

@luxor-code-review luxor-code-review 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.

Adds a grantScreenshots step to the project team-transfer endpoint so the incoming team gains read access to site screenshot files, covered by a console e2e test.

Key findings

  • 🟡 Screenshot batch can exceed APP_DATABASE_QUERY_MAX_VALUES — Update.php:156

Comment on lines +156 to +159
if (\count($ids) >= APP_DATABASE_QUERY_MAX_VALUES) {
$dbForPlatform->updateDocuments('bucket_' . $bucket->getSequence(), $updates, [Query::equal('$id', $ids)]);
$ids = [];
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 bug · medium

Screenshot batch can exceed APP_DATABASE_QUERY_MAX_VALUES

In grantScreenshots, up to two IDs (screenshotLight, screenshotDark) are appended per deployment before the \count($ids) >= APP_DATABASE_QUERY_MAX_VALUES flush check runs (src/Appwrite/Platform/Modules/Projects/Http/Projects/Team/Update.php:156). A batch can reach 501 values against the 500-value cap, making Query::equal('$id', $ids) invalid. The team transfer then fails with a 500 after the project was already moved, leaving screenshots un-granted.

📋 Prompt for AI Agents

In src/Appwrite/Platform/Modules/Projects/Http/Projects/Team/Update.php, in grantScreenshots (around lines 144-164), restructure the batching so a flush happens whenever the pending ID count would exceed APP_DATABASE_QUERY_MAX_VALUES (500): collect the deployment's screenshotLight/screenshotDark IDs first, and if count($ids) plus the new IDs would exceed the limit, flush the current batch via $dbForPlatform->updateDocuments('bucket_' . $bucket->getSequence(), $updates, [Query::equal('$id', $ids)]) and reset $ids before appending, so Query::equal never receives more than 500 values.

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/screenshots-follow-project-team (after).

Metric Before After Change
🚀 Requests/sec 182.44 188.91 ⚪ +3.5%
⏱️ Latency P50 92.37 ms 90.93 ms ⚪ -1.6%
⏱️ Latency P95 223.63 ms 214.72 ms ⚪ -4%
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 90.93 214.72 11,856 188.91 -8.9
Account 172.92 332.51 624 10.32 -56.49
TablesDB 87.94 168.9 6,448 104.97 -8.46
Storage 81.77 196.26 3,120 52.77 -3.72
Functions 127.3 253.16 1,664 28.93 -25.29

Top API waits (after)

API request Max wait (ms)
functions.create 474.06
account.name.update 473.08
functions.variables.update 472.06
account.prefs.update 408.08
storage.buckets.create 397.68

The capture message carries the project as it was when the build queued it, so a capture that ran after a team change granted its files to the previous team.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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

@ChiragAgg5k
ChiragAgg5k merged commit 25dbe2a into main Nov 1, 2026
40 checks passed
@ChiragAgg5k ChiragAgg5k self-assigned this Nov 2, 2026
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