Skip to content

server: remove user-project mappings when delete a project - #14150

Open
weizhouapache wants to merge 1 commit into
apache:4.20from
weizhouapache:fix-12601-project-account-cleanup
Open

weizhouapache wants to merge 1 commit into
apache:4.20from
weizhouapache:fix-12601-project-account-cleanup

Conversation

@weizhouapache

Copy link
Copy Markdown
Member

Description

This PR fixes #12601

When an account is added to a project with a project role (e.g. via addUserToProject), the resulting project_account row has a non-null user_id. Project cleanup (deleteProject ... cleanup=true) unassigns every account from the project via ProjectAccountDaoImpl#findByProjectIdUserId(projectId, accountId, null), expecting a null userId to mean "match this account regardless of which user_id the row has".

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

Verified on a live 2-node management server deployment:

  • Built and deployed the patched jar to both management nodes.
  • Reproduced the original issue with the pre-fix code: created an account, created a project, added the account's user to the project with addUserToProject roletype=Admin (producing a project_account row with a non-null user_id), deleted the project with cleanup=true (reported success), then attempted deleteAccount — reproduced the exact errorcode 431 failure from Unable to delete account if the project is removed #12601.
  • Repeated the same steps against the fixed jar: deleteProject cleanup=true followed by deleteAccount both succeeded, and the account no longer appeared in listAccounts.
  • Confirmed both management nodes ended up running the identical fixed build.

How did you try to break this feature and the system with this change?

@codecov

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 16.37%. Comparing base (a4d3c66) to head (506fbc0).
⚠️ Report is 1 commits behind head on 4.20.

Files with missing lines Patch % Lines
.../com/cloud/projects/dao/ProjectAccountDaoImpl.java 0.00% 3 Missing ⚠️
...in/java/com/cloud/projects/ProjectManagerImpl.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.20   #14150      +/-   ##
============================================
- Coverage     16.37%   16.37%   -0.01%     
+ Complexity    13614    13613       -1     
============================================
  Files          5669     5669              
  Lines        501527   501528       +1     
  Branches      60922    60923       +1     
============================================
- Hits          82148    82142       -6     
- Misses       410171   410179       +8     
+ Partials       9208     9207       -1     
Flag Coverage Δ
uitests 4.14% <ø> (ø)
unittests 17.24% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@weizhouapache
weizhouapache requested a lite review from Copilot September 14, 2026 07:52
@weizhouapache
weizhouapache marked this pull request as ready for review September 14, 2026 07:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Add regression tests covering removal of user-specific mappings during project cleanup.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Fixes project cleanup so user-specific project mappings are removed when deleting a project, allowing associated accounts to be deleted.

Changes:

  • Allows nullable userId lookups in the project-account DAO.
  • Uses account-wide lookup during project cleanup.
  • Updates the DAO contract.
File summaries
File Summary
server/src/main/java/com/cloud/projects/ProjectManagerImpl.java Removes mappings regardless of user association during cleanup.
engine/schema/src/main/java/com/cloud/projects/dao/ProjectAccountDaoImpl.java Implements optional user filtering.
engine/schema/src/main/java/com/cloud/projects/dao/ProjectAccountDao.java Updates the DAO method signature.
Review details

Suppressed comments (1)

engine/schema/src/main/java/com/cloud/projects/dao/ProjectAccountDaoImpl.java:116

  • Please add a regression test for the new nullable path. The current tests exercise user-specific lookups but do not verify that a user-specific project_account row is found and removed when userId is null; without that coverage, the fix for #12601 can regress to the old account-level-only lookup unnoticed.
        if (userId != null) {
            sc.setParameters("userId", userId);
        }
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Override
public boolean unassignAccountFromProject(long projectId, long accountId) {
ProjectAccountVO projectAccount = _projectAccountDao.findByProjectIdAccountId(projectId, accountId);
ProjectAccountVO projectAccount = _projectAccountDao.findByProjectIdUserId(projectId, accountId, null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants