Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORE-242 bulk membership update #1613

Merged
merged 5 commits into from
Jan 9, 2025
Merged

CORE-242 bulk membership update #1613

merged 5 commits into from
Jan 9, 2025

Conversation

dvoet
Copy link
Collaborator

@dvoet dvoet commented Dec 20, 2024

Ticket: https://broadworkbench.atlassian.net/browse/CORE-242

In addition to add the new api, refactored how some other calls validate (see comments in PR).


PR checklist

  • I've followed the instructions if I've made any changes to the API, especially if they're breaking changes
  • I've filled out the Security Risk Assessment (requires Broad Internal network access) and attached the result to the JIRA ticket

@@ -1038,7 +1039,6 @@ from ${GroupMemberTable as groupMemberTable}
}
removeAllGroupMembers(groupId)
insertGroupMembers(groupId, memberList)
updateGroupUpdatedDateAndVersion(id)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is an internal function, calling updateGroupUpdatedDateAndVersion is redundant

Comment on lines -781 to -784
_ <- directoryDAO.updateGroupUpdatedDateAndVersionWithSession(
FullyQualifiedPolicyId(policyId.resource, policyId.accessPolicyName),
samRequestContext
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this was here as a failsafe but was double doing work. I made sure it is correctly called in the DAO. Maybe a follow on would be to figure out a trigger even though I despise triggers.

@@ -851,51 +906,14 @@ class ResourceService(
): IO[Set[ValidatableAccessPolicy]] =
policies.toList
.traverse { case (accessPolicyName, accessPolicyMembershipRequest) =>
for {
// grouping member emails and policy emails together
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It looks like this code was getting the email address for each policy and adding them to memberEmails of the policy. The problem is that policies that do not exist are just ignored. There is also no reason to load a policy by its identifiers, get its email, then use the email to load its identifiers. I changes all this to validate policies (so I could use that for the new api) then use the policy identifiers directly.

Comment on lines +258 to +260
validatableAccessPolicy.emailsToSubjects.values.flatten.toSet ++ validatableAccessPolicy.memberPolicies
.getOrElse(Set.empty)
.map(_.toFullyQualifiedPolicyId),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See comment below. memberPolicies are no longer included in emailsToSubjects so add them here when constructing the policy

@dvoet dvoet marked this pull request as ready for review January 9, 2025 20:03
@dvoet dvoet requested a review from a team as a code owner January 9, 2025 20:03
Copy link
Contributor

@calypsomatic calypsomatic left a comment

Choose a reason for hiding this comment

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

One small nit: the ticket specifies that the API should be a PATCH instead of a POST. Does it matter?

@dvoet
Copy link
Collaborator Author

dvoet commented Jan 9, 2025

One small nit: the ticket specifies that the API should be a PATCH instead of a POST. Does it matter?

I changed the ticket ;)

This endpoint is used to add and remove members of multiple policies across multiple resource in one api call.
Each policy is updated in order in its own transaction. If a policy does not exist on a resource,
processing stops with an error but all updates up to that point are committed. Missing member ids, emails or policies fail fast. Additions are processed
before removals so if a subject is in both the add and remove lists for a policy, the ultimate result is removal.
Copy link
Contributor

Choose a reason for hiding this comment

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

What about checking that the add and remove lists are different and throwing an error if there's any overlap?

@dvoet dvoet enabled auto-merge (squash) January 9, 2025 21:35
Copy link

sonarqubecloud bot commented Jan 9, 2025

@dvoet dvoet merged commit 217768e into develop Jan 9, 2025
20 checks passed
@dvoet dvoet deleted the bulkMembershipUpdate branch January 9, 2025 22:44
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