Skip to content

fix: Update project state logic to correctly handle user roles and de…#5386

Open
hxrshxz wants to merge 6 commits into
litmuschaos:masterfrom
hxrshxz:fix-project-disappear-5106
Open

fix: Update project state logic to correctly handle user roles and de…#5386
hxrshxz wants to merge 6 commits into
litmuschaos:masterfrom
hxrshxz:fix-project-disappear-5106

Conversation

@hxrshxz
Copy link
Copy Markdown

@hxrshxz hxrshxz commented Jan 8, 2026

Proposed changes

Fixed issue where projects become invisible when a project owner is disabled, even if other active owners exist. Updated the UpdateProjectState method 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 x in the boxes that apply

  • New feature (non-breaking change which adds functionality)
  • Bugfix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices applies)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the commit for DCO to be passed.
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have added necessary documentation (if appropriate)

Dependency

NA

Copilot AI review requested due to automatic review settings January 8, 2026 22:37
…activation

Signed-off-by: Harsh <harshmastic@gmail.com>
@hxrshxz hxrshxz force-pushed the fix-project-disappear-5106 branch from 3d3746b to af7cdb2 Compare January 8, 2026 22:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 + $elemMatch condition 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.

Comment thread chaoscenter/authentication/pkg/project/repository.go Outdated
Signed-off-by: Harsh <harshmastic@gmail.com>
@hxrshxz hxrshxz force-pushed the fix-project-disappear-5106 branch from f3598f1 to 05f9099 Compare January 8, 2026 23:18
@PriteshKiri PriteshKiri requested a review from SahilKr24 March 17, 2026 05:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines 364 to +372
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{
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines 366 to +370
{"$elemMatch", bson.D{
{"user_id", userID},
{"role", bson.D{
{"$eq", entities.RoleOwner},
{"role", entities.RoleOwner},
}},
}},
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@SarthakJain26
Copy link
Copy Markdown
Contributor

@hxrshxz can you please address the comments provided by copilot

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.

4 participants