Skip to content

Commit

Permalink
Merge pull request #2425 from constantine2nd/develop
Browse files Browse the repository at this point in the history
User invitation tests
  • Loading branch information
simonredfern authored Sep 19, 2024
2 parents fb6620a + 3e7f835 commit 75def15
Show file tree
Hide file tree
Showing 11 changed files with 296 additions and 53 deletions.
4 changes: 2 additions & 2 deletions obp-api/src/main/scala/code/api/util/NewStyle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ object NewStyle extends MdcLoggable{
}
def getUserInvitation(bankId: BankId, secretLink: Long, callContext: Option[CallContext]): OBPReturnType[UserInvitation] = Future {
val response: Box[UserInvitation] = UserInvitationProvider.userInvitationProvider.vend.getUserInvitation(bankId, secretLink)
(unboxFullOrFail(response, callContext, s"$CannotGetUserInvitation", 400), callContext)
(unboxFullOrFail(response, callContext, s"$CannotGetUserInvitation", 404), callContext)
}
def getUserInvitations(bankId: BankId, callContext: Option[CallContext]): OBPReturnType[List[UserInvitation]] = Future {
val response = UserInvitationProvider.userInvitationProvider.vend.getUserInvitations(bankId)
Expand All @@ -852,7 +852,7 @@ object NewStyle extends MdcLoggable{
}
}
def getAgreementByUserId(userId: String, agreementType: String, callContext: Option[CallContext]): Future[Box[UserAgreement]] = {
Future(UserAgreementProvider.userAgreementProvider.vend.getUserAgreement(userId, agreementType))
Future(UserAgreementProvider.userAgreementProvider.vend.getLastUserAgreement(userId, agreementType))
}

