Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "[ID-1351] store and retrieve user attributes with Sam (#1523)" #1556

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<include file="changesets/20240417_action_managed_identities.xml" relativeToChangelogFile="true"/>
<include file="changesets/20240416_add_sam_rac_tables.xml" relativeToChangelogFile="true"/>
<include file="changesets/20240701_add_group_version_and_last_synchronized_version.xml" relativeToChangelogFile="true"/>
<include file="changesets/20240806_add_profile_info_table.xml" relativeToChangelogFile="true"/>
<include file="changesets/20240809_sam_user_favorite_resources_table.xml" relativeToChangelogFile="true"/>
<include file="changesets/20240820_descendant_auth_domains.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1355,57 +1355,11 @@ class PostgresDirectoryDAO(protected val writeDbRef: DbReference, protected val
val userAttributesTable = UserAttributesTable.syntax
val userAttributesColumns = UserAttributesTable.column
samsql"""
insert into ${UserAttributesTable as userAttributesTable} (
${userAttributesColumns.samUserId},
${userAttributesColumns.marketingConsent},
${userAttributesColumns.firstName},
${userAttributesColumns.lastName},
${userAttributesColumns.organization},
${userAttributesColumns.contactEmail},
${userAttributesColumns.title},
${userAttributesColumns.department},
${userAttributesColumns.interestInTerra},
${userAttributesColumns.programLocationCity},
${userAttributesColumns.programLocationState},
${userAttributesColumns.programLocationCountry},
${userAttributesColumns.researchArea},
${userAttributesColumns.additionalAttributes},
${userAttributesColumns.createdAt},
${userAttributesColumns.updatedAt}
) values (
${userAttributes.userId},
${userAttributes.marketingConsent},
${userAttributes.firstName},
${userAttributes.lastName},
${userAttributes.organization},
${userAttributes.contactEmail},
${userAttributes.title},
${userAttributes.department},
ARRAY[${userAttributes.interestInTerra.getOrElse(Array.empty[String])}]::text[],
${userAttributes.programLocationCity},
${userAttributes.programLocationState},
${userAttributes.programLocationCountry},
ARRAY[${userAttributes.researchArea.getOrElse(Array.empty[String])}]::text[],
${userAttributes.additionalAttributes.getOrElse("{}")}::jsonb,
${Instant.now()},
${Instant.now()}
)
insert into ${UserAttributesTable as userAttributesTable} (${userAttributesColumns.samUserId}, ${userAttributesColumns.marketingConsent}, ${userAttributesColumns.updatedAt})
values (${userAttributes.userId}, ${userAttributes.marketingConsent}, ${Instant.now()})
on conflict(${userAttributesColumns.samUserId})
do update set
${userAttributesColumns.marketingConsent} = ${userAttributes.marketingConsent},
${userAttributesColumns.firstName} = ${userAttributes.firstName},
${userAttributesColumns.lastName} = ${userAttributes.lastName},
${userAttributesColumns.organization} = ${userAttributes.organization},
${userAttributesColumns.contactEmail} = ${userAttributes.contactEmail},
${userAttributesColumns.title} = ${userAttributes.title},
${userAttributesColumns.department} = ${userAttributes.department},
${userAttributesColumns.interestInTerra} = ARRAY[${userAttributes.interestInTerra.getOrElse(Array.empty[String])}]::text[],
${userAttributesColumns.programLocationCity} = ${userAttributes.programLocationCity},
${userAttributesColumns.programLocationState} = ${userAttributes.programLocationState},
${userAttributesColumns.programLocationCountry} = ${userAttributes.programLocationCountry},
${userAttributesColumns.researchArea} = ARRAY[${userAttributes.researchArea.getOrElse(Array.empty[String])}]::text[],
${userAttributesColumns.additionalAttributes} = ${userAttributes.additionalAttributes.getOrElse("{}")}::jsonb,
${userAttributesColumns.updatedAt} = ${Some(Instant.now())}
do update set ${userAttributesColumns.marketingConsent} = ${userAttributes.marketingConsent},
${userAttributesColumns.updatedAt} = ${Instant.now()}
""".update().apply() > 0
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ import org.broadinstitute.dsde.workbench.sam.model._
import scalikejdbc.TypeBinder

