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

ID-1324 Adjust response body of group sync endpoint #1479

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ trait GoogleExtensionRoutes extends ExtensionRoutes with SamUserDirectives with
.synchronizeGroupMembers(policyId, samRequestContext = samRequestContext)
.recover {
// If the group sync was already done previously, then no need to return any sync report items, just return 200
case _: GroupAlreadySynchronized => Map.empty[WorkbenchEmail, Seq[SyncReportItem]]
case exception: GroupAlreadySynchronized => Map(exception.group.email -> Seq.empty[SyncReportItem])
}
.map { syncReport =>
StatusCodes.OK -> syncReport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import org.broadinstitute.dsde.workbench.sam.util.OpenTelemetryIOUtils._
import org.broadinstitute.dsde.workbench.sam.util.SamRequestContext
import org.broadinstitute.dsde.workbench.util.FutureSupport

class GroupAlreadySynchronized(errorReport: ErrorReport = ErrorReport(StatusCodes.Conflict, "Group has already been synchronized"))
extends WorkbenchExceptionWithErrorReport(errorReport)
case class GroupAlreadySynchronized(
group: WorkbenchGroup,
override val errorReport: ErrorReport = ErrorReport(StatusCodes.Conflict, "Group has already been synchronized")
) extends WorkbenchExceptionWithErrorReport(errorReport)

/** This class makes sure that our google groups have the right members.
*
Expand Down Expand Up @@ -61,7 +63,7 @@ class GoogleGroupSynchronizer(
if (group.version > group.lastSynchronizedVersion.getOrElse(0)) {
IO.unit
} else {
IO.raiseError(new GroupAlreadySynchronized)
IO.raiseError(new GroupAlreadySynchronized(group))
}
members <- calculateAuthDomainIntersectionIfRequired(group, samRequestContext)
subGroupSyncs <- syncSubGroupsIfRequired(group, visitedGroups, samRequestContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class GoogleExtensionRoutesSpec extends GoogleExtensionRoutesSpecHelper with Sca
}
}

"GET /api/google/policy/{resourceTypeName}/{resourceId}/{accessPolicyName}/sync" should "200 with empty response when deduping sync requests" in {
"GET /api/google/policy/{resourceTypeName}/{resourceId}/{accessPolicyName}/sync" should "200 with group email when deduping sync requests" in {
val resourceTypes = Map(resourceType.name -> resourceType)
val (user, samDep, routes) = createTestUser(resourceTypes)

Expand All @@ -297,6 +297,14 @@ class GoogleExtensionRoutesSpec extends GoogleExtensionRoutesSpecHelper with Sca
}
}

import spray.json.DefaultJsonProtocol._
val createdPolicy = Get(s"/api/resource/${resourceType.name}/foo/policies") ~> routes.route ~> check {
status shouldEqual StatusCodes.OK
responseAs[Seq[AccessPolicyResponseEntry]]
.find(_.policyName == AccessPolicyName(resourceType.ownerRoleName.value))
.getOrElse(fail("created policy not returned by get request"))
}

import spray.json.DefaultJsonProtocol._
import SamGoogleModelJsonSupport._
Post(s"/api/google/resource/${resourceType.name}/foo/${resourceType.ownerRoleName.value}/sync") ~> routes.route ~> check {
Expand All @@ -307,7 +315,9 @@ class GoogleExtensionRoutesSpec extends GoogleExtensionRoutesSpecHelper with Sca
// A duplicate call should return OK and an empty response
Post(s"/api/google/resource/${resourceType.name}/foo/${resourceType.ownerRoleName.value}/sync") ~> routes.route ~> check {
status shouldEqual StatusCodes.OK
responseAs[Map[WorkbenchEmail, Seq[SyncReportItem]]] shouldBe empty
responseAs[Map[WorkbenchEmail, Seq[SyncReportItem]]] shouldEqual Map(
createdPolicy.email -> Seq.empty
)
}
}

Expand Down
Loading