Skip to content

Commit

Permalink
rename to addProgramUser
Browse files Browse the repository at this point in the history
  • Loading branch information
swalker2m committed Dec 2, 2024
1 parent 87ebb66 commit d467f59
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ type AddDatasetEventResult {

}

input AddProgramUserInput {
orcidId: String!
programId: ProgramId!
role: ProgramUserRole!
SET: ProgramUserPropertiesInput
}

type AddProgramUserResult {
programUser: ProgramUser!
}

"SequenceEvent creation parameters."
input AddSequenceEventInput {
visitId: VisitId!
Expand Down Expand Up @@ -2717,17 +2728,6 @@ enum MosPreImaging {
IS_NOT_MOS_PRE_IMAGING
}

input CreatePreAuthProgramUserInput {
orcidId: String!
programId: ProgramId!
role: ProgramUserRole!
SET: ProgramUserPropertiesInput
}

type CreatePreAuthProgramUserResult {
programUser: ProgramUser!
}

type Mutation {

"""
Expand Down Expand Up @@ -2768,6 +2768,15 @@ type Mutation {

): AddDatasetEventResult!

"""
Looks up or creates (if necessary) a user associated with a given ORCID id and
adds it to the given program. No invitation is sent as a result of this
operation.
"""
addProgramUser(
input: AddProgramUserInput!
): AddProgramUserResult!

"""
Adds a sequence event associated with the given visit. Multiple events
will be produced during the execution of a sequence as it is started,
Expand Down Expand Up @@ -2872,14 +2881,6 @@ type Mutation {
input: CreateObservationInput!
): CreateObservationResult!

"""
Creates a user associated with a given ORCID id and adds it to the given
program.
"""
createPreAuthProgramUser(
input: CreatePreAuthProgramUserInput!
): CreatePreAuthProgramUserResult!

"""
Creates a new program according to provided properties
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ trait BaseMapping[F[_]]
lazy val AddAtomEventResultType = schema.ref("AddAtomEventResult")
lazy val AddConditionsEntryResultType = schema.ref("AddConditionsEntryResult")
lazy val AddDatasetEventResultType = schema.ref("AddDatasetEventResult")
lazy val AddProgramUserResultType = schema.ref("AddProgramUserResult")
lazy val AddSequenceEventResultType = schema.ref("AddSequenceEventResult")
lazy val AddSlewEventResultType = schema.ref("AddSlewEventResult")
lazy val AddStepEventResultType = schema.ref("AddStepEventResult")
Expand Down Expand Up @@ -77,7 +78,6 @@ trait BaseMapping[F[_]]
lazy val CreateCallForProposalsResultType = schema.ref("CreateCallForProposalsResult")
lazy val CreateGroupResultType = schema.ref("CreateGroupResult")
lazy val CreateObservationResultType = schema.ref("CreateObservationResult")
lazy val CreatePreAuthProgramUserResultType = schema.ref("CreatePreAuthProgramUserResult")
lazy val CreateProgramResultType = schema.ref("CreateProgramResult")
lazy val CreateProposalResultType = schema.ref("CreateProposalResult")
lazy val CreateTargetResultType = schema.ref("CreateTargetResult")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ object OdbMapping {
with CreateCallForProposalsResultMapping[F]
with CreateGroupResultMapping[F]
with CreateObservationResultMapping[F]
with CreatePreAuthProgramUserResultMapping[F]
with AddProgramUserResultMapping[F]
with CreateProgramResultMapping[F]
with CreateProposalResultMapping[F]
with CreateTargetResultMapping[F]
Expand Down Expand Up @@ -331,7 +331,7 @@ object OdbMapping {
CreateCallForProposalsResultMapping,
CreateGroupResultMapping,
CreateObservationResultMapping,
CreatePreAuthProgramUserResultMapping,
AddProgramUserResultMapping,
CreateProgramResultMapping,
CreateProposalResultMapping,
CreateTargetResultMapping,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ import lucuma.core.model.Program
import lucuma.core.syntax.string.toScreamingSnakeCase
import lucuma.odb.graphql.binding.*

case class CreatePreAuthProgramUserInput(
case class AddProgramUserInput(
orcidId: OrcidId,
programId: Program.Id,
role: ProgramUserRole,
SET: Option[ProgramUserPropertiesInput]
)

object CreatePreAuthProgramUserInput:
object AddProgramUserInput:
def ensuringCoi(role: ProgramUserRole): Result[ProgramUserRole] =
role match
case ProgramUserRole.Coi | ProgramUserRole.CoiRO =>
role.success
case _ =>
Result.failure(s"Only co-investigators who have not accepted an invitation may be linked via this method, not ${role.tag.toScreamingSnakeCase}")
Result.failure(s"Only co-investigators who have not accepted an invitation may be added via this method, not ${role.tag.toScreamingSnakeCase}")

val Binding: Matcher[CreatePreAuthProgramUserInput] =
val Binding: Matcher[AddProgramUserInput] =
ObjectFieldsBinding.rmap:
case List(
OrcidIdBinding("orcidId", rOrcidId),
Expand All @@ -40,4 +40,4 @@ object CreatePreAuthProgramUserInput:
rProgramId,
rRole.flatMap(ensuringCoi),
rProps
).parMapN(CreatePreAuthProgramUserInput.apply)
).parMapN(AddProgramUserInput.apply)
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import grackle.skunk.SkunkMapping

import table.ProgramUserTable

trait CreatePreAuthProgramUserResultMapping[F[_]] extends ProgramUserTable[F]:
trait AddProgramUserResultMapping[F[_]] extends ProgramUserTable[F]:

lazy val CreatePreAuthProgramUserResultMapping: ObjectMapping =
ObjectMapping(CreatePreAuthProgramUserResultType)(
lazy val AddProgramUserResultMapping: ObjectMapping =
ObjectMapping(AddProgramUserResultType)(
SqlField("programId", ProgramUserTable.ProgramId, key = true, hidden = true),
SqlField("userId", ProgramUserTable.UserId, key = true, hidden = true),
SqlObject("programUser")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import lucuma.odb.data.OdbErrorExtensions.asFailure
import lucuma.odb.graphql.binding.*
import lucuma.odb.graphql.input.AddAtomEventInput
import lucuma.odb.graphql.input.AddDatasetEventInput
import lucuma.odb.graphql.input.AddProgramUserInput
import lucuma.odb.graphql.input.AddSequenceEventInput
import lucuma.odb.graphql.input.AddSlewEventInput
import lucuma.odb.graphql.input.AddStepEventInput
Expand All @@ -61,7 +62,6 @@ import lucuma.odb.graphql.input.CreateCallForProposalsInput
import lucuma.odb.graphql.input.CreateConfigurationRequestInput
import lucuma.odb.graphql.input.CreateGroupInput
import lucuma.odb.graphql.input.CreateObservationInput
import lucuma.odb.graphql.input.CreatePreAuthProgramUserInput
import lucuma.odb.graphql.input.CreateProgramInput
import lucuma.odb.graphql.input.CreateProposalInput
import lucuma.odb.graphql.input.CreateTargetInput
Expand Down Expand Up @@ -117,6 +117,7 @@ trait MutationMapping[F[_]] extends Predicates[F] {
AddConditionsEntry,
AddAtomEvent,
AddDatasetEvent,
AddProgramUser,
AddSequenceEvent,
AddSlewEvent,
AddStepEvent,
Expand All @@ -128,7 +129,6 @@ trait MutationMapping[F[_]] extends Predicates[F] {
CreateConfigurationRequest,
CreateGroup,
CreateObservation,
CreatePreAuthProgramUser,
CreateProgram,
CreateProposal,
CreateTarget,
Expand Down Expand Up @@ -332,6 +332,16 @@ trait MutationMapping[F[_]] extends Predicates[F] {
chronicleService.addConditionsEntry(input).nestMap: id =>
Filter(Predicates.addConditionsEntyResult.conditionsEntry.id.eql(id), child)

private lazy val AddProgramUser: MutationField =
MutationField("addProgramUser", AddProgramUserInput.Binding): (input, child) =>
services.useNonTransactionally:
programUserService.addProgramUser(ssoGraphQlClient, input).map: r =>
r.map: (pid, uid) =>
Unique(Filter(Predicate.And(
Predicates.programUser.programId.eql(pid),
Predicates.programUser.userId.eql(uid)
), child))

private lazy val AddTimeChargeCorrection: MutationField =
MutationField("addTimeChargeCorrection", AddTimeChargeCorrectionInput.Binding): (input, child) =>
services.useTransactionally:
Expand Down Expand Up @@ -403,16 +413,6 @@ trait MutationMapping[F[_]] extends Predicates[F] {
observationService.createObservation(input).nestMap: oid =>
Unique(Filter(Predicates.observation.id.eql(oid), child))

private lazy val CreatePreAuthProgramUser: MutationField =
MutationField("createPreAuthProgramUser", CreatePreAuthProgramUserInput.Binding): (input, child) =>
services.useNonTransactionally:
programUserService.createPreAuthUser(ssoGraphQlClient, input).map: r =>
r.map: (pid, uid) =>
Unique(Filter(Predicate.And(
Predicates.programUser.programId.eql(pid),
Predicates.programUser.userId.eql(uid)
), child))

private lazy val CreateProgram =
MutationField("createProgram", CreateProgramInput.Binding) { (input, child) =>
services.useTransactionally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import lucuma.core.model.User
import lucuma.odb.data.OdbError
import lucuma.odb.data.OdbErrorExtensions.*
import lucuma.odb.data.UserType
import lucuma.odb.graphql.input.CreatePreAuthProgramUserInput
import lucuma.odb.graphql.input.AddProgramUserInput
import lucuma.odb.graphql.input.ProgramUserPropertiesInput
import lucuma.odb.graphql.input.UnlinkUserInput
import lucuma.odb.util.Codecs.educational_status
Expand Down Expand Up @@ -71,9 +71,9 @@ trait ProgramUserService[F[_]]:
which: AppliedFragment
)(using Transaction[F]): F[Result[List[(Program.Id, User.Id)]]]

def createPreAuthUser(
def addProgramUser(
sso: SsoGraphQlClient[F],
input: CreatePreAuthProgramUserInput
input: AddProgramUserInput
)(using NoTransaction[F]): F[Result[(Program.Id, User.Id)]]

/** Check to see if the user has access to the given program. */
Expand Down Expand Up @@ -191,9 +191,9 @@ object ProgramUserService:
session.prepareR(af.fragment.query(program_id *: user_id)).use: pq =>
pq.stream(af.argument, chunkSize = 1024).compile.toList.map(_.success)

override def createPreAuthUser(
override def addProgramUser(
sso: SsoGraphQlClient[F],
input: CreatePreAuthProgramUserInput
input: AddProgramUserInput
)(using NoTransaction[F]): F[Result[(Program.Id, User.Id)]] =
val set0 = input.SET.getOrElse(ProgramUserPropertiesInput.Empty)
val link = set0.partnerLink.getOrElse(PartnerLink.HasUnspecifiedPartner)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import lucuma.core.model.PartnerLink
import lucuma.core.model.User
import lucuma.core.model.UserInvitation

class createPreAuthProgramUser extends OdbSuite:
class addProgramUser extends OdbSuite:
val pi = TestUsers.Standard.pi(1, 30)
val pa0 = TestUsers.Standard.pi(100L, 100L)
val pa1 = TestUsers.Standard.pi(101L, 101L)
Expand All @@ -23,13 +23,13 @@ class createPreAuthProgramUser extends OdbSuite:

override val httpRequestHandler = invitationEmailRequestHandler

test("createPreAuthProgramUser"):
test("addProgramUser"):
createProgramAs(pi).flatMap: pid =>
expect(
user = pi,
query = s"""
mutation {
createPreAuthProgramUser(
addProgramUser(
input: {
orcidId: "${TestUsers.orcidId(100L).value}"
programId: "$pid"
Expand Down Expand Up @@ -71,7 +71,7 @@ class createPreAuthProgramUser extends OdbSuite:
""",
expected = json"""
{
"createPreAuthProgramUser": {
"addProgramUser": {
"programUser": {
"role": "COI",
"partnerLink": {
Expand All @@ -93,13 +93,13 @@ class createPreAuthProgramUser extends OdbSuite:
""".asRight
)

test("createPreAuthProgramUser: illegal role"):
test("addProgramUser: illegal role"):
createProgramAs(pi).flatMap: pid =>
expect(
user = pi,
query = s"""
mutation {
createPreAuthProgramUser(
addProgramUser(
input: {
orcidId: "${TestUsers.orcidId(100L).value}"
programId: "$pid"
Expand All @@ -113,18 +113,18 @@ class createPreAuthProgramUser extends OdbSuite:
}
""",
expected = List(
"Argument 'input' is invalid: Only co-investigators who have not accepted an invitation may be linked via this method, not PI"
"Argument 'input' is invalid: Only co-investigators who have not accepted an invitation may be added via this method, not PI"
).asLeft
)

test("createPreAuthProgramUser: redeem after added"):
test("addProgramUser: redeem after added"):
for
pid <- createProgramAs(pi)
inv <- createUserInvitationAs(pi, pid, ProgramUserRole.Coi, PartnerLink.HasPartner(Partner.CL))
uid <- query(user = pi,
s"""
mutation {
createPreAuthProgramUser(
addProgramUser(
input: {
orcidId: "${TestUsers.orcidId(101L).value}"
programId: "$pid"
Expand All @@ -141,8 +141,8 @@ class createPreAuthProgramUser extends OdbSuite:
}
"""
).map: json =>
json.hcursor.downFields("createPreAuthProgramUser", "programUser", "user", "id").require[User.Id]
// Since the user was added explicitly with createPreAuthProgramUser,
json.hcursor.downFields("addProgramUser", "programUser", "user", "id").require[User.Id]
// Since the user was added explicitly with addProgramUser,
// when they accept the invitation there will already be a link.
_ <- expectIor(
user = pa1,
Expand Down

0 comments on commit d467f59

Please sign in to comment.