def getEntitlementsByBankId(bankId: String, callContext: Option[CallContext]): Future[List[Entitlement]] = {
Expand Down
5 changes: 3 additions & 2 deletions obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3869,16 +3869,17 @@ trait APIMethods400 extends MdcLoggable {
"POST",
"/banks/BANK_ID/user-invitations",
"Get User Invitation Information",
s"""Create User Invitation Information.
s"""Get User Invitation Information.
|
|${authenticationRequiredMessage(false)}
|""",
PostUserInvitationAnonymousJsonV400(secret_key = 5819479115482092878L),
userInvitationJsonV400,
List(
UserNotLoggedIn,
$BankNotFound,
UserCustomerLinksNotFoundForUser,
CannotGetUserInvitation,
CannotFindUserInvitation,
UnknownError
),
List(apiTagUserInvitation, apiTagKyc)
Expand Down
8 changes: 4 additions & 4 deletions obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -686,9 +686,9 @@ import net.liftweb.util.Helpers._
val privacyPolicyValue: String = getWebUiPropsValue("webui_privacy_policy", "")
val termsAndConditionsValue: String = getWebUiPropsValue("webui_terms_and_conditions", "")
// User Agreement table
UserAgreementProvider.userAgreementProvider.vend.createOrUpdateUserAgreement(
UserAgreementProvider.userAgreementProvider.vend.createUserAgreement(
theUser.user.foreign.map(_.userId).getOrElse(""), "privacy_conditions", privacyPolicyValue)
UserAgreementProvider.userAgreementProvider.vend.createOrUpdateUserAgreement(
UserAgreementProvider.userAgreementProvider.vend.createUserAgreement(
theUser.user.foreign.map(_.userId).getOrElse(""), "terms_and_conditions", termsAndConditionsValue)
if (!skipEmailValidation) {
sendValidationEmail(theUser)
Expand Down Expand Up @@ -1041,13 +1041,13 @@ def restoreSomeSessions(): Unit = {
def redirectUri(user: Box[ResourceUser]): String = {
val userId = user.map(_.userId).getOrElse("")
val hashedAgreementTextOfUser =
UserAgreementProvider.userAgreementProvider.vend.getUserAgreement(userId, "terms_and_conditions")
UserAgreementProvider.userAgreementProvider.vend.getLastUserAgreement(userId, "terms_and_conditions")
.map(_.agreementHash).getOrElse(HashUtil.Sha256Hash("not set"))
val agreementText = getWebUiPropsValue("webui_terms_and_conditions", "not set")
val hashedAgreementText = HashUtil.Sha256Hash(agreementText)
if(hashedAgreementTextOfUser == hashedAgreementText) { // Check terms and conditions
val hashedAgreementTextOfUser =
UserAgreementProvider.userAgreementProvider.vend.getUserAgreement(userId, "privacy_conditions")
UserAgreementProvider.userAgreementProvider.vend.getLastUserAgreement(userId, "privacy_conditions")
.map(_.agreementHash).getOrElse(HashUtil.Sha256Hash("not set"))
val agreementText = getWebUiPropsValue("webui_privacy_policy", "not set")
val hashedAgreementText = HashUtil.Sha256Hash(agreementText)
Expand Down
2 changes: 1 addition & 1 deletion obp-api/src/main/scala/code/snippet/PrivacyPolicy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class PrivacyPolicy extends MdcLoggable {
private def updateUserAgreement() = {
if(AuthUser.currentUser.isDefined) {
val agreementText = getWebUiPropsValue("webui_privacy_policy", "not set")
UserAgreementProvider.userAgreementProvider.vend.createOrUpdateUserAgreement(
UserAgreementProvider.userAgreementProvider.vend.createUserAgreement(
AuthUser.currentUser.flatMap(_.user.foreign.map(_.userId)).getOrElse(""), "privacy_conditions", agreementText)
S.redirectTo("/")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class TermsAndConditions extends MdcLoggable {
if(AuthUser.currentUser.isDefined) {
val agreementText = getWebUiPropsValue("webui_terms_and_conditions", "not set")
// val hashedAgreementText = HashUtil.Sha256Hash(agreementText)
UserAgreementProvider.userAgreementProvider.vend.createOrUpdateUserAgreement(
UserAgreementProvider.userAgreementProvider.vend.createUserAgreement(
AuthUser.currentUser.flatMap(_.user.foreign.map(_.userId)).getOrElse(""),
"terms_and_conditions",
agreementText)
Expand Down
14 changes: 7 additions & 7 deletions obp-api/src/main/scala/code/snippet/UserInvitation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ class UserInvitation extends MdcLoggable {
showError(msg)
case _ =>
// User Agreement table
UserAgreementProvider.userAgreementProvider.vend.createOrUpdateUserAgreement(
UserAgreementProvider.userAgreementProvider.vend.createUserAgreement(
u.userId, "privacy_conditions", privacyConditionsValue)
UserAgreementProvider.userAgreementProvider.vend.createOrUpdateUserAgreement(
UserAgreementProvider.userAgreementProvider.vend.createUserAgreement(
u.userId, "terms_and_conditions", termsAndConditionsValue)
UserAgreementProvider.userAgreementProvider.vend.createOrUpdateUserAgreement(
UserAgreementProvider.userAgreementProvider.vend.createUserAgreement(
u.userId, "accept_marketing_info", marketingInfoCheckboxVar.is.toString)
UserAgreementProvider.userAgreementProvider.vend.createOrUpdateUserAgreement(
UserAgreementProvider.userAgreementProvider.vend.createUserAgreement(
u.userId, "consent_for_collecting_personal_data", consentForCollectingCheckboxVar.is.toString)
// Set the status of the user invitation to "FINISHED"
UserInvitationProvider.userInvitationProvider.vend.updateStatusOfUserInvitation(userInvitation.map(_.userInvitationId).getOrElse(""), "FINISHED")
Expand Down Expand Up @@ -187,9 +187,9 @@ class UserInvitation extends MdcLoggable {
"#companyName" #> SHtml.text(companyVar.is, companyVar(_)) &
"#devEmail" #> SHtml.text(devEmailVar, devEmailVar(_)) &
"#username" #> SHtml.text(usernameVar, usernameVar(_)) &
"#privacy_checkbox" #> SHtml.checkbox(privacyCheckboxVar, privacyCheckboxVar(_)) &
"#terms_checkbox" #> SHtml.checkbox(termsCheckboxVar, termsCheckboxVar(_)) &
"#marketing_info_checkbox" #> SHtml.checkbox(marketingInfoCheckboxVar, marketingInfoCheckboxVar(_)) &
"#user_invitation_privacy_checkbox" #> SHtml.checkbox(privacyCheckboxVar, privacyCheckboxVar(_), "id" -> "user_invitation_privacy_checkbox") &
"#user_invitation_terms_checkbox" #> SHtml.checkbox(termsCheckboxVar, termsCheckboxVar(_), "id" -> "user_invitation_terms_checkbox") &
"#marketing_info_checkbox" #> SHtml.checkbox(marketingInfoCheckboxVar, marketingInfoCheckboxVar(_), "id" -> "marketing_info_checkbox") &
"#consent_for_collecting_checkbox" #> SHtml.checkbox(consentForCollectingCheckboxVar, consentForCollectingCheckboxVar(_), "id" -> "consent_for_collecting_checkbox") &
"#consent_for_collecting_mandatory" #> SHtml.checkbox(consentForCollectingMandatoryCheckboxVar, consentForCollectingMandatoryCheckboxVar(_), "id" -> "consent_for_collecting_mandatory", "hidden" -> "true") &
"type=submit" #> SHtml.submit(s"$registrationConsumerButtonValue", () => submitButtonDefense)
Expand Down
6 changes: 3 additions & 3 deletions obp-api/src/main/scala/code/users/LiftUsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ object LiftUsers extends Users with MdcLoggable{
}

private def getUserAgreements(user: ResourceUser) = {
val acceptMarketingInfo = UserAgreementProvider.userAgreementProvider.vend.getUserAgreement(user.userId, "accept_marketing_info")
val termsAndConditions = UserAgreementProvider.userAgreementProvider.vend.getUserAgreement(user.userId, "terms_and_conditions")
val privacyConditions = UserAgreementProvider.userAgreementProvider.vend.getUserAgreement(user.userId, "privacy_conditions")
val acceptMarketingInfo = UserAgreementProvider.userAgreementProvider.vend.getLastUserAgreement(user.userId, "accept_marketing_info")
val termsAndConditions = UserAgreementProvider.userAgreementProvider.vend.getLastUserAgreement(user.userId, "terms_and_conditions")
val privacyConditions = UserAgreementProvider.userAgreementProvider.vend.getLastUserAgreement(user.userId, "privacy_conditions")
val agreements = acceptMarketingInfo.toList ::: termsAndConditions.toList ::: privacyConditions.toList
agreements
}
Expand Down
28 changes: 1 addition & 27 deletions obp-api/src/main/scala/code/users/UserAgreement.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,6 @@ import net.liftweb.mapper._
import net.liftweb.common.Box.tryo

object MappedUserAgreementProvider extends UserAgreementProvider {
// TODO Change the function name
override def createOrUpdateUserAgreement(userId: String, agreementType: String, agreementText: String): Box[UserAgreement] = {
UserAgreement.find(
By(UserAgreement.UserId, userId),
By(UserAgreement.AgreementType, agreementType)
) match {
// TODO We should be adding an additional record. Not changing existing one.
case Full(existingUser) =>
Full(
existingUser
.AgreementType(agreementType)
.AgreementText(agreementText)
.saveMe()
)
case Empty =>
Full(
UserAgreement.create
.UserId(userId)
.AgreementType(agreementType)
.AgreementText(agreementText)
.Date(new Date)
.saveMe()
)
case everythingElse => everythingElse
}
}
override def createUserAgreement(userId: String, agreementType: String, agreementText: String): Box[UserAgreement] = {
Full(
UserAgreement.create
Expand All @@ -46,7 +20,7 @@ object MappedUserAgreementProvider extends UserAgreementProvider {
.saveMe()
)
}
override def getUserAgreement(userId: String, agreementType: String): Box[UserAgreement] = {
override def getLastUserAgreement(userId: String, agreementType: String): Box[UserAgreement] = {
UserAgreement.findAll(
By(UserAgreement.UserId, userId),
By(UserAgreement.AgreementType, agreementType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ object UserAgreementProvider extends SimpleInjector {
}

trait UserAgreementProvider {
def createOrUpdateUserAgreement(userId: String, agreementType: String, agreementText: String): Box[UserAgreement]
def createUserAgreement(userId: String, agreementType: String, agreementText: String): Box[UserAgreement]
def getUserAgreement(userId: String, agreementType: String): Box[UserAgreement]
def getLastUserAgreement(userId: String, agreementType: String): Box[UserAgreement]
}

trait UserAgreementTrait {
Expand Down
8 changes: 4 additions & 4 deletions obp-api/src/main/webapp/user-invitation.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ <h1>Complete your user invitation</h1>
<summary style="display:list-item;"><a class="api_group_name">Privacy Policy</a></summary>
<div id="privacy-policy-page" data-lift="WebUI.privacyPolicyText"></div>
</details>
<input id="privacy_checkbox" type="checkbox" class="form-check-input">
<label class="form-check-label" for="privacy_checkbox">I agree to the above privacy conditions</label>
<input id="user_invitation_privacy_checkbox" type="checkbox" class="form-check-input">
<label class="form-check-label" for="user_invitation_privacy_checkbox">I agree to the above privacy conditions</label>
</div>
<hr>
<div class="form-group" id="terms-and-conditions-div" onclick="enableDisableUserInvitationButton()">
<details open style="cursor:s-resize;">
<summary style="display:list-item;"><a class="api_group_name">Terms and Conditions</a></summary>
<div id="terms-and-conditions-page" data-lift="WebUI.termsAndConditionsText"></div>
</details>
<input type="checkbox" class="form-check-input" id="terms_checkbox" >
<label id="terms_checkbox_value" class="form-check-label" for="terms_checkbox">I agree to the above Developer Terms and Conditions</label>
<input type="checkbox" class="form-check-input" id="user_invitation_terms_checkbox" >
<label id="terms_checkbox_value" class="form-check-label" for="user_invitation_terms_checkbox">I agree to the above Developer Terms and Conditions</label>
</div>
<hr>
<div class="form-group">
Expand Down
Loading

0 comments on commit 75def15

Please sign in to comment.