diff --git a/src/main/scala/code/accountholder/AccountHolders.scala b/src/main/scala/code/accountholder/AccountHolders.scala index 9a1fffe4c..6b35b145b 100644 --- a/src/main/scala/code/accountholder/AccountHolders.scala +++ b/src/main/scala/code/accountholder/AccountHolders.scala @@ -22,15 +22,14 @@ object AccountHolders extends SimpleInjector { } trait AccountHolders { + def getAccountHolders(bankId: BankId, accountId: AccountId): Set[User] def getAccountsHeld(bankId: BankId, user: User): Set[BankIdAccountId] - def createAccountHolder(userId: Long, bankId: String, accountId: String): Boolean def getOrCreateAccountHolder(user: User, bankAccountUID :BankIdAccountId): Box[MapperAccountHolders] //There is no AccountHolder trait, database structure different with view def bulkDeleteAllAccountHolders(): Box[Boolean] } class RemotedataAccountHoldersCaseClasses { - case class createAccountHolder(userId: Long, bankId: String, accountId: String) case class getAccountHolders(bankId: BankId, accountId: AccountId) case class getAccountsHeld(bankId: BankId, user: User) case class getOrCreateAccountHolder(user: User, bankAccountUID :BankIdAccountId) diff --git a/src/main/scala/code/accountholder/MapperAccountHolders.scala b/src/main/scala/code/accountholder/MapperAccountHolders.scala index 9b2093578..2e83604d6 100644 --- a/src/main/scala/code/accountholder/MapperAccountHolders.scala +++ b/src/main/scala/code/accountholder/MapperAccountHolders.scala @@ -30,25 +30,12 @@ object MapperAccountHolders extends MapperAccountHolders with AccountHolders wit override def dbIndexes = Index(accountBankPermalink, accountPermalink) :: Nil - def createAccountHolder(userId: Long, bankId: String, accountId: String): Boolean = { - val holder = MapperAccountHolders.create - .accountBankPermalink(bankId) - .accountPermalink(accountId) - .user(userId) - .saveMe - if(holder.saved_?) - true - else - false - } - - //Note, this method, will not check the existing of bankAccount, any value of BankIdAccountId //Can create the MapperAccountHolders. def getOrCreateAccountHolder(user: User, bankIdAccountId :BankIdAccountId): Box[MapperAccountHolders] ={ val mapperAccountHolder = MapperAccountHolders.find( - By(MapperAccountHolders.user, user.resourceUserId.value), + By(MapperAccountHolders.user, user.userPrimaryKey.value), By(MapperAccountHolders.accountBankPermalink, bankIdAccountId.bankId.value), By(MapperAccountHolders.accountPermalink, bankIdAccountId.accountId.value) ) @@ -64,7 +51,7 @@ object MapperAccountHolders extends MapperAccountHolders with AccountHolders wit val holder: MapperAccountHolders = MapperAccountHolders.create .accountBankPermalink(bankIdAccountId.bankId.value) .accountPermalink(bankIdAccountId.accountId.value) - .user(user.resourceUserId.value) + .user(user.userPrimaryKey.value) .saveMe logger.debug( s"getOrCreateAccountHolder--> create account holder: $holder" diff --git a/src/main/scala/code/api/UKOpenBanking/v2_0_0/JSONFactory_UKOpenBanking_200.scala b/src/main/scala/code/api/UKOpenBanking/v2_0_0/JSONFactory_UKOpenBanking_200.scala index 3a4540559..536109408 100644 --- a/src/main/scala/code/api/UKOpenBanking/v2_0_0/JSONFactory_UKOpenBanking_200.scala +++ b/src/main/scala/code/api/UKOpenBanking/v2_0_0/JSONFactory_UKOpenBanking_200.scala @@ -221,7 +221,7 @@ object JSONFactory_UKOpenBanking_200 { accounts.map(account => BalanceJsonUKV200( AccountId = account.accountId.value, Amount = AmountOfMoneyJsonV121(account.currency, account.balance.toString()), - CreditDebitIndicator = account.owners.headOption.getOrElse(null).name, + CreditDebitIndicator = account.userOwners.headOption.getOrElse(null).name, Type = "Credit", DateTime = null, CreditLine = List(CreditLineJson( diff --git a/src/main/scala/code/api/openidconnect.scala b/src/main/scala/code/api/openidconnect.scala index ce0b4229c..461e433f9 100644 --- a/src/main/scala/code/api/openidconnect.scala +++ b/src/main/scala/code/api/openidconnect.scala @@ -101,9 +101,9 @@ object OpenIdConnect extends OBPRestHelper with MdcLoggable { userEmail <- tryo{(json_user \ "email").extractOrElse[String]("")} auth_user: AuthUser <- AuthUser.find(By(AuthUser.email, userEmail)) resource_user: ResourceUser <- User.findResourceUserByResourceUserId(auth_user.user.get) - if emailVerified && resource_user.resourceUserId.value > 0 + if emailVerified && resource_user.userPrimaryKey.value > 0 } yield { - saveAuthorizationToken(accessToken, accessToken, resource_user.resourceUserId.value) + saveAuthorizationToken(accessToken, accessToken, resource_user.userPrimaryKey.value) httpCode = 200 message= String.format("oauth_token=%s&oauth_token_secret=%s", accessToken, accessToken) val headers = ("Content-type" -> "application/x-www-form-urlencoded") :: Nil diff --git a/src/main/scala/code/api/v1_2_1/APIMethods121.scala b/src/main/scala/code/api/v1_2_1/APIMethods121.scala index c89802b3d..2aa73f450 100644 --- a/src/main/scala/code/api/v1_2_1/APIMethods121.scala +++ b/src/main/scala/code/api/v1_2_1/APIMethods121.scala @@ -530,7 +530,7 @@ trait APIMethods121 { for { u <- cc.user ?~ UserNotLoggedIn account <- BankAccount(bankId, accountId) ?~! BankAccountNotFound - _ <- booleanToBox(u.hasOwnerViewAccess(BankIdAccountId(account.bankId, account.accountId)), UserNoOwnerView +"userId : " + u.resourceUserId + ". account : " + accountId) + _ <- booleanToBox(u.hasOwnerViewAccess(BankIdAccountId(account.bankId, account.accountId)), UserNoOwnerView +"userId : " + u.userId + ". account : " + accountId) views <- Full(Views.views.vend.viewsForAccount(BankIdAccountId(account.bankId, account.accountId))) } yield { val viewsJSON = JSONFactory.createViewsJSON(views) @@ -1864,7 +1864,7 @@ trait APIMethods121 { addCorpLocation <- Box(metadata.addCorporateLocation) ?~ {"the view " + viewId + "does not allow adding a corporate location"} corpLocationJson <- tryo{(json.extract[CorporateLocationJSON])} ?~ {InvalidJsonFormat} correctCoordinates <- checkIfLocationPossible(corpLocationJson.corporate_location.latitude, corpLocationJson.corporate_location.longitude) - added <- Counterparties.counterparties.vend.addCorporateLocation(other_account_id, u.resourceUserId, (now:TimeSpan), corpLocationJson.corporate_location.longitude, corpLocationJson.corporate_location.latitude) ?~ {"Corporate Location cannot be deleted"} + added <- Counterparties.counterparties.vend.addCorporateLocation(other_account_id, u.userPrimaryKey, (now:TimeSpan), corpLocationJson.corporate_location.longitude, corpLocationJson.corporate_location.latitude) ?~ {"Corporate Location cannot be deleted"} if(added) } yield { val successJson = SuccessMessage("corporate location added") @@ -1908,7 +1908,7 @@ trait APIMethods121 { addCorpLocation <- Box(metadata.addCorporateLocation) ?~ {"the view " + viewId + "does not allow updating a corporate location"} corpLocationJson <- tryo{(json.extract[CorporateLocationJSON])} ?~ {InvalidJsonFormat} correctCoordinates <- checkIfLocationPossible(corpLocationJson.corporate_location.latitude, corpLocationJson.corporate_location.longitude) - updated <- Counterparties.counterparties.vend.addCorporateLocation(other_account_id, u.resourceUserId, (now:TimeSpan), corpLocationJson.corporate_location.longitude, corpLocationJson.corporate_location.latitude) ?~ {"Corporate Location cannot be updated"} + updated <- Counterparties.counterparties.vend.addCorporateLocation(other_account_id, u.userPrimaryKey, (now:TimeSpan), corpLocationJson.corporate_location.longitude, corpLocationJson.corporate_location.latitude) ?~ {"Corporate Location cannot be updated"} if(updated) } yield { val successJson = SuccessMessage("corporate location updated") @@ -1995,7 +1995,7 @@ trait APIMethods121 { physicalLocationJson <- tryo{(json.extract[PhysicalLocationJSON])} ?~ {InvalidJsonFormat} correctCoordinates <- checkIfLocationPossible(physicalLocationJson.physical_location.latitude, physicalLocationJson.physical_location.longitude) correctCoordinates <- checkIfLocationPossible(physicalLocationJson.physical_location.latitude, physicalLocationJson.physical_location.longitude) - added <- Counterparties.counterparties.vend.addPhysicalLocation(other_account_id, u.resourceUserId, (now:TimeSpan), physicalLocationJson.physical_location.longitude, physicalLocationJson.physical_location.latitude) ?~ {"Physical Location cannot be added"} + added <- Counterparties.counterparties.vend.addPhysicalLocation(other_account_id, u.userPrimaryKey, (now:TimeSpan), physicalLocationJson.physical_location.longitude, physicalLocationJson.physical_location.latitude) ?~ {"Physical Location cannot be added"} if(added) } yield { val successJson = SuccessMessage("physical location added") @@ -2040,7 +2040,7 @@ trait APIMethods121 { physicalLocationJson <- tryo{(json.extract[PhysicalLocationJSON])} ?~ {InvalidJsonFormat} correctCoordinates <- checkIfLocationPossible(physicalLocationJson.physical_location.latitude, physicalLocationJson.physical_location.longitude) correctCoordinates <- checkIfLocationPossible(physicalLocationJson.physical_location.latitude, physicalLocationJson.physical_location.longitude) - updated <- Counterparties.counterparties.vend.addPhysicalLocation(other_account_id, u.resourceUserId, (now:TimeSpan), physicalLocationJson.physical_location.longitude, physicalLocationJson.physical_location.latitude) ?~ {"Physical Location cannot be updated"} + updated <- Counterparties.counterparties.vend.addPhysicalLocation(other_account_id, u.userPrimaryKey, (now:TimeSpan), physicalLocationJson.physical_location.longitude, physicalLocationJson.physical_location.latitude) ?~ {"Physical Location cannot be updated"} if(updated) } yield { val successJson = SuccessMessage("physical location updated") @@ -2413,7 +2413,7 @@ trait APIMethods121 { commentJson <- tryo{json.extract[PostTransactionCommentJSON]} ?~ {InvalidJsonFormat} metadata <- moderatedTransactionMetadata(bankId, accountId, viewId, transactionId, Full(u), Some(cc)) addCommentFunc <- Box(metadata.addComment) ?~ { s"$NoViewPermission can_add_comment. Current ViewId($viewId)" } - postedComment <- addCommentFunc(u.resourceUserId, viewId, commentJson.value, now) + postedComment <- addCommentFunc(u.userPrimaryKey, viewId, commentJson.value, now) } yield { successJsonResponse(Extraction.decompose(JSONFactory.createTransactionCommentJSON(postedComment)),201) } @@ -2525,7 +2525,7 @@ trait APIMethods121 { tagJson <- tryo{json.extract[PostTransactionTagJSON]} ?~ { s"$InvalidJsonFormat Check your Post Json Body." } metadata <- moderatedTransactionMetadata(bankId, accountId, viewId, transactionId, Full(u), Some(cc)) addTagFunc <- Box(metadata.addTag) ?~ { s"$NoViewPermission can_add_tag. Current ViewId($viewId)" } - postedTag <- addTagFunc(u.resourceUserId, viewId, tagJson.value, now) + postedTag <- addTagFunc(u.userPrimaryKey, viewId, tagJson.value, now) } yield { successJsonResponse(Extraction.decompose(JSONFactory.createTransactionTagJSON(postedTag)), 201) } @@ -2637,7 +2637,7 @@ trait APIMethods121 { metadata <- moderatedTransactionMetadata(bankId, accountId, viewId, transactionId, Full(u), Some(cc)) addImageFunc <- Box(metadata.addImage) ?~ { s"$NoViewPermission can_add_image. Current ViewId($viewId)" } url <- tryo{new URL(imageJson.URL)} ?~! s"$InvalidUrl Could not parse url string as a valid URL" - postedImage <- addImageFunc(u.resourceUserId, viewId, imageJson.label, now, url.toString) + postedImage <- addImageFunc(u.userPrimaryKey, viewId, imageJson.label, now, url.toString) } yield { successJsonResponse(Extraction.decompose(JSONFactory.createTransactionImageJSON(postedImage)),201) } @@ -2753,7 +2753,7 @@ trait APIMethods121 { addWhereTag <- Box(metadata.addWhereTag) ?~ { s"$NoViewPermission can_add_where_tag. Current ViewId($viewId)" } whereJson <- tryo{(json.extract[PostTransactionWhereJSON])} ?~ {InvalidJsonFormat} correctCoordinates <- checkIfLocationPossible(whereJson.where.latitude, whereJson.where.longitude) - if(addWhereTag(u.resourceUserId, viewId, now, whereJson.where.longitude, whereJson.where.latitude)) + if(addWhereTag(u.userPrimaryKey, viewId, now, whereJson.where.longitude, whereJson.where.latitude)) } yield { val successJson = SuccessMessage("where tag added") successJsonResponse(Extraction.decompose(successJson), 201) @@ -2797,7 +2797,7 @@ trait APIMethods121 { addWhereTag <- Box(metadata.addWhereTag) ?~ { s"$NoViewPermission can_add_where_tag. Current ViewId($viewId)" } whereJson <- tryo{(json.extract[PostTransactionWhereJSON])} ?~ {InvalidJsonFormat} correctCoordinates <- checkIfLocationPossible(whereJson.where.latitude, whereJson.where.longitude) - if(addWhereTag(u.resourceUserId, viewId, now, whereJson.where.longitude, whereJson.where.latitude)) + if(addWhereTag(u.userPrimaryKey, viewId, now, whereJson.where.longitude, whereJson.where.latitude)) } yield { val successJson = SuccessMessage("where tag updated") successJsonResponse(Extraction.decompose(successJson)) diff --git a/src/main/scala/code/api/v2_2_0/APIMethods220.scala b/src/main/scala/code/api/v2_2_0/APIMethods220.scala index 4d926d7f6..4b9f36a98 100644 --- a/src/main/scala/code/api/v2_2_0/APIMethods220.scala +++ b/src/main/scala/code/api/v2_2_0/APIMethods220.scala @@ -124,7 +124,7 @@ trait APIMethods220 { for { u <- cc.user ?~ UserNotLoggedIn account <- BankAccount(bankId, accountId) ?~! BankAccountNotFound - _ <- booleanToBox(u.hasOwnerViewAccess(BankIdAccountId(account.bankId, account.accountId)), UserNoOwnerView +"userId : " + u.resourceUserId + ". account : " + accountId) + _ <- booleanToBox(u.hasOwnerViewAccess(BankIdAccountId(account.bankId, account.accountId)), UserNoOwnerView +"userId : " + u.userId + ". account : " + accountId) views <- Full(Views.views.vend.viewsForAccount(BankIdAccountId(account.bankId, account.accountId))) } yield { val viewsJSON = JSONFactory220.createViewsJSON(views) diff --git a/src/main/scala/code/api/v2_2_0/JSONFactory2.2.0.scala b/src/main/scala/code/api/v2_2_0/JSONFactory2.2.0.scala index 8c9662f53..803ff40af 100644 --- a/src/main/scala/code/api/v2_2_0/JSONFactory2.2.0.scala +++ b/src/main/scala/code/api/v2_2_0/JSONFactory2.2.0.scala @@ -680,7 +680,7 @@ object JSONFactory220{ def createUserCustomerViewJsonV220(user: ResourceUser, customer: Customer, view: View): CustomerViewJsonV220 = { var basicUser = BasicUserJsonV220( - user_id = user.resourceUserId.toString, + user_id = user.userId, email = user.email.get, provider_id = user.idGivenByProvider, provider = user.provider, diff --git a/src/main/scala/code/api/v3_0_0/APIMethods300.scala b/src/main/scala/code/api/v3_0_0/APIMethods300.scala index 8dc890f31..9c5cab39a 100644 --- a/src/main/scala/code/api/v3_0_0/APIMethods300.scala +++ b/src/main/scala/code/api/v3_0_0/APIMethods300.scala @@ -116,7 +116,7 @@ trait APIMethods300 { account <- Future { BankAccount(bankId, accountId, callContext) } map { x => fullBoxOrException(x ~> APIFailureNewStyle(BankAccountNotFound, 400, callContext.map(_.toLight))) } map { unboxFull(_) } - _ <- Helper.booleanToFuture(failMsg = UserNoOwnerView +"userId : " + u.resourceUserId + ". account : " + accountId) { + _ <- Helper.booleanToFuture(failMsg = UserNoOwnerView +"userId : " + u.userId + ". account : " + accountId){ u.hasOwnerViewAccess(BankIdAccountId(account.bankId, account.accountId)) } } yield { diff --git a/src/main/scala/code/bankconnectors/Connector.scala b/src/main/scala/code/bankconnectors/Connector.scala index 3816b3423..cfbd86b25 100644 --- a/src/main/scala/code/bankconnectors/Connector.scala +++ b/src/main/scala/code/bankconnectors/Connector.scala @@ -1099,27 +1099,21 @@ trait Connector extends MdcLoggable{ accountRoutingAddress: String ): Box[BankAccount] = Failure(NotImplemented + currentMethodName) - //sets a user as an account owner/holder - def setAccountHolder(bankAccountUID: BankIdAccountId, user: User): Unit = { - AccountHolders.accountHolders.vend.createAccountHolder(user.resourceUserId.value, bankAccountUID.bankId.value, bankAccountUID.accountId.value) - } - /** - * sets a user as an account owner/holder, this maybe duplicated with - * @ setAccountHolder(bankAccountUID: BankAccountUID, user: User) - * - * @param owner - * @param bankId - * @param accountId - * @param account_owners + * A sepecil method: + * This used for set account holder for accounts from Adapter. used in side @code.bankconnectors.Connector#updateUserAccountViewsOld + * But from vJune2017 we introduce the new method `code.model.dataAccess.AuthUser.updateUserAccountViews` instead. + * New method is much powerful and clear then this one. + * If you only want to use this method, please double check your design. You need also think about the view, account holders. */ + @deprecated("we create new code.model.dataAccess.AuthUser.updateUserAccountViews for June2017 connector, try to use new instead of this","11 September 2018") def setAccountHolder(owner : String, bankId: BankId, accountId: AccountId, account_owners: List[String]) : Unit = { // if (account_owners.contains(owner)) { // No need for now, fix it later val resourceUserOwner = Users.users.vend.getUserByUserName(owner) resourceUserOwner match { case Full(owner) => { if ( ! accountOwnerExists(owner, bankId, accountId).openOrThrowException(attemptedToOpenAnEmptyBox)) { - val holder = AccountHolders.accountHolders.vend.createAccountHolder(owner.resourceUserId.value, bankId.value, accountId.value) + val holder = AccountHolders.accountHolders.vend.getOrCreateAccountHolder(owner, BankIdAccountId(bankId, accountId)) logger.debug(s"Connector.setAccountHolder create account holder: $holder") } } diff --git a/src/main/scala/code/bankconnectors/KafkaMappedConnector.scala b/src/main/scala/code/bankconnectors/KafkaMappedConnector.scala index 667fa9247..3a0e3a272 100644 --- a/src/main/scala/code/bankconnectors/KafkaMappedConnector.scala +++ b/src/main/scala/code/bankconnectors/KafkaMappedConnector.scala @@ -152,7 +152,7 @@ object KafkaMappedConnector extends Connector with KafkaHelper with MdcLoggable Views.views.vend.addPermission(v.uid, user) //logger.info(s"------------> updated view ${v.uid} for resourceuser ${user} and account ${acc}") }) - existing_views.filterNot(_.users.contains(user.resourceUserId)).foreach (v => { + existing_views.filterNot(_.users.contains(user.userPrimaryKey)).foreach (v => { Views.views.vend.addPermission(v.uid, user) //logger.info(s"------------> added resourceuser ${user} to view ${v.uid} for account ${acc}") }) @@ -821,11 +821,6 @@ object KafkaMappedConnector extends Connector with KafkaHelper with MdcLoggable } - //sets a user as an account owner/holder - override def setAccountHolder(bankAccountUID: BankIdAccountId, user: User): Unit = { - AccountHolders.accountHolders.vend.createAccountHolder(user.resourceUserId.value, bankAccountUID.bankId.value, bankAccountUID.accountId.value) - } - private def createAccountIfNotExisting(bankId: BankId, accountId: AccountId, accountNumber: String, accountType: String, accountLabel: String, currency: String, balanceInSmallestCurrencyUnits: Long, accountHolderName: String) : BankAccount = { diff --git a/src/main/scala/code/bankconnectors/KafkaMappedConnector_JVMcompatible.scala b/src/main/scala/code/bankconnectors/KafkaMappedConnector_JVMcompatible.scala index 71feeb755..d7c8cea52 100644 --- a/src/main/scala/code/bankconnectors/KafkaMappedConnector_JVMcompatible.scala +++ b/src/main/scala/code/bankconnectors/KafkaMappedConnector_JVMcompatible.scala @@ -355,7 +355,7 @@ object KafkaMappedConnector_JVMcompatible extends Connector with KafkaHelper wit //3 get all the existing views. existingViewsNotBelongtoTheUser <- tryo { Views.views.vend.viewsForAccount(BankIdAccountId(BankId(acc.bankId), AccountId(acc.accountId))) - .filterNot(_.users.contains(user.resourceUserId)) + .filterNot(_.users.contains(user.userPrimaryKey)) } } yield { //4 set Account link to User diff --git a/src/main/scala/code/bankconnectors/ObpJvmMappedConnector.scala b/src/main/scala/code/bankconnectors/ObpJvmMappedConnector.scala index aa38d54b0..f15237583 100644 --- a/src/main/scala/code/bankconnectors/ObpJvmMappedConnector.scala +++ b/src/main/scala/code/bankconnectors/ObpJvmMappedConnector.scala @@ -175,7 +175,7 @@ object ObpJvmMappedConnector extends Connector with MdcLoggable { Views.views.vend.addPermission(v.uid, user) logger.info(s"------------> updated view ${v.uid} for resourceuser ${user} and account ${acc}") }) - existing_views.filterNot(_.users.contains(user.resourceUserId)).foreach (v => { + existing_views.filterNot(_.users.contains(user.userPrimaryKey)).foreach (v => { Views.views.vend.addPermission(v.uid, user) logger.info(s"------------> added resourceuser ${user} to view ${v.uid} for account ${acc}") }) diff --git a/src/main/scala/code/bankconnectors/vJune2017/KafkaMappedConnector_vJune2017.scala b/src/main/scala/code/bankconnectors/vJune2017/KafkaMappedConnector_vJune2017.scala index 992a922b7..20d27277c 100644 --- a/src/main/scala/code/bankconnectors/vJune2017/KafkaMappedConnector_vJune2017.scala +++ b/src/main/scala/code/bankconnectors/vJune2017/KafkaMappedConnector_vJune2017.scala @@ -101,7 +101,7 @@ trait KafkaMappedConnector_vJune2017 extends Connector with KafkaHelper with Mdc messageDocs += MessageDoc( process = "obp.get.AdapterInfo", messageFormat = messageFormat, - description = "getAdapterInfo from kafka ", + description = "getAdapterInfo from Adapter, just for testing kafka and Adapter setting. ", exampleOutboundMessage = decompose( OutboundGetAdapterInfo(date = DateWithSecondsExampleString) ), diff --git a/src/main/scala/code/bankconnectors/vMar2017/KafkaMappedConnector_vMar2017.scala b/src/main/scala/code/bankconnectors/vMar2017/KafkaMappedConnector_vMar2017.scala index 80aa56171..0ccd1a5d7 100644 --- a/src/main/scala/code/bankconnectors/vMar2017/KafkaMappedConnector_vMar2017.scala +++ b/src/main/scala/code/bankconnectors/vMar2017/KafkaMappedConnector_vMar2017.scala @@ -228,7 +228,7 @@ trait KafkaMappedConnector_vMar2017 extends Connector with KafkaHelper with MdcL Views.views.vend.addPermission(v.uid, user) logger.info(s"------------> updated view ${v.uid} for resourceuser ${user} and account ${acc}") }) - existing_views.filterNot(_.users.contains(user.resourceUserId)).foreach (v => { + existing_views.filterNot(_.users.contains(user.userPrimaryKey)).foreach (v => { Views.views.vend.addPermission(v.uid, user) logger.info(s"------------> added resourceuser ${user} to view ${v.uid} for account ${acc}") }) @@ -1444,10 +1444,6 @@ trait KafkaMappedConnector_vMar2017 extends Connector with KafkaHelper with MdcL } - //sets a user as an account owner/holder - override def setAccountHolder(bankAccountUID: BankIdAccountId, user: User): Unit = { - AccountHolders.accountHolders.vend.createAccountHolder(user.resourceUserId.value, bankAccountUID.bankId.value, bankAccountUID.accountId.value) - } private def createAccountIfNotExisting(bankId: BankId, accountId: AccountId, accountNumber: String, accountType: String, accountLabel: String, currency: String, diff --git a/src/main/scala/code/bankconnectors/vSept2018/KafkaJsonFactory_vSept2018.scala b/src/main/scala/code/bankconnectors/vSept2018/KafkaJsonFactory_vSept2018.scala index 42a998b00..90f416a30 100644 --- a/src/main/scala/code/bankconnectors/vSept2018/KafkaJsonFactory_vSept2018.scala +++ b/src/main/scala/code/bankconnectors/vSept2018/KafkaJsonFactory_vSept2018.scala @@ -139,7 +139,33 @@ case class Status( errorCode: String, backendMessages: List[InboundStatusMessage] ) -case class AuthInfo(userId: String = "", username: String ="", cbsToken: String ="", isFirst: Boolean = true, correlationId: String="") + +case class ViewBasic( + id: String, + short_name: String, + description: String, +) + +case class AccountBasic( + id: String, + accountRoutings: List[AccountRouting], + customerOwners: List[InternalBasicCustomer] +) + +case class AuthView( + view: ViewBasic, + account:AccountBasic, +) + +case class AuthInfo( + userId: String = "", + username: String = "", + cbsToken: String = "", + isFirst: Boolean = true, + correlationId: String = "", + authViews: List[AuthView] = Nil +) + case class InboundAccountSept2018( errorCode: String, diff --git a/src/main/scala/code/bankconnectors/vSept2018/KafkaMappedConnector_vSept2018.scala b/src/main/scala/code/bankconnectors/vSept2018/KafkaMappedConnector_vSept2018.scala index 26f190456..323c284bd 100644 --- a/src/main/scala/code/bankconnectors/vSept2018/KafkaMappedConnector_vSept2018.scala +++ b/src/main/scala/code/bankconnectors/vSept2018/KafkaMappedConnector_vSept2018.scala @@ -43,6 +43,7 @@ import code.model._ import code.model.dataAccess._ import code.transactionrequests.TransactionRequests._ import code.util.Helper.MdcLoggable +import code.views.Views import com.sksamuel.avro4s.SchemaFor import com.tesobe.{CacheKeyFromArguments, CacheKeyOmit} import net.liftweb.common.{Box, _} @@ -84,11 +85,46 @@ trait KafkaMappedConnector_vSept2018 extends Connector with KafkaHelper with Mdc cbs_token <- gatewayLoginPayLoad.cbs_token.orElse(Full("")) isFirst <- Full(gatewayLoginPayLoad.is_first) correlationId <- Full(cc.correlationId) + permission <- Views.views.vend.getPermissionForUser(user) + views <- Full(permission.views) + authViews<- Full( + for{ + view <- views + account <- checkBankAccountExists(view.bankId, view.accountId, Some(cc)) ?~! {BankAccountNotFound} + internalCustomers = JsonFactory_vSept2018.createCustomersJson(account.customerOwners.toList) + viewBasic = ViewBasic(view.viewId.value, view.name, view.description) + accountBasic = AccountBasic(account.accountId.value, account.accountRoutings, internalCustomers.customers) + }yield + AuthView(viewBasic, accountBasic) + ) } yield{ - AuthInfo(currentResourceUserId,username, cbs_token, isFirst,correlationId) + AuthInfo(currentResourceUserId, username, cbs_token, isFirst, correlationId, authViews) } - - val authInfoExample = AuthInfo(userId = "userId", username = "username", cbsToken = "cbsToken") + + val viewBasic = ViewBasic("owner","Owner", "This is the owner view") + + val internalBasicCustomer = InternalBasicCustomer( + bankId = "bankId", + customerId = "customerId", + customerNumber = "customerNumber", + legalName = "legalName", + dateOfBirth = DateWithSecondsExampleObject + ) + val accountBasic = AccountBasic( + "123123", + List(AccountRouting("AccountNumber","2345 6789 1234"), + AccountRouting("IBAN","DE91 1000 0000 0123 4567 89")), + List(internalBasicCustomer)) + val authView = AuthView(viewBasic, accountBasic) + val authViews = List(authView) + val authInfoExample = AuthInfo( + userId = "userId", + username = "username", + cbsToken = "cbsToken", + isFirst = true, + correlationId = "correlationId", + authViews + ) val inboundStatusMessagesExample = List(InboundStatusMessage("ESB", "Success", "0", "OK")) val errorCodeExample = "INTERNAL-OBP-ADAPTER-6001: ..." val statusExample = Status(errorCodeExample, inboundStatusMessagesExample) @@ -461,14 +497,7 @@ trait KafkaMappedConnector_vSept2018 extends Connector with KafkaHelper with Mdc OutboundGetAccounts( authInfoExample, true, - InternalBasicCustomers(customers =List( - InternalBasicCustomer( - bankId="bankId", - customerId = "customerId", - customerNumber = "customerNumber", - legalName = "legalName", - dateOfBirth = DateWithSecondsExampleObject - )))) + InternalBasicCustomers(customers =List(internalBasicCustomer))) ), exampleInboundMessage = decompose( InboundGetAccounts(authInfoExample, statusExample, InboundAccountSept2018("", cbsToken ="cbsToken", bankId = "gh.29.uk", branchId = "222", accountId = "8ca8a7e4-6d02-48e3-a029-0b2bf89de9f0", accountNumber = "123", accountType = "AC", balanceAmount = "50", balanceCurrency = "EUR", owners = "Susan" :: " Frank" :: Nil, viewsToGenerate = "Public" :: "Accountant" :: "Auditor" :: Nil, bankRoutingScheme = "iban", bankRoutingAddress = "bankRoutingAddress", branchRoutingScheme = "branchRoutingScheme", branchRoutingAddress = " branchRoutingAddress", accountRoutingScheme = "accountRoutingScheme", accountRoutingAddress = "accountRoutingAddress", accountRouting = Nil, accountRules = Nil) :: Nil) diff --git a/src/main/scala/code/customer/MappedCustomerMessageProvider.scala b/src/main/scala/code/customer/MappedCustomerMessageProvider.scala index 53ea11f28..04db66374 100644 --- a/src/main/scala/code/customer/MappedCustomerMessageProvider.scala +++ b/src/main/scala/code/customer/MappedCustomerMessageProvider.scala @@ -11,7 +11,7 @@ object MappedCustomerMessageProvider extends CustomerMessageProvider { override def getMessages(user: User, bankId : BankId): List[CustomerMessage] = { MappedCustomerMessage.findAll( - By(MappedCustomerMessage.user, user.resourceUserId.value), + By(MappedCustomerMessage.user, user.userPrimaryKey.value), By(MappedCustomerMessage.bank, bankId.value), OrderBy(MappedCustomerMessage.updatedAt, Descending)) } @@ -22,7 +22,7 @@ object MappedCustomerMessageProvider extends CustomerMessageProvider { .mFromDepartment(fromDepartment) .mFromPerson(fromPerson) .mMessage(message) - .user(user.resourceUserId.value) + .user(user.userPrimaryKey.value) .bank(bankId.value).save() } } diff --git a/src/main/scala/code/meetings/MappedMeetingProvider.scala b/src/main/scala/code/meetings/MappedMeetingProvider.scala index a1d1a2bb9..e21424fe6 100644 --- a/src/main/scala/code/meetings/MappedMeetingProvider.scala +++ b/src/main/scala/code/meetings/MappedMeetingProvider.scala @@ -37,7 +37,7 @@ object MappedMeetingProvider extends MeetingProvider { val createdMeeting = MappedMeeting.create .mBankId(bankId.value.toString) //.mStaffUserId(staffUser.apiId.value) - .mCustomerUserId(customerUser.resourceUserId.value) + .mCustomerUserId(customerUser.userPrimaryKey.value) .mProviderId(providerId) .mPurposeId(purposeId) .mWhen(when) diff --git a/src/main/scala/code/metadata/comments/Comments.scala b/src/main/scala/code/metadata/comments/Comments.scala index 27a5aaf54..41d3e0d50 100644 --- a/src/main/scala/code/metadata/comments/Comments.scala +++ b/src/main/scala/code/metadata/comments/Comments.scala @@ -23,7 +23,7 @@ object Comments extends SimpleInjector { trait Comments { def getComments(bankId : BankId, accountId : AccountId, transactionId : TransactionId)(viewId : ViewId) : List[Comment] - def addComment(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(userId: UserId, viewId : ViewId, text : String, datePosted : Date) : Box[Comment] + def addComment(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(userId: UserPrimaryKey, viewId : ViewId, text : String, datePosted : Date) : Box[Comment] //TODO: should commentId be unique among all comments, removing the need for the other parameters? def deleteComment(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(commentId : String) : Box[Boolean] def bulkDeleteComments(bankId: BankId, accountId: AccountId) : Boolean @@ -32,7 +32,7 @@ trait Comments { class RemotedataCommentsCaseClasses { case class getComments(bankId : BankId, accountId : AccountId, transactionId : TransactionId, viewId : ViewId) - case class addComment(bankId : BankId, accountId : AccountId, transactionId: TransactionId, userId: UserId, viewId : ViewId, text : String, datePosted : Date) + case class addComment(bankId : BankId, accountId : AccountId, transactionId: TransactionId, userId: UserPrimaryKey, viewId : ViewId, text : String, datePosted : Date) case class deleteComment(bankId : BankId, accountId : AccountId, transactionId: TransactionId, commentId : String) case class bulkDeleteComments(bankId: BankId, accountId: AccountId) } diff --git a/src/main/scala/code/metadata/comments/MappedComment.scala b/src/main/scala/code/metadata/comments/MappedComment.scala index 908283fd1..2e44e1feb 100644 --- a/src/main/scala/code/metadata/comments/MappedComment.scala +++ b/src/main/scala/code/metadata/comments/MappedComment.scala @@ -35,7 +35,7 @@ object MappedComments extends Comments { } } - override def addComment(bankId: BankId, accountId: AccountId, transactionId: TransactionId)(userId: UserId, viewId: ViewId, text: String, datePosted: Date): Box[Comment] = { + override def addComment(bankId: BankId, accountId: AccountId, transactionId: TransactionId)(userId: UserPrimaryKey, viewId: ViewId, text: String, datePosted: Date): Box[Comment] = { val metadateViewId = Views.views.vend.getMetadataViewId(BankIdAccountId(bankId, accountId), viewId) tryo { MappedComment.create diff --git a/src/main/scala/code/metadata/comments/MongoTransactionComments.scala b/src/main/scala/code/metadata/comments/MongoTransactionComments.scala index 8e17a76d5..34c139d2d 100644 --- a/src/main/scala/code/metadata/comments/MongoTransactionComments.scala +++ b/src/main/scala/code/metadata/comments/MongoTransactionComments.scala @@ -16,7 +16,7 @@ private object MongoTransactionComments extends Comments { def getComments(bankId : BankId, accountId : AccountId, transactionId : TransactionId)(viewId : ViewId) : List[Comment] = { OBPComment.findAll(bankId, accountId, transactionId, viewId) } - def addComment(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(userId: UserId, viewId : ViewId, text : String, datePosted : Date) : Box[Comment] = { + def addComment(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(userId: UserPrimaryKey, viewId : ViewId, text : String, datePosted : Date) : Box[Comment] = { OBPComment.createRecord.userId(userId.value). transactionId(transactionId.value). accountId(accountId.value). diff --git a/src/main/scala/code/metadata/counterparties/Counterparties.scala b/src/main/scala/code/metadata/counterparties/Counterparties.scala index dfbd4b7be..ccac7c3d2 100644 --- a/src/main/scala/code/metadata/counterparties/Counterparties.scala +++ b/src/main/scala/code/metadata/counterparties/Counterparties.scala @@ -69,8 +69,8 @@ trait Counterparties { def addImageURL(counterpartyId : String, imageUrl: String): Box[Boolean] def addOpenCorporatesURL(counterpartyId : String, imageUrl: String): Box[Boolean] def addMoreInfo(counterpartyId : String, moreInfo: String): Box[Boolean] - def addPhysicalLocation(counterpartyId : String, userId: UserId, datePosted : Date, longitude : Double, latitude : Double): Box[Boolean] - def addCorporateLocation(counterpartyId : String, userId: UserId, datePosted : Date, longitude : Double, latitude : Double): Box[Boolean] + def addPhysicalLocation(counterpartyId : String, userId: UserPrimaryKey, datePosted : Date, longitude : Double, latitude : Double): Box[Boolean] + def addCorporateLocation(counterpartyId : String, userId: UserPrimaryKey, datePosted : Date, longitude : Double, latitude : Double): Box[Boolean] def deletePhysicalLocation(counterpartyId : String): Box[Boolean] def deleteCorporateLocation(counterpartyId : String): Box[Boolean] def getCorporateLocation(counterpartyId : String): Box[GeoTag] @@ -170,9 +170,9 @@ class RemotedataCounterpartiesCaseClasses { case class addMoreInfo(counterpartyId : String, moreInfo: String) - case class addPhysicalLocation(counterpartyId : String, userId: UserId, datePosted : Date, longitude : Double, latitude : Double) + case class addPhysicalLocation(counterpartyId : String, userId: UserPrimaryKey, datePosted : Date, longitude : Double, latitude : Double) - case class addCorporateLocation(counterpartyId : String, userId: UserId, datePosted : Date, longitude : Double, latitude : Double) + case class addCorporateLocation(counterpartyId : String, userId: UserPrimaryKey, datePosted : Date, longitude : Double, latitude : Double) case class deletePhysicalLocation(counterpartyId : String) diff --git a/src/main/scala/code/metadata/counterparties/MapperCounterparties.scala b/src/main/scala/code/metadata/counterparties/MapperCounterparties.scala index aac75fa66..3794565f8 100644 --- a/src/main/scala/code/metadata/counterparties/MapperCounterparties.scala +++ b/src/main/scala/code/metadata/counterparties/MapperCounterparties.scala @@ -267,11 +267,11 @@ object MapperCounterparties extends Counterparties with MdcLoggable { getCounterpartyMetadata(counterpartyId).map(_.moreInfo(moreInfo).save()) } - override def addPhysicalLocation(counterpartyId : String, userId: UserId, datePosted : Date, longitude : Double, latitude : Double): Box[Boolean] = { + override def addPhysicalLocation(counterpartyId : String, userId: UserPrimaryKey, datePosted : Date, longitude : Double, latitude : Double): Box[Boolean] = { getCounterpartyMetadata(counterpartyId).map(_.setPhysicalLocation(userId, datePosted, longitude, latitude)) } - override def addCorporateLocation(counterpartyId : String, userId: UserId, datePosted : Date, longitude : Double, latitude : Double): Box[Boolean] = { + override def addCorporateLocation(counterpartyId : String, userId: UserPrimaryKey, datePosted : Date, longitude : Double, latitude : Double): Box[Boolean] = { getCounterpartyMetadata(counterpartyId).map(_.setCorporateLocation(userId, datePosted, longitude, latitude)) } @@ -330,7 +330,7 @@ class MappedCounterpartyMetadata extends CounterpartyMetadata with LongKeyedMapp }.getOrElse(false) private def setWhere(whereTag : Box[MappedCounterpartyWhereTag]) - (userId: UserId, datePosted : Date, longitude : Double, latitude : Double) : Box[MappedCounterpartyWhereTag] = { + (userId: UserPrimaryKey, datePosted : Date, longitude : Double, latitude : Double) : Box[MappedCounterpartyWhereTag] = { val toUpdate = whereTag match { case Full(c) => c case _ => MappedCounterpartyWhereTag.create @@ -346,14 +346,14 @@ class MappedCounterpartyMetadata extends CounterpartyMetadata with LongKeyedMapp } } - def setCorporateLocation(userId: UserId, datePosted : Date, longitude : Double, latitude : Double) : Boolean = { + def setCorporateLocation(userId: UserPrimaryKey, datePosted : Date, longitude : Double, latitude : Double) : Boolean = { //save where tag val savedWhere = setWhere(corporateLocation.obj)(userId, datePosted, longitude, latitude) //set where tag for counterparty savedWhere.map(location => trySave{corporateLocation(location)}).getOrElse(false) } - def setPhysicalLocation(userId: UserId, datePosted : Date, longitude : Double, latitude : Double) : Boolean = { + def setPhysicalLocation(userId: UserPrimaryKey, datePosted : Date, longitude : Double, latitude : Double) : Boolean = { //save where tag val savedWhere = setWhere(physicalLocation.obj)(userId, datePosted, longitude, latitude) //set where tag for counterparty @@ -373,8 +373,8 @@ class MappedCounterpartyMetadata extends CounterpartyMetadata with LongKeyedMapp physicalLocation.obj override def getUrl: String = url.get - override val addPhysicalLocation: (UserId, Date, Double, Double) => Boolean = setPhysicalLocation _ - override val addCorporateLocation: (UserId, Date, Double, Double) => Boolean = setCorporateLocation _ + override val addPhysicalLocation: (UserPrimaryKey, Date, Double, Double) => Boolean = setPhysicalLocation _ + override val addCorporateLocation: (UserPrimaryKey, Date, Double, Double) => Boolean = setCorporateLocation _ override val addPrivateAlias: (String) => Boolean = (x) => trySave{privateAlias(x)} override val addURL: (String) => Boolean = (x) => diff --git a/src/main/scala/code/metadata/counterparties/MongoCounterparties.scala b/src/main/scala/code/metadata/counterparties/MongoCounterparties.scala index 95ffa6027..362b523f6 100644 --- a/src/main/scala/code/metadata/counterparties/MongoCounterparties.scala +++ b/src/main/scala/code/metadata/counterparties/MongoCounterparties.scala @@ -143,8 +143,8 @@ object MongoCounterparties extends Counterparties with MdcLoggable { override def addImageURL(counterpartyId : String, imageUrl: String): Box[Boolean] = ??? override def addOpenCorporatesURL(counterpartyId : String, url: String): Box[Boolean] = ??? override def addMoreInfo(counterpartyId : String, moreInfo: String): Box[Boolean] = ??? - override def addPhysicalLocation(counterpartyId : String, userId: UserId, datePosted : Date, longitude : Double, latitude : Double): Box[Boolean] = ??? - override def addCorporateLocation(counterpartyId : String, userId: UserId, datePosted : Date, longitude : Double, latitude : Double): Box[Boolean] = ??? + override def addPhysicalLocation(counterpartyId : String, userId: UserPrimaryKey, datePosted : Date, longitude : Double, latitude : Double): Box[Boolean] = ??? + override def addCorporateLocation(counterpartyId : String, userId: UserPrimaryKey, datePosted : Date, longitude : Double, latitude : Double): Box[Boolean] = ??? override def deletePhysicalLocation(counterpartyId : String): Box[Boolean] = ??? override def deleteCorporateLocation(counterpartyId : String): Box[Boolean] = ??? override def getCorporateLocation(counterpartyId : String): Box[GeoTag] = ??? diff --git a/src/main/scala/code/metadata/counterparties/MongoMetadata.scala b/src/main/scala/code/metadata/counterparties/MongoMetadata.scala index c03aa03d4..2ac459e8f 100644 --- a/src/main/scala/code/metadata/counterparties/MongoMetadata.scala +++ b/src/main/scala/code/metadata/counterparties/MongoMetadata.scala @@ -5,7 +5,7 @@ import code.util.Helper import net.liftweb.mongodb.record.{BsonMetaRecord, BsonRecord, MongoMetaRecord, MongoRecord} import net.liftweb.mongodb.record.field.ObjectIdPk import net.liftweb.record.field.StringField -import code.model.{CounterpartyMetadata, UserId, ViewId, GeoTag} +import code.model.{CounterpartyMetadata, UserPrimaryKey, ViewId, GeoTag} //TODO: this should be private class Metadata private() extends CounterpartyMetadata with MongoRecord[Metadata] with ObjectIdPk[Metadata] { import net.liftweb.mongodb.record.field.BsonRecordField @@ -32,7 +32,7 @@ class Metadata private() extends CounterpartyMetadata with MongoRecord[Metadata] object corporateLocation extends BsonRecordField(this, OBPGeoTag) object physicalLocation extends BsonRecordField(this, OBPGeoTag) - def addCorporateLocationFn(userId: UserId, datePosted : Date, longitude : Double, latitude : Double) : Boolean = { + def addCorporateLocationFn(userId: UserPrimaryKey, datePosted : Date, longitude : Double, latitude : Double) : Boolean = { val newTag = OBPGeoTag.createRecord. userId(userId.value). date(datePosted). @@ -48,7 +48,7 @@ class Metadata private() extends CounterpartyMetadata with MongoRecord[Metadata] true } - def addPhysicalLocationFn(userId: UserId, datePosted : Date, longitude : Double, latitude : Double) : Boolean = { + def addPhysicalLocationFn(userId: UserPrimaryKey, datePosted : Date, longitude : Double, latitude : Double) : Boolean = { val newTag = OBPGeoTag.createRecord. userId(userId.value). date(datePosted). @@ -95,8 +95,8 @@ class Metadata private() extends CounterpartyMetadata with MongoRecord[Metadata] //so we a true true }) - override val addPhysicalLocation: (UserId, Date, Double, Double) => Boolean = addPhysicalLocationFn _ - override val addCorporateLocation: (UserId, Date, Double, Double) => Boolean = addCorporateLocationFn _ + override val addPhysicalLocation: (UserPrimaryKey, Date, Double, Double) => Boolean = addPhysicalLocationFn _ + override val addCorporateLocation: (UserPrimaryKey, Date, Double, Double) => Boolean = addCorporateLocationFn _ override val addMoreInfo: (String) => Boolean = (text => { moreInfo(text).saveTheRecord() //the save method does not return a Boolean to inform about the saving state, diff --git a/src/main/scala/code/metadata/tags/MappedTags.scala b/src/main/scala/code/metadata/tags/MappedTags.scala index 9803ecdde..f6e322d47 100644 --- a/src/main/scala/code/metadata/tags/MappedTags.scala +++ b/src/main/scala/code/metadata/tags/MappedTags.scala @@ -18,7 +18,7 @@ object MappedTags extends Tags { } override def addTag(bankId: BankId, accountId: AccountId, transactionId: TransactionId) - (userId: UserId, viewId: ViewId, tagText: String, datePosted: Date): Box[TransactionTag] = { + (userId: UserPrimaryKey, viewId: ViewId, tagText: String, datePosted: Date): Box[TransactionTag] = { val metadateViewId = Views.views.vend.getMetadataViewId(BankIdAccountId(bankId, accountId), viewId) tryo{ MappedTag.create diff --git a/src/main/scala/code/metadata/tags/MongoTransactionTags.scala b/src/main/scala/code/metadata/tags/MongoTransactionTags.scala index bc2b3c822..f268d1c9a 100644 --- a/src/main/scala/code/metadata/tags/MongoTransactionTags.scala +++ b/src/main/scala/code/metadata/tags/MongoTransactionTags.scala @@ -15,7 +15,7 @@ private object MongoTransactionTags extends Tags { def getTags(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(viewId : ViewId) : List[TransactionTag] = { OBPTag.findAll(bankId, accountId, transactionId, viewId) } - def addTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(userId: UserId, viewId : ViewId, tagText : String, datePosted : Date) : Box[TransactionTag] = { + def addTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(userId: UserPrimaryKey, viewId : ViewId, tagText : String, datePosted : Date) : Box[TransactionTag] = { OBPTag.createRecord. bankId(bankId.value). accountId(accountId.value). diff --git a/src/main/scala/code/metadata/tags/Tags.scala b/src/main/scala/code/metadata/tags/Tags.scala index 09272c5e9..5e7992cba 100644 --- a/src/main/scala/code/metadata/tags/Tags.scala +++ b/src/main/scala/code/metadata/tags/Tags.scala @@ -23,7 +23,7 @@ object Tags extends SimpleInjector { trait Tags { def getTags(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(viewId : ViewId) : List[TransactionTag] - def addTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(userId: UserId, viewId : ViewId, tagText : String, datePosted : Date) : Box[TransactionTag] + def addTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(userId: UserPrimaryKey, viewId : ViewId, tagText : String, datePosted : Date) : Box[TransactionTag] //TODO: viewId? should tagId always be unique -> in that case bankId, accountId, and transactionId would not be required def deleteTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(tagId : String) : Box[Boolean] def bulkDeleteTags(bankId: BankId, accountId: AccountId) : Boolean @@ -32,7 +32,7 @@ trait Tags { class RemotedataTagsCaseClasses{ case class getTags(bankId : BankId, accountId : AccountId, transactionId: TransactionId, viewId : ViewId) - case class addTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId, userId: UserId, viewId : ViewId, tagText : String, datePosted : Date) + case class addTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId, userId: UserPrimaryKey, viewId : ViewId, tagText : String, datePosted : Date) case class deleteTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId, tagId : String) case class bulkDeleteTags(bankId: BankId, accountId: AccountId) } diff --git a/src/main/scala/code/metadata/transactionimages/MapperTransactionImages.scala b/src/main/scala/code/metadata/transactionimages/MapperTransactionImages.scala index 2b4f229df..98964974e 100644 --- a/src/main/scala/code/metadata/transactionimages/MapperTransactionImages.scala +++ b/src/main/scala/code/metadata/transactionimages/MapperTransactionImages.scala @@ -29,7 +29,7 @@ object MapperTransactionImages extends TransactionImages { } override def addTransactionImage(bankId: BankId, accountId: AccountId, transactionId: TransactionId) - (userId: UserId, viewId: ViewId, description: String, datePosted: Date, imageURL: String): Box[TransactionImage] = { + (userId: UserPrimaryKey, viewId: ViewId, description: String, datePosted: Date, imageURL: String): Box[TransactionImage] = { val metadateViewId = Views.views.vend.getMetadataViewId(BankIdAccountId(bankId, accountId), viewId) tryo { MappedTransactionImage.create diff --git a/src/main/scala/code/metadata/transactionimages/MongoTransactionImages.scala b/src/main/scala/code/metadata/transactionimages/MongoTransactionImages.scala index a9d6dcd72..16a24fa0a 100644 --- a/src/main/scala/code/metadata/transactionimages/MongoTransactionImages.scala +++ b/src/main/scala/code/metadata/transactionimages/MongoTransactionImages.scala @@ -21,7 +21,7 @@ private object MongoTransactionImages extends TransactionImages with MdcLoggable } def addTransactionImage(bankId : BankId, accountId : AccountId, transactionId: TransactionId) - (userId: UserId, viewId : ViewId, description : String, datePosted : Date, imageURL: String) : Box[TransactionImage] = { + (userId: UserPrimaryKey, viewId : ViewId, description : String, datePosted : Date, imageURL: String) : Box[TransactionImage] = { OBPTransactionImage.createRecord. bankId(bankId.value). accountId(accountId.value). diff --git a/src/main/scala/code/metadata/transactionimages/TransactionImages.scala b/src/main/scala/code/metadata/transactionimages/TransactionImages.scala index d0f7b2ab8..cd41279d9 100644 --- a/src/main/scala/code/metadata/transactionimages/TransactionImages.scala +++ b/src/main/scala/code/metadata/transactionimages/TransactionImages.scala @@ -25,7 +25,7 @@ trait TransactionImages { def getImagesForTransaction(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(viewId : ViewId) : List[TransactionImage] def addTransactionImage(bankId : BankId, accountId : AccountId, transactionId: TransactionId) - (userId: UserId, viewId : ViewId, description : String, datePosted : Date, imageURL: String) : Box[TransactionImage] + (userId: UserPrimaryKey, viewId : ViewId, description : String, datePosted : Date, imageURL: String) : Box[TransactionImage] def deleteTransactionImage(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(imageId : String) : Box[Boolean] @@ -35,7 +35,7 @@ trait TransactionImages { class RemotedataTransactionImagesCaseClasses { case class getImagesForTransaction(bankId : BankId, accountId : AccountId, transactionId: TransactionId, viewId : ViewId) - case class addTransactionImage(bankId : BankId, accountId : AccountId, transactionId: TransactionId, userId: UserId, viewId : ViewId, description : String, datePosted : Date, imageURL: String) + case class addTransactionImage(bankId : BankId, accountId : AccountId, transactionId: TransactionId, userId: UserPrimaryKey, viewId : ViewId, description : String, datePosted : Date, imageURL: String) case class deleteTransactionImage(bankId : BankId, accountId : AccountId, transactionId: TransactionId, imageId : String) case class bulkDeleteTransactionImage(bankId: BankId, accountId: AccountId) } diff --git a/src/main/scala/code/metadata/wheretags/MapperWhereTags.scala b/src/main/scala/code/metadata/wheretags/MapperWhereTags.scala index 8be3373e7..c4ae56118 100644 --- a/src/main/scala/code/metadata/wheretags/MapperWhereTags.scala +++ b/src/main/scala/code/metadata/wheretags/MapperWhereTags.scala @@ -22,7 +22,7 @@ object MapperWhereTags extends WhereTags { } override def addWhereTag(bankId: BankId, accountId: AccountId, transactionId: TransactionId) - (userId: UserId, viewId: ViewId, datePosted: Date, longitude: Double, latitude: Double): Boolean = { + (userId: UserPrimaryKey, viewId: ViewId, datePosted: Date, longitude: Double, latitude: Double): Boolean = { val metadateViewId = Views.views.vend.getMetadataViewId(BankIdAccountId(bankId, accountId), viewId) val found = findMappedWhereTag(bankId, accountId, transactionId, ViewId(metadateViewId)) diff --git a/src/main/scala/code/metadata/wheretags/MongoTransactionWhereTags.scala b/src/main/scala/code/metadata/wheretags/MongoTransactionWhereTags.scala index d9c58a6ad..c1db31f72 100644 --- a/src/main/scala/code/metadata/wheretags/MongoTransactionWhereTags.scala +++ b/src/main/scala/code/metadata/wheretags/MongoTransactionWhereTags.scala @@ -10,7 +10,7 @@ import code.util.Helper.MdcLoggable private object MongoTransactionWhereTags extends WhereTags with MdcLoggable { def addWhereTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId) - (userId: UserId, viewId : ViewId, datePosted : Date, longitude : Double, latitude : Double) : Boolean = { + (userId: UserPrimaryKey, viewId : ViewId, datePosted : Date, longitude : Double, latitude : Double) : Boolean = { //avoiding upsert for now as it seemed to behave a little strangely val findQuery = OBPWhereTag.getFindQuery(bankId, accountId, transactionId, viewId) diff --git a/src/main/scala/code/metadata/wheretags/WhereTags.scala b/src/main/scala/code/metadata/wheretags/WhereTags.scala index ead796fbd..e3ebd7396 100644 --- a/src/main/scala/code/metadata/wheretags/WhereTags.scala +++ b/src/main/scala/code/metadata/wheretags/WhereTags.scala @@ -24,7 +24,7 @@ trait WhereTags { //TODO: it probably makes more sense for this to return Box[GeoTag]. Leaving it as a Boolean for now... def addWhereTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId) - (userId: UserId, viewId : ViewId, datePosted : Date, longitude : Double, latitude : Double) : Boolean + (userId: UserPrimaryKey, viewId : ViewId, datePosted : Date, longitude : Double, latitude : Double) : Boolean //TODO: would be nicer to change this to return Box[Unit] like in e.g. comments. Or perhaps change the way the other ones work //instead, with the end effect of keeping them consistent. Leaving it as a Boolean for now... @@ -37,7 +37,7 @@ trait WhereTags { } class RemotedataWhereTagsCaseClasses { - case class addWhereTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId, userId: UserId, viewId : ViewId, datePosted : Date, longitude : Double, latitude : Double) + case class addWhereTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId, userId: UserPrimaryKey, viewId : ViewId, datePosted : Date, longitude : Double, latitude : Double) case class deleteWhereTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId, viewId : ViewId) case class getWhereTagForTransaction(bankId : BankId, accountId : AccountId, transactionId: TransactionId, viewId : ViewId) case class bulkDeleteWhereTags(bankId: BankId, accountId: AccountId) diff --git a/src/main/scala/code/model/BankingData.scala b/src/main/scala/code/model/BankingData.scala index 1d0fd4525..fa922976a 100644 --- a/src/main/scala/code/model/BankingData.scala +++ b/src/main/scala/code/model/BankingData.scala @@ -32,11 +32,13 @@ Berlin 13359, Germany package code.model import java.util.Date + import code.api.util.ErrorMessages._ import code.accountholder.AccountHolders import code.api.util.APIUtil.hasEntitlement import code.api.util.{APIUtil, ApiRole, CallContext, ErrorMessages} import code.bankconnectors.{Connector, OBPQueryParam} +import code.customer.Customer import code.metadata.comments.Comments import code.metadata.counterparties.{Counterparties, CounterpartyTrait} import code.metadata.narrative.Narrative @@ -309,14 +311,27 @@ trait BankAccount extends MdcLoggable { Failure(UserNoOwnerView+"user's email : " + user.emailAddress + ". account : " + accountId, Empty, Empty) } } - - final def owners: Set[User] = { + + /** + * Note: There are two types of account-owners in OBP: the OBP users and the customers(in a real bank, these should from Main Frame) + * + * This will return all the OBP users who have the link in code.accountholder.MapperAccountHolders. + * This field is tricky, it belongs to Trait `BankAccount` directly, not a filed in `MappedBankAccount` + * So this method always need to call the Model `MapperAccountHolders` and get the data there. + * Note: + * We need manully create records for`MapperAccountHolders`, then we can get the data back. + * each time when we create a account, we need call `getOrCreateAccountHolder` + * eg1: code.sandbox.OBPDataImport#setAccountOwner used in createSandBox + * eg2: code.model.dataAccess.AuthUser#updateUserAccountViews used in Adapter create accounts. + * eg3: code.bankconnectors.Connector#setAccountHolder used in api level create account. + */ + final def userOwners: Set[User] = { val accountHolders = AccountHolders.accountHolders.vend.getAccountHolders(bankId, accountId) if(accountHolders.isEmpty) { //account holders are not all set up in the db yet, so we might not get any back. //In this case, we just use the previous behaviour, which did not return very much information at all Set(new User { - val resourceUserId = UserId(-1) + val userPrimaryKey = UserPrimaryKey(-1) val userId = "" val idGivenByProvider = "" val provider = "" @@ -328,6 +343,25 @@ trait BankAccount extends MdcLoggable { } } + /** + * Note: There are two types of account-owners in OBP: the OBP users and the customers(in a real bank, these should from Main Frame) + * This method is in processing, not finished yet. + * For now, it just returns the Customers link to the OBP user, both for `Sandbox Mode` and `MainFrame Mode`. + * + * Maybe later, we need to create a new model, store the link between account<--> Customers. But this is not OBP Standard, these customers should come + * from MainFrame, this is only for MainFrame Mode. We need to clarify what kind of Customers we can get from MainFrame. + * + */ + final def customerOwners: Set[Customer] = { + val customerList = for{ + accountHolder <- (AccountHolders.accountHolders.vend.getAccountHolders(bankId, accountId).toList) + customers <- Customer.customerProvider.vend.getCustomersByUserId(accountHolder.userId) + } yield { + customers + } + customerList.toSet + } + private def viewNotAllowed(view : View ) = Failure(s"${UserNoPermissionAccessView} Current VIEW_ID (${view.viewId.value})") diff --git a/src/main/scala/code/model/Metadata.scala b/src/main/scala/code/model/Metadata.scala index c81186e3d..cc2140130 100644 --- a/src/main/scala/code/model/Metadata.scala +++ b/src/main/scala/code/model/Metadata.scala @@ -126,7 +126,7 @@ trait CounterpartyMetadata { * @param: longitude * @param: latitude */ - val addCorporateLocation: (UserId, Date, Double, Double) => Boolean + val addCorporateLocation: (UserPrimaryKey, Date, Double, Double) => Boolean val deleteCorporateLocation: () => Boolean /** * @param: userId @@ -134,7 +134,7 @@ trait CounterpartyMetadata { * @param: longitude * @param: latitude */ - val addPhysicalLocation: (UserId, Date, Double, Double) => Boolean + val addPhysicalLocation: (UserPrimaryKey, Date, Double, Double) => Boolean val deletePhysicalLocation: () => Boolean val addPublicAlias: (String) => Boolean val addPrivateAlias: (String) => Boolean @@ -154,7 +154,7 @@ class TransactionMetadata( * @param: text * @param: datePosted */ - val addComment : (UserId, ViewId, String, Date) => Box[Comment], + val addComment : (UserPrimaryKey, ViewId, String, Date) => Box[Comment], /** * @param: commentId */ @@ -167,7 +167,7 @@ class TransactionMetadata( * @param: tag * @param: datePosted */ - val addTag: (UserId, ViewId, String, Date) => Box[TransactionTag], + val addTag: (UserPrimaryKey, ViewId, String, Date) => Box[TransactionTag], /** * @param: tagId */ @@ -180,7 +180,7 @@ class TransactionMetadata( * @param: datePosted * @param: imageURL */ - val addImage : (UserId, ViewId, String, Date, String) => Box[TransactionImage], + val addImage : (UserPrimaryKey, ViewId, String, Date, String) => Box[TransactionImage], /** * @param: imageId */ @@ -200,7 +200,7 @@ class TransactionMetadata( * @param: longitude * @param: latitude */ - val addWhereTag : (UserId, ViewId, Date, Double, Double) => Boolean, + val addWhereTag : (UserPrimaryKey, ViewId, Date, Double, Double) => Boolean, /** * @param: viewId */ diff --git a/src/main/scala/code/model/ModeratedBankingData.scala b/src/main/scala/code/model/ModeratedBankingData.scala index 0739c7df0..682fbb937 100644 --- a/src/main/scala/code/model/ModeratedBankingData.scala +++ b/src/main/scala/code/model/ModeratedBankingData.scala @@ -108,16 +108,16 @@ class ModeratedTransactionMetadata( val ownerComment : Moderated[String], val addOwnerComment : Moderated[(String => Boolean)], val comments : Moderated[List[Comment]], - val addComment: Moderated[(UserId, ViewId, String, Date) => Box[Comment]], + val addComment: Moderated[(UserPrimaryKey, ViewId, String, Date) => Box[Comment]], private val deleteComment: Moderated[(String) => Box[Boolean]], val tags : Moderated[List[TransactionTag]], - val addTag : Moderated[(UserId, ViewId, String, Date) => Box[TransactionTag]], + val addTag : Moderated[(UserPrimaryKey, ViewId, String, Date) => Box[TransactionTag]], private val deleteTag : Moderated[(String) => Box[Boolean]], val images : Moderated[List[TransactionImage]], - val addImage : Moderated[(UserId, ViewId, String, Date, String) => Box[TransactionImage]], + val addImage : Moderated[(UserPrimaryKey, ViewId, String, Date, String) => Box[TransactionImage]], private val deleteImage : Moderated[String => Box[Boolean]], val whereTag : Moderated[Option[GeoTag]], - val addWhereTag : Moderated[(UserId, ViewId, Date, Double, Double) => Boolean], + val addWhereTag : Moderated[(UserPrimaryKey, ViewId, Date, Double, Double) => Boolean], private val deleteWhereTag : Moderated[(ViewId) => Boolean] ){ @@ -339,8 +339,8 @@ class ModeratedOtherBankAccountMetadata( val addURL : Moderated[(String) => Boolean], val addImageURL : Moderated[(String) => Boolean], val addOpenCorporatesURL : Moderated[(String) => Boolean], - val addCorporateLocation : Moderated[(UserId, Date, Double, Double) => Boolean], - val addPhysicalLocation : Moderated[(UserId, Date, Double, Double) => Boolean], + val addCorporateLocation : Moderated[(UserPrimaryKey, Date, Double, Double) => Boolean], + val addPhysicalLocation : Moderated[(UserPrimaryKey, Date, Double, Double) => Boolean], val addPublicAlias : Moderated[(String) => Boolean], val addPrivateAlias : Moderated[(String) => Boolean], val deleteCorporateLocation : Moderated[() => Boolean], diff --git a/src/main/scala/code/model/User.scala b/src/main/scala/code/model/User.scala index 07c9a8637..43b256387 100644 --- a/src/main/scala/code/model/User.scala +++ b/src/main/scala/code/model/User.scala @@ -45,16 +45,38 @@ import code.users.Users import code.util.Helper.MdcLoggable import net.liftweb.mapper.By -case class UserId(val value : Long) { +case class UserPrimaryKey(val value : Long) { override def toString = value.toString } - -// TODO Document clearly the difference between this and AuthUser - +/** + * An O-R mapped "User" class that includes first name, last name, password + * + * 1 AuthUser : is used for authentication, only for webpage Login in stuff + * 1) It is MegaProtoUser, has lots of methods for validation username, password, email .... + * Such as lost password, reset password ..... + * Lift have some helper methods to make these things easily. + * + * + * + * 2 ResourceUser: is only a normal LongKeyedMapper + * 1) All the accounts, transactions ,roles, views, accountHolders, customers... should be linked to ResourceUser.userId_ field. + * 2) The consumer keys, tokens are also belong ResourceUser + * + * + * 3 RelationShips: + * 1)When `Sign up` new user --> create AuthUser --> call AuthUser.save() --> create ResourceUser user. + * They share the same username and email. + * 2)AuthUser `user` field as the Foreign Key to link to Resource User. + * one AuthUser <---> one ResourceUser + * + */ trait User extends MdcLoggable { - - def resourceUserId : UserId + + /**This will return resouceUser primary key: it is a long value !!! + * This should not be exposed to outside. */ + def userPrimaryKey : UserPrimaryKey + /** This will be a UUID for Resource User Docment */ def userId: String def idGivenByProvider: String @@ -88,7 +110,7 @@ trait User extends MdcLoggable { */ final def hasViewAccess(view: View): Boolean ={ val viewImpl = view.asInstanceOf[ViewImpl] - !(ViewPrivileges.count(By(ViewPrivileges.user, this.resourceUserId.value), By(ViewPrivileges.view, viewImpl.id)) == 0) + !(ViewPrivileges.count(By(ViewPrivileges.user, this.userPrimaryKey.value), By(ViewPrivileges.view, viewImpl.id)) == 0) } def assignedEntitlements : List[Entitlement] = { diff --git a/src/main/scala/code/model/View.scala b/src/main/scala/code/model/View.scala index 6438cb35e..640576ccc 100644 --- a/src/main/scala/code/model/View.scala +++ b/src/main/scala/code/model/View.scala @@ -403,7 +403,7 @@ trait View { else None - val addWhereTagFunc : Option[(UserId, ViewId, Date, Double, Double) => Boolean] = + val addWhereTagFunc : Option[(UserPrimaryKey, ViewId, Date, Double, Double) => Boolean] = if(canAddWhereTag) Some(transaction.metadata.addWhereTag) else @@ -609,7 +609,7 @@ trait View { def moderateAccount(bankAccount: BankAccount) : Box[ModeratedBankAccount] = { if(canSeeTransactionThisBankAccount) { - val owners : Set[User] = if(canSeeBankAccountOwners) bankAccount.owners else Set() + val owners : Set[User] = if(canSeeBankAccountOwners) bankAccount.userOwners else Set() val balance = if(canSeeBankAccountBalance) bankAccount.balance.toString else "" val accountType = if(canSeeBankAccountType) Some(bankAccount.accountType) else None val currency = if(canSeeBankAccountCurrency) Some(bankAccount.currency) else None diff --git a/src/main/scala/code/model/dataAccess/AuthUser.scala b/src/main/scala/code/model/dataAccess/AuthUser.scala index 70159b8f2..2d1f06efc 100644 --- a/src/main/scala/code/model/dataAccess/AuthUser.scala +++ b/src/main/scala/code/model/dataAccess/AuthUser.scala @@ -59,9 +59,6 @@ import scala.collection.immutable.List /** * An O-R mapped "User" class that includes first name, last name, password * - * - * // TODO Document the difference between this and AuthUser / ResourceUser - * * 1 AuthUser : is used for authentication, only for webpage Login in stuff * 1) It is MegaProtoUser, has lots of methods for validation username, password, email .... * Such as lost password, reset password ..... @@ -79,7 +76,6 @@ import scala.collection.immutable.List * They share the same username and email. * 2)AuthUser `user` field as the Foreign Key to link to Resource User. * one AuthUser <---> one ResourceUser - * * */ class AuthUser extends MegaProtoUser[AuthUser] with Logger { diff --git a/src/main/scala/code/model/dataAccess/BankAccountCreationDispatcher.scala b/src/main/scala/code/model/dataAccess/BankAccountCreationDispatcher.scala index 3ba8f8eb8..60a85e51b 100644 --- a/src/main/scala/code/model/dataAccess/BankAccountCreationDispatcher.scala +++ b/src/main/scala/code/model/dataAccess/BankAccountCreationDispatcher.scala @@ -48,6 +48,7 @@ package com.tesobe.model { package code.model.dataAccess { +import code.accountholder.AccountHolders import code.api.util.APIUtil import code.bankconnectors.Connector import code.model._ @@ -90,7 +91,7 @@ import net.liftweb.common.{Failure, Full} */ def setAsOwner(bankId : BankId, accountId : AccountId, user: User): Unit = { createOwnerView(bankId, accountId, user) - Connector.connector.vend.setAccountHolder(BankIdAccountId(bankId, accountId), user) + val accountHolder = AccountHolders.accountHolders.vend.getOrCreateAccountHolder(user: User, BankIdAccountId(bankId, accountId)) } /** @@ -110,7 +111,7 @@ import net.liftweb.common.{Failure, Full} existingOwnerView match { case Full(v) => { logger.debug(s"account $accountId at bank $bankId has already an owner view") - v.users.toList.find(_.resourceUserId == user.resourceUserId) match { + v.users.toList.find(_.userPrimaryKey == user.userPrimaryKey) match { case Some(u) => { logger.debug(s"user ${user.emailAddress} has already an owner view access on account $accountId at bank $bankId") } diff --git a/src/main/scala/code/model/dataAccess/ResourceUser.scala b/src/main/scala/code/model/dataAccess/ResourceUser.scala index 99af71834..d68b8fed4 100644 --- a/src/main/scala/code/model/dataAccess/ResourceUser.scala +++ b/src/main/scala/code/model/dataAccess/ResourceUser.scala @@ -32,13 +32,32 @@ Berlin 13359, Germany package code.model.dataAccess import code.api.util.APIUtil -import code.model.{User, UserId} +import code.model.{User, UserPrimaryKey} import code.util.MappedUUID import net.liftweb.mapper._ /** - * Refer to AuthUser, see the difference between AuthUser and ResourceUser - */ + * An O-R mapped "User" class that includes first name, last name, password + * + * 1 AuthUser : is used for authentication, only for webpage Login in stuff + * 1) It is MegaProtoUser, has lots of methods for validation username, password, email .... + * Such as lost password, reset password ..... + * Lift have some helper methods to make these things easily. + * + * + * + * 2 ResourceUser: is only a normal LongKeyedMapper + * 1) All the accounts, transactions ,roles, views, accountHolders, customers... should be linked to ResourceUser.userId_ field. + * 2) The consumer keys, tokens are also belong ResourceUser + * + * + * 3 RelationShips: + * 1)When `Sign up` new user --> create AuthUser --> call AuthUser.save() --> create ResourceUser user. + * They share the same username and email. + * 2)AuthUser `user` field as the Foreign Key to link to Resource User. + * one AuthUser <---> one ResourceUser + * + */ class ResourceUser extends LongKeyedMapper[ResourceUser] with User with ManyToMany with OneToMany[Long, ResourceUser]{ def getSingleton = ResourceUser def primaryKeyField = id @@ -68,7 +87,7 @@ class ResourceUser extends LongKeyedMapper[ResourceUser] with User with ManyToMa } def idGivenByProvider = providerId.get - def resourceUserId = UserId(id.get) + def userPrimaryKey = UserPrimaryKey(id.get) def userId = userId_.get @@ -79,7 +98,7 @@ class ResourceUser extends LongKeyedMapper[ResourceUser] with User with ManyToMa ResourceUserCaseClass( emailAddress = emailAddress, idGivenByProvider = idGivenByProvider, - resourceUserId = resourceUserId.value, + resourceUserId = userPrimaryKey.value, userId = userId, name = name, provider = provider diff --git a/src/main/scala/code/remotedata/RemotedataAccountHolders.scala b/src/main/scala/code/remotedata/RemotedataAccountHolders.scala index 733d55afa..327be1f2c 100644 --- a/src/main/scala/code/remotedata/RemotedataAccountHolders.scala +++ b/src/main/scala/code/remotedata/RemotedataAccountHolders.scala @@ -11,9 +11,6 @@ object RemotedataAccountHolders extends ObpActorInit with AccountHolders { val cc = RemotedataAccountHoldersCaseClasses - override def createAccountHolder(userId: Long, bankId: String, accountId: String): Boolean = - extractFuture(actor ? cc.createAccountHolder(userId, bankId, accountId)) - override def getOrCreateAccountHolder(user: User, bankAccountUID :BankIdAccountId): Box[MapperAccountHolders] = extractFutureToBox(actor ? cc.getOrCreateAccountHolder(user: User, bankAccountUID :BankIdAccountId)) diff --git a/src/main/scala/code/remotedata/RemotedataAccountHoldersActor.scala b/src/main/scala/code/remotedata/RemotedataAccountHoldersActor.scala index 6f01c85eb..57f29138b 100644 --- a/src/main/scala/code/remotedata/RemotedataAccountHoldersActor.scala +++ b/src/main/scala/code/remotedata/RemotedataAccountHoldersActor.scala @@ -14,10 +14,6 @@ class RemotedataAccountHoldersActor extends Actor with ObpActorHelper with MdcLo def receive = { - case cc.createAccountHolder(userId: Long, bankId: String, accountId: String) => - logger.debug("createAccountHolder(" + userId +", "+ bankId +", "+ accountId +", " +")") - sender ! extractResult(mapper.createAccountHolder(userId, bankId, accountId)) - case cc.getOrCreateAccountHolder(user: User, account :BankIdAccountId) => logger.debug("getOrCreateAccountHolder(" + user +", "+ account +", " +")") sender ! extractResult(mapper.getOrCreateAccountHolder(user: User, account :BankIdAccountId)) diff --git a/src/main/scala/code/remotedata/RemotedataComments.scala b/src/main/scala/code/remotedata/RemotedataComments.scala index a65b02c56..a72a59c67 100644 --- a/src/main/scala/code/remotedata/RemotedataComments.scala +++ b/src/main/scala/code/remotedata/RemotedataComments.scala @@ -18,7 +18,7 @@ object RemotedataComments extends ObpActorInit with Comments { def getComments(bankId : BankId, accountId : AccountId, transactionId : TransactionId)(viewId : ViewId) : List[Comment] = extractFuture(actor ? cc.getComments(bankId, accountId, transactionId, viewId)) - def addComment(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(userId: UserId, viewId : ViewId, text : String, datePosted : Date) : Box[Comment] = + def addComment(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(userId: UserPrimaryKey, viewId : ViewId, text : String, datePosted : Date) : Box[Comment] = extractFutureToBox(actor ? cc.addComment(bankId, accountId, transactionId, userId, viewId, text, datePosted)) def deleteComment(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(commentId : String) : Box[Boolean] = diff --git a/src/main/scala/code/remotedata/RemotedataCounterparties.scala b/src/main/scala/code/remotedata/RemotedataCounterparties.scala index 29adf9645..3a8ba925d 100644 --- a/src/main/scala/code/remotedata/RemotedataCounterparties.scala +++ b/src/main/scala/code/remotedata/RemotedataCounterparties.scala @@ -109,10 +109,10 @@ object RemotedataCounterparties extends ObpActorInit with Counterparties { override def addMoreInfo(counterpartyId : String, moreInfo: String): Box[Boolean] = extractFutureToBox(actor ? cc.addMoreInfo(counterpartyId, moreInfo)) - override def addPhysicalLocation(counterpartyId : String, userId: UserId, datePosted : Date, longitude : Double, latitude : Double): Box[Boolean] = + override def addPhysicalLocation(counterpartyId : String, userId: UserPrimaryKey, datePosted : Date, longitude : Double, latitude : Double): Box[Boolean] = extractFutureToBox(actor ? cc.addPhysicalLocation(counterpartyId, userId, datePosted, longitude, latitude)) - override def addCorporateLocation(counterpartyId : String, userId: UserId, datePosted : Date, longitude : Double, latitude : Double): Box[Boolean] = + override def addCorporateLocation(counterpartyId : String, userId: UserPrimaryKey, datePosted : Date, longitude : Double, latitude : Double): Box[Boolean] = extractFutureToBox(actor ? cc.addCorporateLocation(counterpartyId, userId, datePosted, longitude, latitude)) override def deletePhysicalLocation(counterpartyId: String): Box[Boolean] = diff --git a/src/main/scala/code/remotedata/RemotedataCounterpartiesActor.scala b/src/main/scala/code/remotedata/RemotedataCounterpartiesActor.scala index eab60e839..f12234fbe 100644 --- a/src/main/scala/code/remotedata/RemotedataCounterpartiesActor.scala +++ b/src/main/scala/code/remotedata/RemotedataCounterpartiesActor.scala @@ -142,11 +142,11 @@ class RemotedataCounterpartiesActor extends Actor with ObpActorHelper with MdcLo logger.debug("addMoreInfo(" + counterpartyId + ", " + moreInfo +")") sender ! extractResult(mapper.addMoreInfo(counterpartyId, moreInfo)) - case cc.addPhysicalLocation(counterpartyId : String, userId: UserId, datePosted : Date, longitude : Double, latitude : Double) => + case cc.addPhysicalLocation(counterpartyId : String, userId: UserPrimaryKey, datePosted : Date, longitude : Double, latitude : Double) => logger.debug("addPhysicalLocation(" + counterpartyId + ", " + userId + ", " + datePosted + ", " + longitude + ", " + latitude +")") sender ! extractResult(mapper.addPhysicalLocation(counterpartyId, userId, datePosted, longitude, latitude)) - case cc.addCorporateLocation(counterpartyId : String, userId: UserId, datePosted : Date, longitude : Double, latitude : Double) => + case cc.addCorporateLocation(counterpartyId : String, userId: UserPrimaryKey, datePosted : Date, longitude : Double, latitude : Double) => logger.debug("addCorporateLocation(" + counterpartyId + ", " + userId + ", " + datePosted + ", " + longitude + ", " + latitude +")") sender ! extractResult(mapper.addCorporateLocation(counterpartyId, userId, datePosted, longitude, latitude)) diff --git a/src/main/scala/code/remotedata/RemotedataTags.scala b/src/main/scala/code/remotedata/RemotedataTags.scala index 7099874fa..d88790bfc 100644 --- a/src/main/scala/code/remotedata/RemotedataTags.scala +++ b/src/main/scala/code/remotedata/RemotedataTags.scala @@ -16,7 +16,7 @@ object RemotedataTags extends ObpActorInit with Tags { def getTags(bankId : BankId, accountId : AccountId, transactionId : TransactionId)(viewId : ViewId) : List[TransactionTag] = extractFuture(actor ? cc.getTags(bankId, accountId, transactionId, viewId)) - def addTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(userId: UserId, viewId : ViewId, tagText : String, datePosted : Date) : Box[TransactionTag] = + def addTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(userId: UserPrimaryKey, viewId : ViewId, tagText : String, datePosted : Date) : Box[TransactionTag] = extractFutureToBox(actor ? cc.addTag(bankId, accountId, transactionId, userId, viewId, tagText, datePosted)) def deleteTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(tagId : String) : Box[Boolean] = diff --git a/src/main/scala/code/remotedata/RemotedataTransactionImages.scala b/src/main/scala/code/remotedata/RemotedataTransactionImages.scala index 97dd767da..d096fdbde 100644 --- a/src/main/scala/code/remotedata/RemotedataTransactionImages.scala +++ b/src/main/scala/code/remotedata/RemotedataTransactionImages.scala @@ -16,7 +16,7 @@ object RemotedataTransactionImages extends ObpActorInit with TransactionImages { extractFuture(actor ? cc.getImagesForTransaction(bankId, accountId, transactionId, viewId)) def addTransactionImage(bankId : BankId, accountId : AccountId, transactionId: TransactionId) - (userId: UserId, viewId : ViewId, description : String, datePosted : Date, imageURL: String) : Box[TransactionImage] = + (userId: UserPrimaryKey, viewId : ViewId, description : String, datePosted : Date, imageURL: String) : Box[TransactionImage] = extractFutureToBox(actor ? cc.addTransactionImage(bankId, accountId, transactionId, userId, viewId, description, datePosted, imageURL)) def deleteTransactionImage(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(imageId : String) : Box[Boolean] = diff --git a/src/main/scala/code/remotedata/RemotedataTransactionImagesActor.scala b/src/main/scala/code/remotedata/RemotedataTransactionImagesActor.scala index 78a9d802a..b7fc6acc2 100644 --- a/src/main/scala/code/remotedata/RemotedataTransactionImagesActor.scala +++ b/src/main/scala/code/remotedata/RemotedataTransactionImagesActor.scala @@ -20,7 +20,7 @@ class RemotedataTransactionImagesActor extends Actor with ObpActorHelper with Md logger.debug("getImagesForTransaction(" + bankId +", "+ accountId +", "+ transactionId +", "+ viewId +")") sender ! extractResult(mapper.getImagesForTransaction(bankId, accountId, transactionId)(viewId)) - case cc.addTransactionImage(bankId : BankId, accountId : AccountId, transactionId: TransactionId, userId: UserId, viewId : ViewId, description : String, datePosted : Date, imageURL: String) => + case cc.addTransactionImage(bankId : BankId, accountId : AccountId, transactionId: TransactionId, userId: UserPrimaryKey, viewId : ViewId, description : String, datePosted : Date, imageURL: String) => logger.debug("addTransactionImage( " + bankId +", "+ accountId +", "+ transactionId +", "+ userId +", "+ viewId + ", "+ description + ", " + datePosted + ", " + imageURL + ")") sender ! extractResult(mapper.addTransactionImage(bankId, accountId, transactionId)(userId, viewId, description, datePosted, imageURL)) diff --git a/src/main/scala/code/remotedata/RemotedataViews.scala b/src/main/scala/code/remotedata/RemotedataViews.scala index aeadc3b7c..2f2ac1819 100644 --- a/src/main/scala/code/remotedata/RemotedataViews.scala +++ b/src/main/scala/code/remotedata/RemotedataViews.scala @@ -18,6 +18,9 @@ object RemotedataViews extends ObpActorInit with Views { def permission(account: BankIdAccountId, user: User): Box[Permission] = extractFutureToBox(actor ? cc.permission(account, user)) + + def getPermissionForUser(user: User): Box[Permission] = + extractFutureToBox(actor ? cc.getPermissionForUser(user)) def addPermission(viewIdBankIdAccountId: ViewIdBankIdAccountId, user: User): Box[View] = extractFutureToBox(actor ? cc.addPermission(viewIdBankIdAccountId, user)) diff --git a/src/main/scala/code/remotedata/RemotedataViewsActor.scala b/src/main/scala/code/remotedata/RemotedataViewsActor.scala index d5ef8ff1a..f54c7c266 100644 --- a/src/main/scala/code/remotedata/RemotedataViewsActor.scala +++ b/src/main/scala/code/remotedata/RemotedataViewsActor.scala @@ -26,6 +26,10 @@ class RemotedataViewsActor extends Actor with ObpActorHelper with MdcLoggable { logger.debug("permission(" + account +"," + user +")") sender ! extractResult(mapper.permission(account, user)) + case cc.getPermissionForUser(user: User) => + logger.debug("permission(" +user +")") + sender ! extractResult(mapper.getPermissionForUser(user)) + case cc.revokePermission(viewIdBankIdAccountId : ViewIdBankIdAccountId, user : User) => logger.debug("revokePermission(" + viewIdBankIdAccountId +"," + user +")") sender ! extractResult(mapper.revokePermission(viewIdBankIdAccountId, user)) diff --git a/src/main/scala/code/remotedata/RemotedataWhereTags.scala b/src/main/scala/code/remotedata/RemotedataWhereTags.scala index f6edb5209..4508478d9 100644 --- a/src/main/scala/code/remotedata/RemotedataWhereTags.scala +++ b/src/main/scala/code/remotedata/RemotedataWhereTags.scala @@ -17,8 +17,8 @@ object RemotedataWhereTags extends ObpActorInit with WhereTags { extractFutureToBox(actor ? cc.getWhereTagForTransaction(bankId, accountId, transactionId, viewId)) def addWhereTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId) - (userId: UserId, viewId : ViewId, datePosted : Date, longitude : Double, latitude : Double) : Boolean = - extractFuture(actor ? cc.addWhereTag(bankId, accountId, transactionId, userId: UserId, viewId : ViewId, datePosted : Date, longitude : Double, latitude : Double)) + (userId: UserPrimaryKey, viewId : ViewId, datePosted : Date, longitude : Double, latitude : Double) : Boolean = + extractFuture(actor ? cc.addWhereTag(bankId, accountId, transactionId, userId: UserPrimaryKey, viewId : ViewId, datePosted : Date, longitude : Double, latitude : Double)) def deleteWhereTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(viewId : ViewId) : Boolean = extractFuture(actor ? cc.deleteWhereTag(bankId, accountId, transactionId, viewId)) diff --git a/src/main/scala/code/remotedata/RemotedataWhereTagsActor.scala b/src/main/scala/code/remotedata/RemotedataWhereTagsActor.scala index bb6b70f98..861ca3abc 100644 --- a/src/main/scala/code/remotedata/RemotedataWhereTagsActor.scala +++ b/src/main/scala/code/remotedata/RemotedataWhereTagsActor.scala @@ -28,9 +28,9 @@ class RemotedataWhereTagsActor extends Actor with ObpActorHelper with MdcLoggabl logger.debug("deleteWhereTag(" + bankId +", "+ accountId + ", "+ transactionId + ", "+ viewId + ")") sender ! extractResult(mapper.deleteWhereTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(viewId : ViewId)) - case cc.addWhereTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId, userId: UserId, viewId : ViewId, datePosted : Date, longitude : Double, latitude : Double) => + case cc.addWhereTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId, userId: UserPrimaryKey, viewId : ViewId, datePosted : Date, longitude : Double, latitude : Double) => logger.debug("addWhereTag(" + bankId +", "+ accountId + ", "+ transactionId + ", "+ userId + ", " + viewId + ", "+ datePosted + ", "+ longitude + ", "+ latitude + ")") - sender ! extractResult(mapper.addWhereTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(userId: UserId, viewId : ViewId, datePosted : Date, longitude : Double, latitude : Double)) + sender ! extractResult(mapper.addWhereTag(bankId : BankId, accountId : AccountId, transactionId: TransactionId)(userId: UserPrimaryKey, viewId : ViewId, datePosted : Date, longitude : Double, latitude : Double)) case message => logger.warn("[AKKA ACTOR ERROR - REQUEST NOT RECOGNIZED] " + message) diff --git a/src/main/scala/code/sandbox/OBPDataImport.scala b/src/main/scala/code/sandbox/OBPDataImport.scala index 0b00e4a0b..9a628d239 100644 --- a/src/main/scala/code/sandbox/OBPDataImport.scala +++ b/src/main/scala/code/sandbox/OBPDataImport.scala @@ -174,8 +174,8 @@ trait OBPDataImport extends MdcLoggable { //println("{resourceUserOwner: " + resourceUserOwner) resourceUserOwner match { - case Some(o) => { - AccountHolders.accountHolders.vend.createAccountHolder(o.resourceUserId.value, account.bankId.value, account.accountId.value) + case Some(user) => { + val accountHolder = AccountHolders.accountHolders.vend.getOrCreateAccountHolder(user, BankIdAccountId(account.bankId, account.accountId)) } case None => { //This shouldn't happen as AuthUser should generate the ResourceUsers when saved diff --git a/src/main/scala/code/views/MapperViews.scala b/src/main/scala/code/views/MapperViews.scala index eb9729259..3e75426a5 100644 --- a/src/main/scala/code/views/MapperViews.scala +++ b/src/main/scala/code/views/MapperViews.scala @@ -48,7 +48,7 @@ object MapperViews extends Views with MdcLoggable { //search ViewPrivileges to get all views for user and then filter the views // by bankPermalink and accountPermalink //TODO: do it in a single query with a join - val privileges = ViewPrivileges.findAll(By(ViewPrivileges.user, user.resourceUserId.value)) + val privileges = ViewPrivileges.findAll(By(ViewPrivileges.user, user.userPrimaryKey.value)) val views = privileges.flatMap(_.view.obj).filter(v => if (ALLOW_PUBLIC_VIEWS) { v.accountId == account.accountId && @@ -62,12 +62,18 @@ object MapperViews extends Views with MdcLoggable { Full(Permission(user, views)) } + def getPermissionForUser(user: User): Box[Permission] = { + val privileges = ViewPrivileges.findAll(By(ViewPrivileges.user, user.userPrimaryKey.value)) + val views = privileges.flatMap(_.view.obj) + Full(Permission(user, views)) + } + private def getOrCreateViewPrivilege(user: User, viewImpl: ViewImpl): Box[ViewImpl] = { - if (ViewPrivileges.count(By(ViewPrivileges.user, user.resourceUserId.value), By(ViewPrivileges.view, viewImpl.id)) == 0) { + if (ViewPrivileges.count(By(ViewPrivileges.user, user.userPrimaryKey.value), By(ViewPrivileges.view, viewImpl.id)) == 0) { //logger.debug(s"saving ViewPrivileges for user ${user.resourceUserId.value} for view ${vImpl.id}") // SQL Insert ViewPrivileges val saved = ViewPrivileges.create. - user(user.resourceUserId.value). + user(user.userPrimaryKey.value). view(viewImpl.id). save if (saved) { @@ -118,7 +124,7 @@ object MapperViews extends Views with MdcLoggable { val res = for { viewImpl <- ViewImpl.find(viewUID) - vp: ViewPrivileges <- ViewPrivileges.find(By(ViewPrivileges.user, user.resourceUserId.value), By(ViewPrivileges.view, viewImpl.id)) + vp: ViewPrivileges <- ViewPrivileges.find(By(ViewPrivileges.user, user.userPrimaryKey.value), By(ViewPrivileges.view, viewImpl.id)) deletable <- accessRemovableAsBox(viewImpl, user) } yield { vp.delete_! @@ -139,8 +145,8 @@ object MapperViews extends Views with MdcLoggable { //if the user is an account holder, we can't revoke access to the owner view val accountHolders = MapperAccountHolders.getAccountHolders(viewImpl.bankId, viewImpl.accountId) if(accountHolders.map {h => - h.resourceUserId - }.contains(user.resourceUserId)) { + h.userPrimaryKey + }.contains(user.userPrimaryKey)) { false } else { // if it's the owner view, we can only revoke access if there would then still be someone else @@ -160,7 +166,7 @@ object MapperViews extends Views with MdcLoggable { def revokeAllPermissions(bankId : BankId, accountId: AccountId, user : User) : Box[Boolean] = { //TODO: make this more efficient by using one query (with a join) - val allUserPrivs = ViewPrivileges.findAll(By(ViewPrivileges.user, user.resourceUserId.value)) + val allUserPrivs = ViewPrivileges.findAll(By(ViewPrivileges.user, user.userPrimaryKey.value)) val relevantAccountPrivs = allUserPrivs.filter(p => p.view.obj match { case Full(v) => { @@ -291,7 +297,7 @@ object MapperViews extends Views with MdcLoggable { } def privateViewsUserCanAccess(user: User): List[View] ={ - ViewPrivileges.findAll(By(ViewPrivileges.user, user.resourceUserId.value)).map(_.view.obj).flatten.filter(_.isPrivate) + ViewPrivileges.findAll(By(ViewPrivileges.user, user.userPrimaryKey.value)).map(_.view.obj).flatten.filter(_.isPrivate) } def privateViewsUserCanAccessForAccount(user: User, bankIdAccountId : BankIdAccountId) : List[View] = @@ -477,11 +483,11 @@ object MapperViews extends Views with MdcLoggable { def grantAccessToAllExistingViews(user : User) = { ViewImpl.findAll.foreach(v => { //Get All the views from ViewImpl table, and create the link user <--> each view. The link record the access permission. - if ( ViewPrivileges.find(By(ViewPrivileges.view, v), By(ViewPrivileges.user, user.resourceUserId.value) ).isEmpty ) + if ( ViewPrivileges.find(By(ViewPrivileges.view, v), By(ViewPrivileges.user, user.userPrimaryKey.value) ).isEmpty ) //If the user and one view has no link, it will create one . ViewPrivileges.create. view(v). - user(user.resourceUserId.value). + user(user.userPrimaryKey.value). save }) true @@ -502,10 +508,10 @@ object MapperViews extends Views with MdcLoggable { */ def grantAccessToView(user : User, view : View): Boolean = { val v = ViewImpl.find(view.uid).orNull - if ( ViewPrivileges.count(By(ViewPrivileges.view, v), By(ViewPrivileges.user, user.resourceUserId.value) ) == 0 ) + if ( ViewPrivileges.count(By(ViewPrivileges.view, v), By(ViewPrivileges.user, user.userPrimaryKey.value) ) == 0 ) ViewPrivileges.create. view(v). //explodes if no viewImpl exists, but that's okay, the test should fail then - user(user.resourceUserId.value). + user(user.userPrimaryKey.value). save else false diff --git a/src/main/scala/code/views/Views.scala b/src/main/scala/code/views/Views.scala index 10529d4d3..f018340c0 100644 --- a/src/main/scala/code/views/Views.scala +++ b/src/main/scala/code/views/Views.scala @@ -32,6 +32,7 @@ trait Views { def permissions(account : BankIdAccountId) : List[Permission] def permission(account : BankIdAccountId, user: User) : Box[Permission] + def getPermissionForUser(user: User) : Box[Permission] /** * This is for @ViewPrivileges. * It will first find the view object by `viewIdBankIdAccountId` @@ -99,8 +100,8 @@ trait Views { class RemotedataViewsCaseClasses { case class permissions(account: BankIdAccountId) + case class getPermissionForUser(user: User) case class permission(account: BankIdAccountId, user: User) - case class getOrCreateViewPrivilege(view: View, user: User) case class addPermission(viewUID: ViewIdBankIdAccountId, user: User) case class addPermissions(views: List[ViewIdBankIdAccountId], user: User) case class revokePermission(viewUID: ViewIdBankIdAccountId, user: User) diff --git a/src/test/scala/code/crm/MappedCrmEventProviderTest.scala b/src/test/scala/code/crm/MappedCrmEventProviderTest.scala index 0a6234a09..b308c3f10 100644 --- a/src/test/scala/code/crm/MappedCrmEventProviderTest.scala +++ b/src/test/scala/code/crm/MappedCrmEventProviderTest.scala @@ -73,7 +73,7 @@ class MappedCrmEventProviderTest extends ServerSetup with DefaultUsers { Given("MappedCrmEvent exists for a user on a bank") MappedCrmEvent.find( By(MappedCrmEvent.mBankId, testBankId1.toString), - By(MappedCrmEvent.mUserId, resourceUser1.resourceUserId.value) + By(MappedCrmEvent.mUserId, resourceUser1.userPrimaryKey.value) ).isDefined should equal(true) When("We try to get it by bank and user") @@ -111,7 +111,7 @@ class MappedCrmEventProviderTest extends ServerSetup with DefaultUsers { Given("MappedCrmEvent exists for a user") MappedCrmEvent.find( By(MappedCrmEvent.mBankId, testBankId2.toString), - By(MappedCrmEvent.mUserId, resourceUser2.resourceUserId.value) + By(MappedCrmEvent.mUserId, resourceUser2.userPrimaryKey.value) ).isDefined should equal(true) When("We try to get them") diff --git a/src/test/scala/code/model/AuthUserTest.scala b/src/test/scala/code/model/AuthUserTest.scala index 035965e5e..719f44c5e 100644 --- a/src/test/scala/code/model/AuthUserTest.scala +++ b/src/test/scala/code/model/AuthUserTest.scala @@ -40,8 +40,8 @@ class AuthUserTest extends ServerSetup with DefaultUsers { var accountholder1 = MapperAccountHolders.getAccountHolders(bankIdAccountId.bankId, bankIdAccountId.accountId) var accountholder2 = MapperAccountHolders.getAccountHolders(bankIdAccountId2.bankId, bankIdAccountId2.accountId) var accountholders = MapperAccountHolders.findAll() - accountholder1.head.resourceUserId should equal(resourceUser1.resourceUserId) - accountholder2.head.resourceUserId should equal(resourceUser1.resourceUserId) + accountholder1.head.userPrimaryKey should equal(resourceUser1.userPrimaryKey) + accountholder2.head.userPrimaryKey should equal(resourceUser1.userPrimaryKey) accountholders.length should equal(2) Then("We check the views") //"Owner"::"Public" :: "Accountant" :: "Auditor" diff --git a/src/test/scala/code/sandbox/SandboxDataLoadingTest.scala b/src/test/scala/code/sandbox/SandboxDataLoadingTest.scala index 54a11fa58..5a50eb83e 100644 --- a/src/test/scala/code/sandbox/SandboxDataLoadingTest.scala +++ b/src/test/scala/code/sandbox/SandboxDataLoadingTest.scala @@ -291,7 +291,7 @@ class SandboxDataLoadingTest extends FlatSpec with SendServerRequests with Match foundAccount.balance.toString should equal(account.balance.amount) foundAccount.currency should equal(account.balance.currency) - foundAccount.owners.map(_.name) should equal(account.owners.toSet) + foundAccount.userOwners.map(_.name) should equal(account.owners.toSet) if(account.generate_public_view) { Views.views.vend.viewsForAccount(BankIdAccountId(foundAccount.bankId, foundAccount.accountId)).filter(_.isPublic).size should equal(1) @@ -299,7 +299,7 @@ class SandboxDataLoadingTest extends FlatSpec with SendServerRequests with Match Views.views.vend.viewsForAccount(BankIdAccountId(foundAccount.bankId, foundAccount.accountId)).filter(_.isPublic).size should equal(0) } - val owner = Users.users.vend.getUserByProviderId(defaultProvider, foundAccount.owners.toList.head.name).openOrThrowException(attemptedToOpenAnEmptyBox) + val owner = Users.users.vend.getUserByProviderId(defaultProvider, foundAccount.userOwners.toList.head.name).openOrThrowException(attemptedToOpenAnEmptyBox) //there should be an owner view val views = Views.views.vend.privateViewsUserCanAccessForAccount(owner, BankIdAccountId(foundAccount.bankId, foundAccount.accountId)) val ownerView = views.find(v => v.viewId.value == "owner") diff --git a/src/test/scala/code/setup/TestConnectorSetupWithStandardPermissions.scala b/src/test/scala/code/setup/TestConnectorSetupWithStandardPermissions.scala index bd06cbade..5687b0e20 100644 --- a/src/test/scala/code/setup/TestConnectorSetupWithStandardPermissions.scala +++ b/src/test/scala/code/setup/TestConnectorSetupWithStandardPermissions.scala @@ -19,7 +19,7 @@ import code.api.util.ErrorMessages._ trait TestConnectorSetupWithStandardPermissions extends TestConnectorSetup { override protected def setAccountHolder(user: User, bankId : BankId, accountId : AccountId) = { - AccountHolders.accountHolders.vend.createAccountHolder(user.resourceUserId.value, bankId.value, accountId.value) + AccountHolders.accountHolders.vend.getOrCreateAccountHolder(user, BankIdAccountId(bankId, accountId)) } override protected def grantAccessToAllExistingViews(user : User) = {