Repository navigation
fix: preserve server team_id during admin UI edits - #3780
Conversation
When editing a virtual server via the admin UI without an explicit team_id in the form, verify_team_for_user() fell back to the current user's personal team, silently reassigning the server on every edit. Now the edit endpoint looks up the existing server's team_id and preserves it when no team_id is provided in the form. Closes: IBM#3779 Signed-off-by: kimsehwan96 <[email protected]>
Extend the server team_id preservation fix to gateway, resource, prompt,
and A2A agent edit endpoints. All five endpoints now look up the existing
entity's team_id when no explicit team_id is provided in the form, instead
of silently falling back to the user's personal team.
Also fixes:
- resource edit was missing team_id and owner_email entirely
- prompt edit had a debug log typo ("befor")
Adds comprehensive tests for all five entity types covering the team_id
preservation path and the explicit team_id override path.
Closes: IBM#3779
Signed-off-by: Mihai Criveti <[email protected]>
…ity types The admin-side team_id preservation (previous commit) was only effective for server and A2A agent edits because only those service-layer update methods actually persisted team_id to the ORM row. Gateway, resource, and prompt services accepted team_id in their update DTOs but silently ignored it. This commit: - Adds team_id persistence to gateway_service.update_gateway() - Adds team_id persistence to resource_service.update_resource() - Adds team_id persistence to prompt_service.update_prompt() - Adds team reassignment validation to a2a_service.update_agent() (previously persisted via generic setattr without ownership checks) - Each service now validates team existence and caller ownership before allowing team reassignment, matching server_service's pattern Signed-off-by: Mihai Criveti <[email protected]>
The server service validates the effective team_id when visibility changes to "team" (even when team_id is not explicitly provided in the update), ensuring you cannot set visibility to "team" with an invalid or missing team. The gateway, resource, prompt, and A2A services were missing this validation. Now all four services validate the target team_id (either from the update DTO or from the existing entity) when visibility transitions to "team", matching server_service's stricter pattern. Signed-off-by: Mihai Criveti <[email protected]>
Add targeted deny-path tests for all four entity services verifying: - Reassigning to a non-existent team is rejected - Setting visibility to "team" without any team_id is rejected These tests validate the service-layer validation logic, not just admin-route DTO construction. Signed-off-by: Mihai Criveti <[email protected]>
2566056 to
5323853
Compare
|
Thanks for catching this @kimsehwan96 — the root cause analysis was spot-on. I rebased onto main, expanded the fix to cover all entity types, and added service-layer persistence + validation. Here's what the final branch contains: Commits:
Test results: 6310 passed, 0 failures. |
crivetimihai
left a comment
There was a problem hiding this comment.
LGTM — fix is correct, complete, and well-tested across all entity types.
|
@crivetimihai Thanks for fast review and addintional works! |
Add tests for uncovered branches in team validation functions: - Non-owner membership rejection (all 4 services) - No-user-email early return path with team_id persistence (gateway, resource, prompt, A2A) Differential coverage: 114 lines, 0 missing, 100%. Signed-off-by: Mihai Criveti <[email protected]>
|
@kimsehwan96 thanks for the PR. Merging. Can you please test that everything still works correctly post merge? Thank you! |
|
@crivetimihai I tested it from main branch. It correctly works. But, If some user who are not member of that team try to change MCP server configuration (via admin UI edit), then just show I will create issue related this. Thanks! |
* fix: preserve server team_id during admin UI edits When editing a virtual server via the admin UI without an explicit team_id in the form, verify_team_for_user() fell back to the current user's personal team, silently reassigning the server on every edit. Now the edit endpoint looks up the existing server's team_id and preserves it when no team_id is provided in the form. Closes: #3779 Signed-off-by: kimsehwan96 <[email protected]> * fix: preserve entity team_id during admin UI edits for all entity types Extend the server team_id preservation fix to gateway, resource, prompt, and A2A agent edit endpoints. All five endpoints now look up the existing entity's team_id when no explicit team_id is provided in the form, instead of silently falling back to the user's personal team. Also fixes: - resource edit was missing team_id and owner_email entirely - prompt edit had a debug log typo ("befor") Adds comprehensive tests for all five entity types covering the team_id preservation path and the explicit team_id override path. Closes: #3779 Signed-off-by: Mihai Criveti <[email protected]> * fix: add service-layer team_id persistence and validation for all entity types The admin-side team_id preservation (previous commit) was only effective for server and A2A agent edits because only those service-layer update methods actually persisted team_id to the ORM row. Gateway, resource, and prompt services accepted team_id in their update DTOs but silently ignored it. This commit: - Adds team_id persistence to gateway_service.update_gateway() - Adds team_id persistence to resource_service.update_resource() - Adds team_id persistence to prompt_service.update_prompt() - Adds team reassignment validation to a2a_service.update_agent() (previously persisted via generic setattr without ownership checks) - Each service now validates team existence and caller ownership before allowing team reassignment, matching server_service's pattern Signed-off-by: Mihai Criveti <[email protected]> * fix: validate visibility->"team" transitions in all entity services The server service validates the effective team_id when visibility changes to "team" (even when team_id is not explicitly provided in the update), ensuring you cannot set visibility to "team" with an invalid or missing team. The gateway, resource, prompt, and A2A services were missing this validation. Now all four services validate the target team_id (either from the update DTO or from the existing entity) when visibility transitions to "team", matching server_service's stricter pattern. Signed-off-by: Mihai Criveti <[email protected]> * test: add deny-path service tests for team_id validation Add targeted deny-path tests for all four entity services verifying: - Reassigning to a non-existent team is rejected - Setting visibility to "team" without any team_id is rejected These tests validate the service-layer validation logic, not just admin-route DTO construction. Signed-off-by: Mihai Criveti <[email protected]> * test: achieve 100% differential coverage for team_id validation Add tests for uncovered branches in team validation functions: - Non-owner membership rejection (all 4 services) - No-user-email early return path with team_id persistence (gateway, resource, prompt, A2A) Differential coverage: 114 lines, 0 missing, 100%. Signed-off-by: Mihai Criveti <[email protected]> --------- Signed-off-by: kimsehwan96 <[email protected]> Signed-off-by: Mihai Criveti <[email protected]> Co-authored-by: Mihai Criveti <[email protected]>
* fix: preserve server team_id during admin UI edits When editing a virtual server via the admin UI without an explicit team_id in the form, verify_team_for_user() fell back to the current user's personal team, silently reassigning the server on every edit. Now the edit endpoint looks up the existing server's team_id and preserves it when no team_id is provided in the form. Closes: IBM#3779 Signed-off-by: kimsehwan96 <[email protected]> * fix: preserve entity team_id during admin UI edits for all entity types Extend the server team_id preservation fix to gateway, resource, prompt, and A2A agent edit endpoints. All five endpoints now look up the existing entity's team_id when no explicit team_id is provided in the form, instead of silently falling back to the user's personal team. Also fixes: - resource edit was missing team_id and owner_email entirely - prompt edit had a debug log typo ("befor") Adds comprehensive tests for all five entity types covering the team_id preservation path and the explicit team_id override path. Closes: IBM#3779 Signed-off-by: Mihai Criveti <[email protected]> * fix: add service-layer team_id persistence and validation for all entity types The admin-side team_id preservation (previous commit) was only effective for server and A2A agent edits because only those service-layer update methods actually persisted team_id to the ORM row. Gateway, resource, and prompt services accepted team_id in their update DTOs but silently ignored it. This commit: - Adds team_id persistence to gateway_service.update_gateway() - Adds team_id persistence to resource_service.update_resource() - Adds team_id persistence to prompt_service.update_prompt() - Adds team reassignment validation to a2a_service.update_agent() (previously persisted via generic setattr without ownership checks) - Each service now validates team existence and caller ownership before allowing team reassignment, matching server_service's pattern Signed-off-by: Mihai Criveti <[email protected]> * fix: validate visibility->"team" transitions in all entity services The server service validates the effective team_id when visibility changes to "team" (even when team_id is not explicitly provided in the update), ensuring you cannot set visibility to "team" with an invalid or missing team. The gateway, resource, prompt, and A2A services were missing this validation. Now all four services validate the target team_id (either from the update DTO or from the existing entity) when visibility transitions to "team", matching server_service's stricter pattern. Signed-off-by: Mihai Criveti <[email protected]> * test: add deny-path service tests for team_id validation Add targeted deny-path tests for all four entity services verifying: - Reassigning to a non-existent team is rejected - Setting visibility to "team" without any team_id is rejected These tests validate the service-layer validation logic, not just admin-route DTO construction. Signed-off-by: Mihai Criveti <[email protected]> * test: achieve 100% differential coverage for team_id validation Add tests for uncovered branches in team validation functions: - Non-owner membership rejection (all 4 services) - No-user-email early return path with team_id persistence (gateway, resource, prompt, A2A) Differential coverage: 114 lines, 0 missing, 100%. Signed-off-by: Mihai Criveti <[email protected]> --------- Signed-off-by: kimsehwan96 <[email protected]> Signed-off-by: Mihai Criveti <[email protected]> Co-authored-by: Mihai Criveti <[email protected]>
🔗 Related Issue
Closes: #3779
📝 Summary
When editing a virtual server via the admin UI, the server's
team_idwas silently overwritten on every save — even when the user did not intend to change the team.Root cause: In
admin_edit_server(), when noteam_idis present in the form (e.g., editing from the "All Teams" view),verify_team_for_user()falls back to the current user's personal team, which is then unconditionally written to the server record.Fix: Before calling
verify_team_for_user(), the edit endpoint now looks up the existing server'steam_idfrom the database and uses it as the default when the form does not include one. This preserves the original team assignment while still allowing explicit team changes via the API.🏷️ Type of Change
🧪 Verification
make lintmake testmake coverage✅ Checklist
make black isort pre-commit)📓 Notes (optional)
Recommended future work
a2a_service.pyuses genericsetattrloop)verify_team_for_user()but their service layers don't persist the result (accidentally safe)