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/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/model/BankingData.scala b/src/main/scala/code/model/BankingData.scala index 3c8549938..2ee11537b 100644 --- a/src/main/scala/code/model/BankingData.scala +++ b/src/main/scala/code/model/BankingData.scala @@ -313,16 +313,17 @@ trait BankAccount extends MdcLoggable { } /** - * This will return all the obp users who has the link in code.accountholder.MapperAccountHolders. - * This field is tricky, it is belong to Trait `BankAccount` directly, not a filed in `MappedBankAccount` - * So this method always need call the Model `MapperAccountHolders`, and get the data there. + * 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. - * @return */ final def userOwners: Set[User] = { val accountHolders = AccountHolders.accountHolders.vend.getAccountHolders(bankId, accountId) @@ -342,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/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/views/MapperViews.scala b/src/main/scala/code/views/MapperViews.scala index 2d547fda8..12c76b0a8 100644 --- a/src/main/scala/code/views/MapperViews.scala +++ b/src/main/scala/code/views/MapperViews.scala @@ -62,6 +62,12 @@ object MapperViews extends Views with MdcLoggable { Full(Permission(user, views)) } + def getPermissionForUser(user: User): Box[Permission] = { + val privileges = ViewPrivileges.findAll(By(ViewPrivileges.user, user.userPrimaryId.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.userPrimaryId.value), By(ViewPrivileges.view, viewImpl.id)) == 0) { //logger.debug(s"saving ViewPrivileges for user ${user.resourceUserId.value} for view ${vImpl.id}") diff --git a/src/main/scala/code/views/Views.scala b/src/main/scala/code/views/Views.scala index 3cb237278..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,6 +100,7 @@ trait Views { class RemotedataViewsCaseClasses { case class permissions(account: BankIdAccountId) + case class getPermissionForUser(user: User) case class permission(account: BankIdAccountId, user: User) case class addPermission(viewUID: ViewIdBankIdAccountId, user: User) case class addPermissions(views: List[ViewIdBankIdAccountId], user: User)