From 2a50bdf3f566d63a9f89a18fd2b7e998d48bed98 Mon Sep 17 00:00:00 2001 From: Carlos Quiroz Date: Tue, 13 Aug 2024 16:51:38 -0400 Subject: [PATCH] Update pi to support the latest schema --- .../common/ProgramDetailsSubquery.scala | 2 +- .../queries/common/ProgramUserSubquery.scala | 1 - .../scala/explore/model/ProgramDetails.scala | 13 +---- .../scala/explore/model/ProgramUser.scala | 50 ++++--------------- .../explore/model/ProgramUserWithRole.scala | 12 +++-- .../explore/model/enums/ProgramUserRole.scala | 1 + project/Versions.scala | 4 +- 7 files changed, 25 insertions(+), 58 deletions(-) diff --git a/explore/src/clue/scala/queries/common/ProgramDetailsSubquery.scala b/explore/src/clue/scala/queries/common/ProgramDetailsSubquery.scala index 70bbd44c87..1e344e9f81 100644 --- a/explore/src/clue/scala/queries/common/ProgramDetailsSubquery.scala +++ b/explore/src/clue/scala/queries/common/ProgramDetailsSubquery.scala @@ -14,7 +14,7 @@ object ProgramDetailsSubquery override val subquery: String = s""" { type - pi $ProgramUserSubquery + pi $ProgramUserWithRoleSubquery proposal $ProposalSubquery proposalStatus users $ProgramUserWithRoleSubquery diff --git a/explore/src/clue/scala/queries/common/ProgramUserSubquery.scala b/explore/src/clue/scala/queries/common/ProgramUserSubquery.scala index b7d45066ba..39e36839e1 100644 --- a/explore/src/clue/scala/queries/common/ProgramUserSubquery.scala +++ b/explore/src/clue/scala/queries/common/ProgramUserSubquery.scala @@ -13,7 +13,6 @@ object ProgramUserSubquery extends GraphQLSubquery.Typed[ObservationDB, ProgramU override val subquery: String = """ { id - type orcidId orcidGivenName orcidCreditName diff --git a/model/shared/src/main/scala/explore/model/ProgramDetails.scala b/model/shared/src/main/scala/explore/model/ProgramDetails.scala index 859356c34e..fdb495475a 100644 --- a/model/shared/src/main/scala/explore/model/ProgramDetails.scala +++ b/model/shared/src/main/scala/explore/model/ProgramDetails.scala @@ -40,20 +40,11 @@ object ProgramDetails: t <- c.get[ProgramType]("type") p <- c.get[Option[Proposal]]("proposal") ps <- c.get[ProposalStatus]("proposalStatus") - pi <- c.downField("pi").as[Option[ProgramUser]] + pi <- c.downField("pi").as[Option[ProgramUserWithRole]] us <- c.get[List[ProgramUserWithRole]]("users") in <- c.get[List[CoIInvitation]]("userInvitations") r <- c.downField("reference").downField("label").success.traverse(_.as[Option[ProgramReference]]) as <- c.downField("allocations").as[CategoryAllocationList] - } yield ProgramDetails( - t, - p, - ps, - pi.map(ProgramUserWithRole(_, None, None)), - us, - in, - r.flatten, - as - ) + } yield ProgramDetails(t, p, ps, pi, us, in, r.flatten, as) ) diff --git a/model/shared/src/main/scala/explore/model/ProgramUser.scala b/model/shared/src/main/scala/explore/model/ProgramUser.scala index 8d17ef49a6..fecb0facd0 100644 --- a/model/shared/src/main/scala/explore/model/ProgramUser.scala +++ b/model/shared/src/main/scala/explore/model/ProgramUser.scala @@ -14,8 +14,6 @@ import lucuma.core.model.User // Case class for the 'pi' and `users` in the Program. These must be // actual users, not service users. -// An empty OrcidProfile implies a guest - which is possible for PIs, but -// not other program roles. case class ProgramUser( id: User.Id, profile: Option[OrcidProfile] @@ -26,41 +24,13 @@ object ProgramUser: OrcidId.fromValue(s).fold(s => DecodingFailure(s, Nil).asLeft, _.asRight) given Decoder[ProgramUser] = c => - c.downField("type").as[String].flatMap { - case "STANDARD" => - for { - id <- c.downField("id").as[User.Id] - orcidId <- c.downField("orcidId").as[String].flatMap(toOrcidId) - gname <- c.downField("orcidGivenName").as[Option[String]] - fname <- c.downField("orcidFamilyName").as[Option[String]] - cname <- c.downField("orcidCreditName").as[Option[String]] - email <- c.downField("orcidEmail").as[Option[String]] - } yield ProgramUser(id, OrcidProfile(orcidId, gname, fname, cname, email).some) - - case "GUEST" => - for { - id <- c.downField("id").as[User.Id] - } yield ProgramUser(id, none) - - case tag => - DecodingFailure(s"Invalid program user type: $tag", Nil).asLeft - } - - // The API should prevent non-std users from creating proposals, then we - // can use the code below and make the profile non-optional. - - // private def validateUserType(s: String): Decoder.Result[Unit] = - // if (s === "STANDARD") ().asRight - // else DecodingFailure(s"Invalid program user type `$s`", Nil).asLeft - - // given Decoder[ProgramUser] = Decoder.instance(c => - // for { - // _ <- c.downField("type").as[String].flatMap(validateUserType) - // id <- c.downField("id").as[User.Id] - // orcidId <- c.downField("orcidId").as[String].flatMap(toOrcidId) - // gname <- c.downField("orcidGivenName").as[Option[String]] - // cname <- c.downField("orcidCreditName").as[Option[String]] - // fname <- c.downField("orcidFamilyName").as[Option[String]] - // email <- c.downField("orcidEmail").as[Option[String]] - // } yield ProgramUser(id, OrcidProfile(orchidId, gname, cname, fname, email)) - // ) + for { + id <- c.downField("id").as[User.Id] + orcidId <- c.downField("orcidId").as[Option[String]].map(_.traverse(toOrcidId)) + gname <- c.downField("orcidGivenName").as[Option[String]] + fname <- c.downField("orcidFamilyName").as[Option[String]] + cname <- c.downField("orcidCreditName").as[Option[String]] + email <- c.downField("orcidEmail").as[Option[String]] + } yield ProgramUser(id, + orcidId.toOption.flatten.map(OrcidProfile(_, gname, fname, cname, email)) + ) diff --git a/model/shared/src/main/scala/explore/model/ProgramUserWithRole.scala b/model/shared/src/main/scala/explore/model/ProgramUserWithRole.scala index 3a2eae97dd..fe5a51f010 100644 --- a/model/shared/src/main/scala/explore/model/ProgramUserWithRole.scala +++ b/model/shared/src/main/scala/explore/model/ProgramUserWithRole.scala @@ -15,12 +15,18 @@ case class ProgramUserWithRole( user: ProgramUser, partnerLink: Option[PartnerLink], role: Option[ProgramUserRole] -) derives Decoder, - Eq { +) derives Eq: val roleName: String = role match { case None => "Pi" case Some(role) => role.tag } val name: String = user.profile.fold("Guest User")(p => p.displayName) -} + +object ProgramUserWithRole: + given Decoder[ProgramUserWithRole] = c => + for { + u <- c.downField("user").as[ProgramUser] + pl <- c.downField("partnerLink").as[Option[PartnerLink]] + role <- c.downField("role").as[Option[ProgramUserRole]] + } yield ProgramUserWithRole(u, pl, role) diff --git a/model/shared/src/main/scala/explore/model/enums/ProgramUserRole.scala b/model/shared/src/main/scala/explore/model/enums/ProgramUserRole.scala index bcd0911c84..8b5a74d682 100644 --- a/model/shared/src/main/scala/explore/model/enums/ProgramUserRole.scala +++ b/model/shared/src/main/scala/explore/model/enums/ProgramUserRole.scala @@ -6,6 +6,7 @@ package explore.model.enums import lucuma.core.util.Enumerated enum ProgramUserRole(val tag: String) derives Enumerated { + case Pi extends ProgramUserRole("Pi") case Coi extends ProgramUserRole("Coi") case Observer extends ProgramUserRole("Observer") case Support extends ProgramUserRole("Support") diff --git a/project/Versions.scala b/project/Versions.scala index 5eac3a8ab1..062b7add37 100644 --- a/project/Versions.scala +++ b/project/Versions.scala @@ -25,8 +25,8 @@ object Versions { val lucumaCatalog = "0.47.3" val lucumaReact = "0.70.0" val lucumaRefined = "0.1.3" - val lucumaSchemas = "0.94.0" - val lucumaOdbSchema = "0.11.12" + val lucumaSchemas = "0.94.1" + val lucumaOdbSchema = "0.11.13" val lucumaSSO = "0.6.21" val lucumaUI = "0.114.0" val lucumaITC = "0.21.17"