Skip to content

feat(projects): When adding members check all memberships#2368

Closed
javirln wants to merge 1 commit intochainloop-dev:mainfrom
javirln:feat/consider-all-memberships-for-lookup
Closed

feat(projects): When adding members check all memberships#2368
javirln wants to merge 1 commit intochainloop-dev:mainfrom
javirln:feat/consider-all-memberships-for-lookup

Conversation

@javirln
Copy link
Member

@javirln javirln commented Aug 19, 2025

This pull request refactors how project membership checks are performed in the codebase, introducing a clearer distinction between direct and inherited (effective) memberships. It replaces the previous single membership query method with two new methods, ensuring that membership checks are accurate depending on the context—whether only direct membership or all effective memberships (including inherited) should be considered.

Previously, the behavior only checked direct memberships (parentID == nil) when adding a new member to a project. With inheritance now in place, we must verify whether the membership being created already exists through inheritance from another resource.

This inherited membership check applies only when adding new members. For all other operations, only direct memberships are considered, since inherited ones are treated as managed.

@javirln javirln self-assigned this Aug 19, 2025
Copy link
Member

@migmartri migmartri left a comment

Choose a reason for hiding this comment

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

please review my comments

@javirln javirln force-pushed the feat/consider-all-memberships-for-lookup branch from e50d80d to 99e2ab7 Compare August 20, 2025 07:23
@javirln javirln force-pushed the feat/consider-all-memberships-for-lookup branch from 99e2ab7 to 2954e25 Compare August 20, 2025 10:36
Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
@javirln javirln force-pushed the feat/consider-all-memberships-for-lookup branch from 2954e25 to 4be0473 Compare August 20, 2025 10:38
@javirln
Copy link
Member Author

javirln commented Aug 20, 2025

Updated the PR, I've simplified things by just creating a method that checks for the existence of all kind of memberships, direct or inherited. The old code remains untouched.

@javirln javirln requested a review from migmartri August 20, 2025 10:51
existingMembership, err := uc.projectsRepository.FindProjectMembershipByProjectAndID(ctx, orgID, projectID, userUUID, authz.MembershipTypeUser)
if err != nil && !IsNotFound(err) {
// Check if the user is already a member of the project (including inherited memberships)
membershipExists, err := uc.projectsRepository.ExistsProjectMembershipEffective(ctx, orgID, projectID, userUUID, authz.MembershipTypeUser)
Copy link
Member

Choose a reason for hiding this comment

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

Do we want this? This will prevent setting a custom role at the project level (inherited as viewer, local as Admin). This was one of our main use cases if I'm not wrong.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we take into account the role when checking if the membership exists, we could have both, inherited as viewer and local as admin, that's an easy change.

@javirln
Copy link
Member Author

javirln commented Aug 20, 2025

We are going to reevaluate the behavior because we have some doubts on how it should work.

@javirln javirln closed this Aug 20, 2025
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.

3 participants