Skip to content

Commit

Permalink
Merge pull request #4057 from gemini-hlsw/fix-upstream
Browse files Browse the repository at this point in the history
Update pi to support the latest schema
  • Loading branch information
cquiroz authored Aug 13, 2024
2 parents d881530 + 2a50bdf commit 2d3474d
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object ProgramDetailsSubquery
override val subquery: String = s"""
{
type
pi $ProgramUserSubquery
pi $ProgramUserWithRoleSubquery
proposal $ProposalSubquery
proposalStatus
users $ProgramUserWithRoleSubquery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ object ProgramUserSubquery extends GraphQLSubquery.Typed[ObservationDB, ProgramU
override val subquery: String = """
{
id
type
orcidId
orcidGivenName
orcidCreditName
Expand Down
13 changes: 2 additions & 11 deletions model/shared/src/main/scala/explore/model/ProgramDetails.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
50 changes: 10 additions & 40 deletions model/shared/src/main/scala/explore/model/ProgramUser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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))
)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions project/Versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2d3474d

Please sign in to comment.