Skip to content

Commit 07d63dc

Browse files
Make attributes in response optional
1 parent d49fe6d commit 07d63dc

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ trait UserRoutesV2 extends SamUserDirectives with SamRequestContextDirectives {
187187
private def getSamUserCombinedState(samUser: SamUser, samRequestContext: SamRequestContext): Route =
188188
get {
189189
complete {
190-
val combinedStateResponse = for {
190+
for {
191191
allowances <- userService.getUserAllowances(samUser, samRequestContext)
192192
maybeAttributes <- userService.getUserAttributes(samUser.id, samRequestContext)
193193
termsOfServiceDetails <- tosService.getTermsOfServiceDetailsForUser(samUser.id, samRequestContext)
@@ -201,14 +201,13 @@ trait UserRoutesV2 extends SamUserDirectives with SamRequestContextDirectives {
201201
includePublic = false,
202202
samRequestContext
203203
)
204-
.recover(_ => FilteredResourcesFlat(Set.empty))
205-
} yield maybeAttributes.map(
206-
SamUserCombinedStateResponse(samUser, allowances, _, termsOfServiceDetails, Map("enterpriseFeatures" -> enterpriseFeatures.toJson))
204+
} yield SamUserCombinedStateResponse(
205+
samUser,
206+
allowances,
207+
maybeAttributes,
208+
termsOfServiceDetails,
209+
Map("enterpriseFeatures" -> enterpriseFeatures.toJson)
207210
)
208-
combinedStateResponse.map {
209-
case Some(response) => OK -> Some(response)
210-
case None => NotFound -> None
211-
}
212211
}
213212
}
214213

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

+1-1
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

+1-1
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)