Merge pull request #1087 from hongwei1/OBP-API-1081

Obp api 1081
This commit is contained in:
Simon Redfern 2018-09-12 12:36:03 +02:00 committed by GitHub
commit da29979db0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
61 changed files with 290 additions and 185 deletions

View File

@ -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)

View File

@ -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"

View File

@ -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(

View File

@ -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

View File

@ -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))

View File

@ -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)

View File

@ -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,

View File

@ -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 {

View File

@ -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")
}
}

View File

@ -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 = {

View File

@ -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

View File

@ -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}")
})

View File

@ -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)
),

View File

@ -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,

View File

@ -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,

View File

@ -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)

View File

@ -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()
}
}

View File

@ -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)

View File

@ -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)
}

View File

@ -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

View File

@ -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).

View File

@ -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)

View File

@ -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) =>

View File

@ -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] = ???

View File

@ -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,

View File

@ -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

View File

@ -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).

View File

@ -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)
}

View File

@ -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

View File

@ -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).

View File

@ -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)
}

View File

@ -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))

View File

@ -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)

View File

@ -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)

View File

@ -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})")

View File

@ -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
*/

View File

@ -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],

View File

@ -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] = {

View File

@ -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

View File

@ -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 {

View File

@ -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")
}

View File

@ -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

View File

@ -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))

View File

@ -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))

View File

@ -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] =

View File

@ -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] =

View File

@ -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))

View File

@ -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] =

View File

@ -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] =

View File

@ -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))

View File

@ -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))

View File

@ -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))

View File

@ -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))

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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")

View File

@ -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"

View File

@ -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")

View File

@ -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) = {