Skip to content

Commit 5911109

Browse files
Make attributes in response optional
1 parent d49fe6d commit 5911109

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

src/main/scala/org/broadinstitute/dsde/workbench/sam/api/UserRoutesV2.scala

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import org.broadinstitute.dsde.workbench.model._
1010
import org.broadinstitute.dsde.workbench.sam.model.{ResourceRoleName, ResourceTypeName}
1111
import org.broadinstitute.dsde.workbench.sam.model.api.SamUserResponse._
1212
import org.broadinstitute.dsde.workbench.sam.model.api.{
13-
FilteredResourcesFlat,
1413
SamUser,
1514
SamUserAttributesRequest,
1615
SamUserCombinedStateResponse,
@@ -187,7 +186,7 @@ trait UserRoutesV2 extends SamUserDirectives with SamRequestContextDirectives {
187186
private def getSamUserCombinedState(samUser: SamUser, samRequestContext: SamRequestContext): Route =
188187
get {
189188
complete {
190-
val combinedStateResponse = for {
189+
for {
191190
allowances <- userService.getUserAllowances(samUser, samRequestContext)
192191
maybeAttributes <- userService.getUserAttributes(samUser.id, samRequestContext)
193192
termsOfServiceDetails <- tosService.getTermsOfServiceDetailsForUser(samUser.id, samRequestContext)
@@ -201,14 +200,13 @@ trait UserRoutesV2 extends SamUserDirectives with SamRequestContextDirectives {
201200
includePublic = false,
202201
samRequestContext
203202
)
204-
.recover(_ => FilteredResourcesFlat(Set.empty))
205-
} yield maybeAttributes.map(
206-
SamUserCombinedStateResponse(samUser, allowances, _, termsOfServiceDetails, Map("enterpriseFeatures" -> enterpriseFeatures.toJson))
203+
} yield SamUserCombinedStateResponse(
204+
samUser,
205+
allowances,
206+
maybeAttributes,
207+
termsOfServiceDetails,
208+
Map("enterpriseFeatures" -> enterpriseFeatures.toJson)
207209
)
208-
combinedStateResponse.map {
209-
case Some(response) => OK -> Some(response)
210-
case None => NotFound -> None
211-
}
212210
}
213211
}
214212

src/main/scala/org/broadinstitute/dsde/workbench/sam/model/api/SamUserCombinedStateResponse.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object SamUserCombinedStateResponse {
1313
final case class SamUserCombinedStateResponse(
1414
samUser: SamUser,
1515
allowances: SamUserAllowances,
16-
attributes: SamUserAttributes,
16+
attributes: Option[SamUserAttributes],
1717
termsOfServiceDetails: TermsOfServiceDetails,
1818
additionalDetails: Map[String, JsValue]
1919
)

src/test/scala/org/broadinstitute/dsde/workbench/sam/api/UserRoutesV2Spec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ class UserRoutesV2Spec extends AnyFlatSpec with Matchers with TimeMatchers with
273273
val userCombinedStateResponse = SamUserCombinedStateResponse(
274274
defaultUser,
275275
SamUserAllowances(enabled = true, termsOfService = true),
276-
SamUserAttributes(defaultUser.id, marketingConsent = true),
276+
Option(SamUserAttributes(defaultUser.id, marketingConsent = true)),
277277
TermsOfServiceDetails("v1", Instant.now(), permitsSystemUsage = true, isCurrentVersion = true),
278278
Map("enterpriseFeatures" -> FilteredResourcesFlat(Set(enterpriseFeature)).toJson)
279279
)

0 commit comments

Comments
 (0)