object SamTypeBinders {
implicit val optionListStringTypeBinder: TypeBinder[Option[List[String]]] = new TypeBinder[Option[List[String]]] {
def apply(rs: ResultSet, label: String): Option[List[String]] =
Option(rs.getArray(label)).map(_.getArray.asInstanceOf[Array[String]].toList)
def apply(rs: ResultSet, index: Int): Option[List[String]] =
Option(rs.getArray(index)).map(_.getArray.asInstanceOf[Array[String]].toList)
}

implicit val accessInstructionsPKTypeBinder: TypeBinder[AccessInstructionsPK] = new TypeBinder[AccessInstructionsPK] {
def apply(rs: ResultSet, label: String): AccessInstructionsPK = AccessInstructionsPK(rs.getLong(label))
def apply(rs: ResultSet, index: Int): AccessInstructionsPK = AccessInstructionsPK(rs.getLong(index))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,13 @@ import org.broadinstitute.dsde.workbench.model._
import org.broadinstitute.dsde.workbench.sam.db.SamTypeBinders
import org.broadinstitute.dsde.workbench.sam.model.api.SamUserAttributes
import scalikejdbc._

import java.time.Instant

final case class UserAttributesRecord(
samUserId: WorkbenchUserId,
marketingConsent: Boolean,
firstName: Option[String],
lastName: Option[String],
organization: Option[String],
contactEmail: Option[String],
title: Option[String],
department: Option[String],
interestInTerra: Option[List[String]],
programLocationCity: Option[String],
programLocationState: Option[String],
programLocationCountry: Option[String],
researchArea: Option[List[String]],
additionalAttributes: Option[String],
createdAt: Option[Instant],
updatedAt: Option[Instant]
updatedAt: Instant
)

object UserAttributesTable extends SQLSyntaxSupportWithDefaultSamDB[UserAttributesRecord] {
Expand All @@ -32,19 +20,6 @@ object UserAttributesTable extends SQLSyntaxSupportWithDefaultSamDB[UserAttribut
def apply(e: ResultName[UserAttributesRecord])(rs: WrappedResultSet): UserAttributesRecord = UserAttributesRecord(
rs.get(e.samUserId),
rs.get(e.marketingConsent),
rs.get(e.firstName),
rs.get(e.lastName),
rs.get(e.organization),
rs.get(e.contactEmail),
rs.get(e.title),
rs.get(e.department),
rs.get(e.interestInTerra),
rs.get(e.programLocationCity),
rs.get(e.programLocationState),
rs.get(e.programLocationCountry),
rs.get(e.researchArea),
rs.get(e.additionalAttributes),
rs.get(e.createdAt),
rs.get(e.updatedAt)
)

Expand All @@ -53,20 +28,6 @@ object UserAttributesTable extends SQLSyntaxSupportWithDefaultSamDB[UserAttribut
def unmarshalUserAttributesRecord(userAttributesRecord: UserAttributesRecord): SamUserAttributes =
SamUserAttributes(
userAttributesRecord.samUserId,
userAttributesRecord.marketingConsent,
userAttributesRecord.firstName,
userAttributesRecord.lastName,
userAttributesRecord.organization,
userAttributesRecord.contactEmail,
userAttributesRecord.title,
userAttributesRecord.department,
userAttributesRecord.interestInTerra,
userAttributesRecord.programLocationCity,
userAttributesRecord.programLocationState,
userAttributesRecord.programLocationCountry,
userAttributesRecord.researchArea,
userAttributesRecord.additionalAttributes,
userAttributesRecord.createdAt,
userAttributesRecord.updatedAt
userAttributesRecord.marketingConsent
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,91 +5,25 @@ import akka.http.scaladsl.model.StatusCodes
import cats.effect.IO
import org.broadinstitute.dsde.workbench.model.WorkbenchIdentityJsonSupport.WorkbenchUserIdFormat
import org.broadinstitute.dsde.workbench.model.{ErrorReport, WorkbenchExceptionWithErrorReport, WorkbenchUserId}
import spray.json.DefaultJsonProtocol.jsonFormat2
import spray.json.DefaultJsonProtocol._
import spray.json.RootJsonFormat
import org.broadinstitute.dsde.workbench.model.google.GoogleModelJsonSupport.InstantFormat

import java.time.Instant

object SamUserAttributes {
implicit val SamUserAttributesFormat: RootJsonFormat[SamUserAttributes] = jsonFormat16(SamUserAttributes.apply)
implicit val SamUserAttributesFormat: RootJsonFormat[SamUserAttributes] = jsonFormat2(SamUserAttributes.apply)

def newUserAttributesFromRequest(userId: WorkbenchUserId, userAttributesRequest: SamUserAttributesRequest): IO[SamUserAttributes] = {
val samUserAttributes = for {
marketingConsent <- userAttributesRequest.marketingConsent
firstName = userAttributesRequest.firstName
lastName = userAttributesRequest.lastName
organization = userAttributesRequest.organization
contactEmail = userAttributesRequest.contactEmail
title = userAttributesRequest.title
department = userAttributesRequest.department
interestInTerra = userAttributesRequest.interestInTerra
programLocationCity = userAttributesRequest.programLocationCity
programLocationState = userAttributesRequest.programLocationState
programLocationCountry = userAttributesRequest.programLocationCountry
researchArea = userAttributesRequest.researchArea
additionalAttributes = userAttributesRequest.additionalAttributes

} yield SamUserAttributes(
userId,
marketingConsent,
firstName,
lastName,
organization,
contactEmail,
title,
department,
interestInTerra,
programLocationCity,
programLocationState,
programLocationCountry,
researchArea,
additionalAttributes,
Some(Instant.now()),
Some(Instant.now())
)
} yield SamUserAttributes(userId, marketingConsent)
IO.fromOption(samUserAttributes)(
new WorkbenchExceptionWithErrorReport(ErrorReport(StatusCodes.BadRequest, s"Missing values required for new user attributes."))
)

}

}
final case class SamUserAttributes(
userId: WorkbenchUserId,
marketingConsent: Boolean,
firstName: Option[String],
lastName: Option[String],
organization: Option[String],
contactEmail: Option[String],
title: Option[String],
department: Option[String],
interestInTerra: Option[List[String]],
programLocationCity: Option[String],
programLocationState: Option[String],
programLocationCountry: Option[String],
researchArea: Option[List[String]],
additionalAttributes: Option[String],
createdAt: Option[Instant],
updatedAt: Option[Instant]
) {
def updateFromUserAttributesRequest(userId: WorkbenchUserId, userAttributesRequest: SamUserAttributesRequest): IO[SamUserAttributes] =
IO(
this.copy(
userId = userId,
marketingConsent = userAttributesRequest.marketingConsent.getOrElse(this.marketingConsent),
firstName = userAttributesRequest.firstName.orElse(this.firstName),
lastName = userAttributesRequest.lastName.orElse(this.lastName),
organization = userAttributesRequest.organization.orElse(this.organization),
contactEmail = userAttributesRequest.contactEmail.orElse(this.contactEmail),
title = userAttributesRequest.title.orElse(this.title),
department = userAttributesRequest.department.orElse(this.department),
interestInTerra = userAttributesRequest.interestInTerra.orElse(this.interestInTerra),
programLocationCity = userAttributesRequest.programLocationCity.orElse(this.programLocationCity),
programLocationState = userAttributesRequest.programLocationState.orElse(this.programLocationState),
programLocationCountry = userAttributesRequest.programLocationCountry.orElse(this.programLocationCountry),
researchArea = userAttributesRequest.researchArea.orElse(this.researchArea),
additionalAttributes = userAttributesRequest.additionalAttributes.orElse(this.additionalAttributes)
)
)
final case class SamUserAttributes(userId: WorkbenchUserId, marketingConsent: Boolean) {
def updateFromUserAttributesRequest(userAttributesRequest: SamUserAttributesRequest): IO[SamUserAttributes] =
IO(this.copy(marketingConsent = userAttributesRequest.marketingConsent.getOrElse(this.marketingConsent)))
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
package org.broadinstitute.dsde.workbench.sam
package model.api

import org.broadinstitute.dsde.workbench.model.WorkbenchIdentityJsonSupport.WorkbenchUserIdFormat
import org.broadinstitute.dsde.workbench.model.{ErrorReport, WorkbenchUserId}
import org.broadinstitute.dsde.workbench.model.ErrorReport
import spray.json.DefaultJsonProtocol.jsonFormat1
import spray.json.DefaultJsonProtocol._
import spray.json.RootJsonFormat

object SamUserAttributesRequest {
implicit val SamUserAttributesRequestFormat: RootJsonFormat[SamUserAttributesRequest] = jsonFormat14(SamUserAttributesRequest.apply)
implicit val SamUserAttributesRequestFormat: RootJsonFormat[SamUserAttributesRequest] = jsonFormat1(SamUserAttributesRequest.apply)

}
case class SamUserAttributesRequest(
userId: WorkbenchUserId,
marketingConsent: Option[Boolean],
firstName: Option[String],
lastName: Option[String],
organization: Option[String],
contactEmail: Option[String],
title: Option[String],
department: Option[String],
interestInTerra: Option[List[String]],
programLocationCity: Option[String],
programLocationState: Option[String],
programLocationCountry: Option[String],
researchArea: Option[List[String]],
additionalAttributes: Option[String]
marketingConsent: Option[Boolean]
) {
def validateForNewUser: Option[Seq[ErrorReport]] = Option(
Seq(
Expand Down
Loading
Loading