-
Notifications
You must be signed in to change notification settings - Fork 12
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1028,6 +1028,7 @@ from ${GroupMemberTable as groupMemberTable} | |
override def overwritePolicyMembers(id: FullyQualifiedPolicyId, memberList: Set[WorkbenchSubject], samRequestContext: SamRequestContext): IO[Unit] = | ||
serializableWriteTransaction("overwritePolicyMembers", samRequestContext) { implicit session => | ||
overwritePolicyMembersInternal(id, memberList) | ||
updateGroupUpdatedDateAndVersion(id) | ||
} | ||
|
||
// Steps: Delete every member from the underlying group and then add all of the new members. Do this in a *single* | ||
|
@@ -1038,7 +1039,6 @@ from ${GroupMemberTable as groupMemberTable} | |
} | ||
removeAllGroupMembers(groupId) | ||
insertGroupMembers(groupId, memberList) | ||
updateGroupUpdatedDateAndVersion(id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is an internal function, calling |
||
} | ||
|
||
override def overwritePolicy(newPolicy: AccessPolicy, samRequestContext: SamRequestContext): IO[AccessPolicy] = | ||
|
@@ -1056,7 +1056,7 @@ from ${GroupMemberTable as groupMemberTable} | |
newPolicy | ||
) | ||
setPolicyIsPublicInternal(policyPK, newPolicy.public) | ||
|
||
updateGroupUpdatedDateAndVersion(newPolicy.id) | ||
newPolicy | ||
} | ||
|
||
|
@@ -1661,7 +1661,11 @@ from ${GroupMemberTable as groupMemberTable} | |
override def setPolicyIsPublic(policyId: FullyQualifiedPolicyId, isPublic: Boolean, samRequestContext: SamRequestContext): IO[Boolean] = | ||
serializableWriteTransaction("setPolicyIsPublic", samRequestContext) { implicit session => | ||
val policyPK = loadPolicyPK(policyId) | ||
setPolicyIsPublicInternal(policyPK, isPublic) > 0 | ||
val changed = setPolicyIsPublicInternal(policyPK, isPublic) > 0 | ||
if (changed) { | ||
updateGroupUpdatedDateAndVersion(policyId) | ||
} | ||
changed | ||
} | ||
|
||
override def getResourceParent(resource: FullyQualifiedResourceId, samRequestContext: SamRequestContext): IO[Option[FullyQualifiedResourceId]] = { | ||
|
@@ -1975,6 +1979,28 @@ from ${GroupMemberTable as groupMemberTable} | |
.filter(r => roles.isEmpty || r.role.exists(role => roles.contains(role))) | ||
.filter(r => actions.isEmpty || r.action.exists(action => actions.contains(action))) ++ privateResources | ||
|
||
override def addAndRemovePolicyMembers( | ||
policyId: FullyQualifiedPolicyId, | ||
addSubjects: Set[WorkbenchSubject], | ||
removeSubjects: Set[WorkbenchSubject], | ||
samRequestContext: SamRequestContext | ||
): IO[Int] = | ||
serializableWriteTransaction("addAndRemovePolicyMembers", samRequestContext) { implicit session => | ||
val groupId = samsql"${workbenchGroupIdentityToGroupPK(policyId)}".map(rs => rs.get[GroupPK](1)).single().apply().getOrElse { | ||
throw new WorkbenchException(s"Group for policy [$policyId] not found") | ||
} | ||
val insertedCount = insertGroupMembers(groupId, addSubjects) | ||
// there is no bulk removeGroupMembers because figuring out which records to remove from the flat structure | ||
// can't be done with an in clause because it needs to use array functions | ||
val removedCount = removeSubjects | ||
.map { subject => | ||
removeGroupMember(policyId, subject) | ||
} | ||
.count(identity) // counts all that were true | ||
updateGroupUpdatedDateAndVersion(policyId) | ||
insertedCount + removedCount | ||
} | ||
|
||
private def recreateEffectivePolicyRolesTableEntry(resourceTypeNames: Set[ResourceTypeName])(implicit session: DBSession): Int = { | ||
val resource = ResourceTable.syntax("resource") | ||
val policyResource = ResourceTable.syntax("policyResource") | ||
|
29 changes: 29 additions & 0 deletions
29
src/main/scala/org/broadinstitute/dsde/workbench/sam/model/api/BulkMembershipUpdate.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.broadinstitute.dsde.workbench.sam.model.api | ||
|
||
import org.broadinstitute.dsde.workbench.model.{WorkbenchEmail, WorkbenchUserId} | ||
import org.broadinstitute.dsde.workbench.sam.model.{AccessPolicyName, PolicyIdentifiers, ResourceId, ResourceTypeName} | ||
import spray.json.RootJsonFormat | ||
|
||
case class PolicyMembershipUpdate( | ||
policyName: AccessPolicyName, | ||
addUserIds: Set[WorkbenchUserId] = Set.empty, | ||
addEmails: Set[WorkbenchEmail] = Set.empty, | ||
addPolicies: Set[PolicyIdentifiers] = Set.empty, | ||
removeUserIds: Set[WorkbenchUserId] = Set.empty, | ||
removeEmails: Set[WorkbenchEmail] = Set.empty, | ||
removePolicies: Set[PolicyIdentifiers] = Set.empty | ||
) | ||
object PolicyMembershipUpdate { | ||
import spray.json.DefaultJsonProtocol._ | ||
import SamJsonSupport._ | ||
import org.broadinstitute.dsde.workbench.model.WorkbenchIdentityJsonSupport._ | ||
implicit val policyMembershipUpdateFormat: RootJsonFormat[PolicyMembershipUpdate] = jsonFormat7(PolicyMembershipUpdate.apply) | ||
} | ||
|
||
case class BulkMembershipUpdate(resourceTypeName: ResourceTypeName, resourceId: ResourceId, policyUpdates: Seq[PolicyMembershipUpdate]) | ||
object BulkMembershipUpdate { | ||
import spray.json.DefaultJsonProtocol._ | ||
import SamJsonSupport._ | ||
import PolicyMembershipUpdate.policyMembershipUpdateFormat | ||
implicit val bulkMembershipUpdateFormat: RootJsonFormat[BulkMembershipUpdate] = jsonFormat3(BulkMembershipUpdate.apply) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?