mirror of
https://github.com/OpenBankProject/API-Explorer.git
synced 2026-02-06 10:47:23 +00:00
deleted useless methods and changed the API(s) to implement the new way
This commit is contained in:
parent
097cef2e37
commit
cf8f2f90a8
@ -148,8 +148,8 @@ class Boot extends Loggable{
|
||||
val transactionsAndView : Box[(List[ModeratedTransaction], View, BankAccount)] = for {
|
||||
b <- BankAccount(bank, account) ?~ {"account " + account + " not found for bank " + bank}
|
||||
v <- View.fromUrl(viewName) ?~ {"view " + viewName + " not found for account " + account + " and bank " + bank}
|
||||
if(b.authorizedAccess(v, OBPUser.currentUser))
|
||||
} yield (b.getModeratedTransactions(v.moderate), v, b)
|
||||
transactions <- b.getModeratedTransactions(OBPUser.currentUser, v)
|
||||
} yield (transactions, v, b)
|
||||
|
||||
transactionsAndView match {
|
||||
case Failure(msg, _, _) => logger.warn("Could not get transactions and view: " + msg)
|
||||
@ -177,24 +177,23 @@ class Boot extends Loggable{
|
||||
}
|
||||
def getTransaction(URLParameters : List[String]) =
|
||||
{
|
||||
if(URLParameters.length==4)
|
||||
{
|
||||
if(URLParameters.length==4){
|
||||
val bank = URLParameters(0)
|
||||
val account = URLParameters(1)
|
||||
val transactionID = URLParameters(2)
|
||||
val viewName = URLParameters(3)
|
||||
val transaction = for{
|
||||
bankAccount <- BankAccount(bank, account) ?~ {"account " + account + " not found for bank " + bank}
|
||||
transaction <- bankAccount.transaction(transactionID) ?~ {"transaction " + transactionID + " not found in account " + account + " for bank " + bank}
|
||||
view <- View.fromUrl(viewName) ?~ {"view " + viewName + " not found"}
|
||||
if(bankAccount.authorizedAccess(view, OBPUser.currentUser))
|
||||
} yield (view.moderate(transaction),view)
|
||||
view <- View.fromUrl(viewName)
|
||||
transaction <- bankAccount.moderatedTransaction(transactionID, view, OBPUser.currentUser)
|
||||
} yield (transaction,view)
|
||||
|
||||
transaction match {
|
||||
case Failure(msg, _, _) => logger.info("Could not get transaction: " + msg)
|
||||
case _ => //don't log anything
|
||||
}
|
||||
transaction
|
||||
transaction match {
|
||||
case Failure(msg, _, _) => logger.info("Could not get transaction: " + msg)
|
||||
case _ => //don't log anything
|
||||
}
|
||||
|
||||
transaction
|
||||
}
|
||||
else
|
||||
Empty
|
||||
|
||||
@ -187,23 +187,16 @@ object OBPAPI1_0 extends RestHelper with Loggable {
|
||||
val fromDate = tryo{dateFormat.parse(json.header("obp_from_date") getOrElse "")}.map(OBPFromDate(_))
|
||||
val toDate = tryo{dateFormat.parse(json.header("obp_to_date") getOrElse "")}.map(OBPToDate(_))
|
||||
|
||||
def getTransactions(bankAccount: BankAccount, view: View, user: Option[OBPUser]) = {
|
||||
if(bankAccount.authorizedAccess(view, user)) {
|
||||
val basicParams = List(OBPLimit(limit),
|
||||
OBPOffset(offset),
|
||||
OBPOrdering(sortBy, sortDirection))
|
||||
|
||||
val params : List[OBPQueryParam] = fromDate.toList ::: toDate.toList ::: basicParams
|
||||
bankAccount.getModeratedTransactions(params: _*)(view.moderate)
|
||||
} else Nil
|
||||
}
|
||||
|
||||
val basicParams = List(OBPLimit(limit),
|
||||
OBPOffset(offset),
|
||||
OBPOrdering(sortBy, sortDirection))
|
||||
val params : List[OBPQueryParam] = fromDate.toList ::: toDate.toList ::: basicParams
|
||||
val response = for {
|
||||
bankAccount <- BankAccount(bankAlias, accountAlias)
|
||||
view <- View.fromUrl(viewName) //TODO: This will have to change if we implement custom view names for different accounts
|
||||
view <- View.fromUrl(viewName)
|
||||
transactions <- bankAccount.getModeratedTransactions(getOBPUser(httpCode,oAuthParameters.get("oauth_token")), view, params : _*)
|
||||
} yield {
|
||||
val ts = getTransactions(bankAccount, view, getOBPUser(httpCode,oAuthParameters.get("oauth_token")))
|
||||
JsonResponse("transactions" -> ts.map(t => t.toJson(view)))
|
||||
JsonResponse("transactions" -> transactions.map(t => t.toJson(view)))
|
||||
}
|
||||
|
||||
response getOrElse InMemoryResponse(data.getBytes, headers, Nil, 401) : LiftResponse
|
||||
|
||||
@ -517,27 +517,21 @@ object OBPAPI1_1 extends RestHelper with Loggable {
|
||||
val fromDate = tryo{dateFormat.parse(json.header("obp_from_date") getOrElse "")}.map(OBPFromDate(_))
|
||||
val toDate = tryo{dateFormat.parse(json.header("obp_to_date") getOrElse "")}.map(OBPToDate(_))
|
||||
|
||||
def getTransactions(bankAccount: BankAccount, view: View, user: Option[User]) = {
|
||||
if(bankAccount.authorizedAccess(view, user)) {
|
||||
val basicParams = List(OBPLimit(limit),
|
||||
OBPOffset(offset),
|
||||
OBPOrdering(sortBy, sortDirection))
|
||||
val basicParams = List(OBPLimit(limit),
|
||||
OBPOffset(offset),
|
||||
OBPOrdering(sortBy, sortDirection))
|
||||
|
||||
val params : List[OBPQueryParam] = fromDate.toList ::: toDate.toList ::: basicParams
|
||||
bankAccount.getModeratedTransactions(params: _*)(view.moderate)
|
||||
} else Nil
|
||||
}
|
||||
val params : List[OBPQueryParam] = fromDate.toList ::: toDate.toList ::: basicParams
|
||||
|
||||
def transactionsJson(transactions : List[ModeratedTransaction], v : View) : JObject = {
|
||||
("transactions" -> transactions.map(transactionJson))
|
||||
}
|
||||
|
||||
val response : Box[JsonResponse] = for {
|
||||
bankAccount <- BankAccount(bankId, accountId)
|
||||
view <- View.fromUrl(viewId) //TODO: This will have to change if we implement custom view names for different accounts
|
||||
view <- View.fromUrl(viewId)
|
||||
transactions <- bankAccount.getModeratedTransactions(getUser(httpCode,oAuthParameters.get("oauth_token")), view, params: _*)
|
||||
} yield {
|
||||
val ts = getTransactions(bankAccount, view, getUser(httpCode,oAuthParameters.get("oauth_token")))
|
||||
JsonResponse(transactionsJson(ts, view),Nil, Nil, 200)
|
||||
JsonResponse(transactionsJson(transactions, view),Nil, Nil, 200)
|
||||
}
|
||||
|
||||
response getOrElse (JsonResponse(ErrorMessage(message), Nil, Nil, 401)) : LiftResponse
|
||||
|
||||
@ -857,26 +857,21 @@ def checkIfLocationPossible(lat:Double,lon:Double) : Box[Unit] = {
|
||||
val fromDate = tryo{dateFormat.parse(json.header("obp_from_date") getOrElse "")}.map(OBPFromDate(_))
|
||||
val toDate = tryo{dateFormat.parse(json.header("obp_to_date") getOrElse "")}.map(OBPToDate(_))
|
||||
|
||||
def getTransactions(bankAccount: BankAccount, view: View, user: Option[User]) = {
|
||||
if(bankAccount.authorizedAccess(view, user)) {
|
||||
val basicParams = List(OBPLimit(limit),
|
||||
OBPOffset(offset),
|
||||
OBPOrdering(sortBy, sortDirection))
|
||||
|
||||
val params : List[OBPQueryParam] = fromDate.toList ::: toDate.toList ::: basicParams
|
||||
bankAccount.getModeratedTransactions(params: _*)(view.moderate)
|
||||
} else Nil
|
||||
}
|
||||
|
||||
for {
|
||||
val basicParams =
|
||||
List(
|
||||
OBPLimit(limit),
|
||||
OBPOffset(offset),
|
||||
OBPOrdering(sortBy, sortDirection)
|
||||
)
|
||||
val params : List[OBPQueryParam] = fromDate.toList ::: toDate.toList ::: basicParams
|
||||
for {
|
||||
bankAccount <- BankAccount(bankId, accountId)
|
||||
view <- View.fromUrl(viewId)
|
||||
transactions <- bankAccount.getModeratedTransactions(user, view, params : _*)
|
||||
} yield {
|
||||
val ts = getTransactions(bankAccount, view, user)
|
||||
val json = JSONFactory.createTransactionsJSON(ts)
|
||||
val json = JSONFactory.createTransactionsJSON(transactions)
|
||||
successJsonResponse(Extraction.decompose(json))
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
@ -887,7 +882,7 @@ def checkIfLocationPossible(lat:Double,lon:Double) : Box[Unit] = {
|
||||
for {
|
||||
account <- BankAccount(bankId, accountId)
|
||||
view <- View.fromUrl(viewId)
|
||||
moderatedTransaction <- account.moderatedTransaction(transactionId, view, user) ?~ "view/transaction not authorized"
|
||||
moderatedTransaction <- account.moderatedTransaction(transactionId, view, user)
|
||||
} yield {
|
||||
val json = JSONFactory.createTransactionJSON(moderatedTransaction)
|
||||
successJsonResponse(Extraction.decompose(json))
|
||||
|
||||
@ -35,7 +35,6 @@ import scala.math.BigDecimal
|
||||
import java.util.Date
|
||||
import scala.collection.immutable.Set
|
||||
import net.liftweb.json.JsonDSL._
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException
|
||||
import net.liftweb.json.JObject
|
||||
import net.liftweb.json.JsonDSL._
|
||||
import net.liftweb.json.JsonAST.JArray
|
||||
@ -123,46 +122,23 @@ class BankAccount(
|
||||
}
|
||||
}
|
||||
|
||||
def transactions(from: Date, to: Date): Set[Transaction] = {
|
||||
throw new NotImplementedException
|
||||
}
|
||||
|
||||
def transaction(id: String): Box[Transaction] = {
|
||||
LocalStorage.getTransaction(id, bankPermalink, permalink)
|
||||
}
|
||||
def allowPublicAccess = allowAnnoymousAccess
|
||||
|
||||
def getModeratedTransactions(moderate: Transaction => ModeratedTransaction): List[ModeratedTransaction] = {
|
||||
LocalStorage.getModeratedTransactions(permalink, bankPermalink)(moderate)
|
||||
}
|
||||
|
||||
def getModeratedTransactions(queryParams: OBPQueryParam*)(moderate: Transaction => ModeratedTransaction): List[ModeratedTransaction] = {
|
||||
LocalStorage.getModeratedTransactions(permalink, bankPermalink, queryParams: _*)(moderate)
|
||||
}
|
||||
|
||||
def getTransactions(queryParams: OBPQueryParam*) : Box[List[Transaction]] = {
|
||||
LocalStorage.getTransactions(permalink, bankPermalink, queryParams: _*)
|
||||
}
|
||||
|
||||
def getTransactions(bank: String, account: String): Box[List[Transaction]] = {
|
||||
LocalStorage.getTransactions(permalink, bankPermalink)
|
||||
}
|
||||
|
||||
def moderatedTransaction(id: String, view: View, user: Box[User]) : Box[ModeratedTransaction] = {
|
||||
if(authorizedAccess(view, user)) {
|
||||
transaction(id).map(view.moderate)
|
||||
} else Failure("view/transaction not authorized")
|
||||
}
|
||||
|
||||
def moderatedBankAccount(view: View, user: Box[User]) : Box[ModeratedBankAccount] = {
|
||||
if(authorizedAccess(view, user)){
|
||||
view.moderate(this) match {
|
||||
case Some(thisBankAccount) => Full(thisBankAccount)
|
||||
case _ => Failure("could not moderate this bank account id " + id, Empty, Empty)
|
||||
/**
|
||||
* @param the view that we want test the access to
|
||||
* @param the user that we want to see if he has access to the view or not
|
||||
* @return true if the user is allowed to access this view, false otherwise
|
||||
*/
|
||||
def authorizedAccess(view: View, user: Option[User]) : Boolean = {
|
||||
view match {
|
||||
case Public => allowPublicAccess
|
||||
case _ => user match {
|
||||
case Some(u) => {
|
||||
u.permittedViews(this).contains(view)
|
||||
}
|
||||
case None => false
|
||||
}
|
||||
}
|
||||
else
|
||||
Failure("user not allowed to access the " + view.name + " view.", Empty, Empty)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -195,7 +171,6 @@ class BankAccount(
|
||||
Failure("user : " + user.emailAddress + "don't have access to owner view on account " + id, Empty, Empty)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param a user that want to grant an other user access to a list views
|
||||
* @param the list of views ids that we want to grant access
|
||||
@ -214,11 +189,11 @@ class BankAccount(
|
||||
|
||||
lazy val viewsFormIds : Box[List[View]] =
|
||||
//if no failures then we return the Full views
|
||||
if(failureList.size == 0)
|
||||
Full(viewBoxes.flatten)
|
||||
if(failureList.size == 0)
|
||||
Full(viewBoxes.flatten)
|
||||
else
|
||||
//we return just the first failure
|
||||
failureList.head
|
||||
failureList.head
|
||||
|
||||
//check if the user have access to the owner view in this the account
|
||||
if(authorizedAccess(Owner,Full(user)))
|
||||
@ -255,6 +230,7 @@ class BankAccount(
|
||||
* @param the id of the other user that we want revoke access
|
||||
* @return a Full(true) if everything is okay, a Failure otherwise
|
||||
*/
|
||||
|
||||
def revokeAllPermission(user : User, otherUserId : String) : Box[Boolean] = {
|
||||
//check if the user have access to the owner view in this the account
|
||||
if(authorizedAccess(Owner,Full(user)))
|
||||
@ -276,22 +252,35 @@ class BankAccount(
|
||||
Failure("user : " + user.emailAddress + " don't have access to owner view on account " + id, Empty, Empty)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param the view that we want test the access to
|
||||
* @param the user that we want to see if he has access to the view or not
|
||||
* @return true if the user is allowed to access this view, false otherwise
|
||||
*/
|
||||
def authorizedAccess(view: View, user: Option[User]) : Boolean = {
|
||||
def moderatedTransaction(id: String, view: View, user: Box[User]) : Box[ModeratedTransaction] = {
|
||||
if(authorizedAccess(view, user)) {
|
||||
LocalStorage.getTransaction(id, bankPermalink, permalink).map(view.moderate)
|
||||
} else Failure("view/transaction not authorized")
|
||||
}
|
||||
|
||||
view match {
|
||||
case Public => allowPublicAccess
|
||||
case _ => user match {
|
||||
case Some(u) => {
|
||||
u.permittedViews(this).contains(view)
|
||||
}
|
||||
case None => false
|
||||
def getModeratedTransactions(user : Box[User], view : View): Box[List[ModeratedTransaction]] = {
|
||||
if(authorizedAccess(view, user))
|
||||
Full(LocalStorage.getModeratedTransactions(permalink, bankPermalink)(view.moderate))
|
||||
else
|
||||
Failure("user don't have access to the " + view.id + "view ")
|
||||
}
|
||||
|
||||
def getModeratedTransactions(user : Box[User], view : View, queryParams: OBPQueryParam*): Box[List[ModeratedTransaction]] = {
|
||||
if(authorizedAccess(view, user))
|
||||
Full(LocalStorage.getModeratedTransactions(permalink, bankPermalink, queryParams: _*)(view.moderate))
|
||||
else
|
||||
Failure("user don't have access to the " + view.id + "view ")
|
||||
}
|
||||
|
||||
def moderatedBankAccount(view: View, user: Box[User]) : Box[ModeratedBankAccount] = {
|
||||
if(authorizedAccess(view, user)){
|
||||
view.moderate(this) match {
|
||||
case Some(thisBankAccount) => Full(thisBankAccount)
|
||||
case _ => Failure("could not moderate this bank account id " + id, Empty, Empty)
|
||||
}
|
||||
}
|
||||
else
|
||||
Failure("user not allowed to access the " + view.name + " view.", Empty, Empty)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -351,10 +340,6 @@ object BankAccount {
|
||||
}
|
||||
}
|
||||
|
||||
def all : List[BankAccount] = {
|
||||
LocalStorage.getAllAccounts()
|
||||
}
|
||||
|
||||
def publicAccounts : List[BankAccount] = {
|
||||
LocalStorage.getAllPublicAccounts()
|
||||
}
|
||||
|
||||
@ -65,12 +65,12 @@ trait LocalStorage extends Loggable {
|
||||
rawTransactions.map(moderate)
|
||||
}
|
||||
|
||||
def getTransactions(permalink: String, bankPermalink: String, queryParams: OBPQueryParam*) : Box[List[Transaction]] = {
|
||||
private def getTransactions(permalink: String, bankPermalink: String, queryParams: OBPQueryParam*) : Box[List[Transaction]] = {
|
||||
val envelopesForAccount = (acc: Account) => acc.envelopes(queryParams: _*)
|
||||
getTransactions(permalink, bankPermalink, envelopesForAccount)
|
||||
}
|
||||
|
||||
def getTransactions(permalink: String, bankPermalink: String): Box[List[Transaction]] = {
|
||||
private def getTransactions(permalink: String, bankPermalink: String): Box[List[Transaction]] = {
|
||||
val envelopesForAccount = (acc: Account) => acc.allEnvelopes
|
||||
getTransactions(permalink, bankPermalink, envelopesForAccount)
|
||||
}
|
||||
@ -100,7 +100,6 @@ trait LocalStorage extends Loggable {
|
||||
def getCurrentUser : Box[User]
|
||||
def getOtherAccount(accountID : String, otherAccountID : String) : Box[OtherBankAccount]
|
||||
|
||||
def getAllAccounts() : List[BankAccount]
|
||||
def getAllPublicAccounts() : List[BankAccount]
|
||||
def getPublicBankAccounts(bank : Bank) : List[BankAccount]
|
||||
def getNonPublicBankAccounts(user : User) : List[BankAccount]
|
||||
@ -404,8 +403,6 @@ class MongoDBLocalStorage extends LocalStorage {
|
||||
} yield createTransaction(envelope,account)
|
||||
}
|
||||
|
||||
def getAllAccounts() : List[BankAccount] = Account.findAll map Account.toBankAccount
|
||||
|
||||
def getAllPublicAccounts() : List[BankAccount] = Account.findAll("anonAccess", true) map Account.toBankAccount
|
||||
|
||||
def getUser(id : String) : Box[User] =
|
||||
|
||||
Loading…
Reference in New Issue
Block a user