fix: Update project state logic to correctly handle user roles and de…#5386
fix: Update project state logic to correctly handle user roles and de…#5386hxrshxz wants to merge 6 commits into
Conversation
…activation Signed-off-by: Harsh <harshmastic@gmail.com>
3d3746b to
af7cdb2
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue where projects become invisible when a project owner is disabled, even if other active owners exist. The fix updates the UpdateProjectState method in the repository layer to add a filter that checks for other active owners before marking a project as removed.
Key Changes:
- Added a
$not+$elemMatchcondition to check if there are other active owners besides the user being deactivated - Modified the MongoDB filter to only mark projects as removed when the disabled user is the sole owner
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f3598f1 to
05f9099
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| filter = bson.D{ | ||
| {"members", bson.D{ | ||
| {"$elemMatch", bson.D{ | ||
| {"user_id", userID}, | ||
| {"role", bson.D{ | ||
| {"$eq", entities.RoleOwner}, | ||
| {"role", entities.RoleOwner}, | ||
| }}, | ||
| }}, | ||
| {"members", bson.D{ | ||
| {"$not", bson.D{ |
There was a problem hiding this comment.
The filter uses two top-level "members" keys (one $elemMatch and one $not/$elemMatch). MongoDB query documents should avoid duplicate field names because behavior can be undefined/last-key-wins, which could cause this update to match unintended projects. Combine these predicates with an explicit $and (or merge into a single members expression) so both conditions are guaranteed to apply.
| {"$elemMatch", bson.D{ | ||
| {"user_id", userID}, | ||
| {"role", bson.D{ | ||
| {"$eq", entities.RoleOwner}, | ||
| {"role", entities.RoleOwner}, | ||
| }}, | ||
| }}, |
There was a problem hiding this comment.
The owner-matching $elemMatch doesn’t include invitation status. Since project visibility elsewhere treats non-accepted invitations as inactive (see chaoscenter/authentication/api/utils/project_utils.go:104-121), consider adding invitation == Accepted (and likewise in the “other owner” $elemMatch) so only accepted owners keep a project from being marked removed.
|
@hxrshxz can you please address the comments provided by copilot |
Proposed changes
Fixed issue where projects become invisible when a project owner is disabled, even if other active owners exist. Updated the
UpdateProjectStatemethod in the repository layer to only mark a project as removed when the disabled user is the only active owner.Link to issue: #5106
Types of changes
What types of changes does your code introduce to Litmus? Put an
xin the boxes that applyChecklist
Dependency
NA