Repository navigation
fix(teams): allow 81-character roles on team create - #13944
Conversation
createTeam validated roles with a bare Key(), capping them at 36 chars while createMembership and updateMembership already allow 81, so a role accepted on a membership was rejected on the team that owns it. The param description also claimed 32.
🔵 Tier A · Mergeable after minor fixes
Team creation now accepts roles up to 81 characters, matching membership creation and updates. The pull request also updates the API descriptions and adds a team-creation E2E case that checks the creator’s persisted role. Latest changes: The newest commits centralize the 81-character limit in a shared constant and change the E2E case from an 81-character string to a project-shaped role checked through the memberships API.
📂 Walkthrough · 5
Reviewed the commits since |
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Team create and both membership actions each spelled the role limit as a bare 81, repeated it in their parameter descriptions, and carried the same comment explaining where it comes from. Define it once as APP_LIMIT_ROLE_LENGTH and use it in all three, so the validators and the documented limit cannot drift apart. The rendered descriptions are unchanged. The create-team test now sends a project-scoped role longer than a bare ID, rather than a string built to the limit, and reads the creator's membership back to confirm the role was saved.
| $this->assertEquals(true, $dateValidator->isValid($response3['body']['$createdAt'])); | ||
|
|
||
| // A project-scoped role is longer than a bare ID | ||
| $role = 'project-' . ID::unique() . '-developer'; |
There was a problem hiding this comment.
Keep the E2E role at the 81-character boundary
Replacing the 81-character string with an ID::unique()-based role no longer exercises the advertised limit. The test would still pass if the validator were lowered to a value between this shorter role’s length and 81, so please construct a project-shaped role of exactly 81 characters.
| $role = 'project-' . ID::unique() . '-developer'; | |
| $role = 'project-' . str_repeat('a', 36) . '-' . str_repeat('b', 36); |
🟡 Minor · testing · Reply if this doesn't apply.
There was a problem hiding this comment.
IS THIS an established pattren?
There was a problem hiding this comment.
Not as a Teams-specific pattern, no. I should have framed the suggestion as boundary coverage, not an established convention. There is a similar max-length E2E test using str_repeat() in tests/e2e/Services/Project/LabelsBase.php:119-126.
Your current test already catches the original create-team bug by sending a role longer than 36 characters (tests/e2e/Services/Teams/TeamsBase.php:169-180). My suggestion would additionally catch a future change that accepts that shorter role but rejects the documented 81-character maximum (src/Appwrite/Platform/Modules/Teams/Http/Teams/Create.php:65). It’s a useful improvement, not a claim that your regression test is invalid.
What does this PR do?
createTeamvalidatedroleswith a barenew Key(), which defaultsmaxLengthtoDatabase::MAX_UID_DEFAULT_LENGTH(36), while its description claimed 32. So the documented limit was wrong either way, and a role thatcreateMembershipandupdateMembershipaccept was rejected atcreateTeam.Those two actions already allowed 81 characters: a project-scoped role,
project-<projectId>-<role>, is 9 template characters around two 36-character IDs. But each spelled it as a bare81, repeated81in its parameter description, and carried the same comment explaining the arithmetic.This names the limit once as
APP_LIMIT_ROLE_LENGTHinapp/init/constants.php, beside the otherAPP_LIMIT_*values, and uses it in all three actions for both the validator and the description. The validators and the documented limit can no longer drift apart, which is howcreateTeamended up at 36 while claiming 32. The rendered descriptions are unchanged, so the generated specs do not move.utopia-php/database'sRolesvalidator also allows 81 for the same reason (Validator/Roles.php). It is a vendored library and cannot reference an Appwrite constant, so it stays as it is; the two agree today.Storage is unaffected: the memberships
rolesattribute is size 128 inapp/config/collections/common.php.Test Plan
composer linton all five changed files,vendor/bin/rector --dry-runon the test, andphpstanon the three actions: all clean.testCreateTeamnow sends a project-scoped role,project-<ID>-developer, which is 38 characters: longer than the old 36-character limit, so it fails before this change, without restating the limit in the test. On the client and console sides it then reads the creator's membership back and checks the role was saved. An API key creates a team without a creator membership, so the server side checks the 201 only. The creator always getsowneras well, so the check is that the role is contained, not that it is the only one.Not run: the e2e needs the Docker stack, which was not available here.
Related PRs and Issues
Checklist
createTeam's description moves from "32" to "81", which is the only rendered change; the two membership descriptions render the same as before