From 2003b80b770622516fded3edca7f1ed6ab0039a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Fri, 25 Aug 2023 05:31:28 +0200 Subject: [PATCH] feature/Enable Metric regarding Request Timeout 3 --- .../v1_0_0/EventNotificationApi.scala | 3 +- .../scala/code/api/v1_2_1/APIMethods121.scala | 96 ++++++++++--------- .../scala/code/api/v1_3_0/APIMethods130.scala | 2 + .../scala/code/api/v1_4_0/APIMethods140.scala | 4 +- .../scala/code/api/v2_0_0/APIMethods200.scala | 33 ++++--- .../scala/code/api/v2_1_0/APIMethods210.scala | 19 ++-- .../scala/code/api/v3_0_0/APIMethods300.scala | 82 +++++++++------- 7 files changed, 135 insertions(+), 104 deletions(-) diff --git a/obp-api/src/main/scala/code/api/BahrainOBF/v1_0_0/EventNotificationApi.scala b/obp-api/src/main/scala/code/api/BahrainOBF/v1_0_0/EventNotificationApi.scala index d9ae1befb1..2d40272d5b 100644 --- a/obp-api/src/main/scala/code/api/BahrainOBF/v1_0_0/EventNotificationApi.scala +++ b/obp-api/src/main/scala/code/api/BahrainOBF/v1_0_0/EventNotificationApi.scala @@ -5,6 +5,7 @@ import code.api.util.APIUtil._ import code.api.util.ApiTag import code.api.util.ApiTag._ import code.api.util.ErrorMessages._ +import code.api.util.FutureUtil.EndpointContext import com.github.dwickern.macros.NameOf.nameOf import com.openbankproject.commons.ExecutionContext.Implicits.global import net.liftweb.common.Full @@ -98,7 +99,7 @@ object APIMethods_EventNotificationApi extends RestHelper { lazy val eventNotificationsPost : OBPEndpoint = { case "event-notifications" :: Nil JsonPost _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc, UserNotLoggedIn) } yield { diff --git a/obp-api/src/main/scala/code/api/v1_2_1/APIMethods121.scala b/obp-api/src/main/scala/code/api/v1_2_1/APIMethods121.scala index 9038ada7b0..fc94233cc7 100644 --- a/obp-api/src/main/scala/code/api/v1_2_1/APIMethods121.scala +++ b/obp-api/src/main/scala/code/api/v1_2_1/APIMethods121.scala @@ -4,12 +4,14 @@ import java.net.URL import java.util.Random import java.security.SecureRandom import java.util.UUID.randomUUID + import com.tesobe.CacheKeyFromArguments import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON._ import code.api.cache.Caching import code.api.util.APIUtil._ import code.api.util.ApiTag._ import code.api.util.ErrorMessages._ +import code.api.util.FutureUtil.EndpointContext import code.api.util.NewStyle.HttpCode import code.api.util._ import code.bankconnectors._ @@ -490,7 +492,7 @@ trait APIMethods121 { //change account label // TODO Remove BANK_ID AND ACCOUNT_ID from the body? (duplicated in URL) case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) json <- NewStyle.function.tryons(InvalidJsonFormat, 400, callContext) { json.extract[UpdateAccountJSON] } @@ -721,7 +723,7 @@ trait APIMethods121 { //deletes a view on an bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId ) :: "views" :: ViewId(viewId) :: Nil JsonDelete req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -858,7 +860,7 @@ trait APIMethods121 { lazy val addPermissionForUserForBankAccountForMultipleViews : OBPEndpoint = { //add access for specific user to a list of views case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "permissions" :: provider :: providerId :: "views" :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -901,7 +903,7 @@ trait APIMethods121 { lazy val addPermissionForUserForBankAccountForOneView : OBPEndpoint = { //add access for specific user to a specific view case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "permissions" :: provider :: providerId :: "views" :: ViewId(viewId) :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -961,7 +963,7 @@ trait APIMethods121 { lazy val removePermissionForUserForBankAccountForOneView : OBPEndpoint = { //delete access for specific user to one view case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "permissions" :: provider :: providerId :: "views" :: ViewId(viewId) :: Nil JsonDelete req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -998,7 +1000,7 @@ trait APIMethods121 { lazy val removePermissionForUserForBankAccountForAllViews : OBPEndpoint = { //delete access for specific user to all the views case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "permissions" :: provider :: providerId :: "views" :: Nil JsonDelete req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -1092,7 +1094,7 @@ trait APIMethods121 { lazy val getOtherAccountMetadata : OBPEndpoint = { //get metadata of one other account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "metadata" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (account, callContext) <- NewStyle.function.checkBankAccountExists(bankId, accountId, callContext) @@ -1131,7 +1133,7 @@ trait APIMethods121 { lazy val getCounterpartyPublicAlias : OBPEndpoint = { //get public alias of other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "public_alias" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (account, callContext) <- NewStyle.function.checkBankAccountExists(bankId, accountId, callContext) @@ -1182,7 +1184,7 @@ trait APIMethods121 { lazy val addCounterpartyPublicAlias : OBPEndpoint = { //add public alias to other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "public_alias" :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -1235,7 +1237,7 @@ trait APIMethods121 { lazy val updateCounterpartyPublicAlias : OBPEndpoint = { //update public alias of other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "public_alias" :: Nil JsonPut json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -1286,7 +1288,7 @@ trait APIMethods121 { lazy val deleteCounterpartyPublicAlias : OBPEndpoint = { //delete public alias of other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "public_alias" :: Nil JsonDelete _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -1334,7 +1336,7 @@ trait APIMethods121 { lazy val getOtherAccountPrivateAlias : OBPEndpoint = { //get private alias of other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "private_alias" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (account, callContext) <- NewStyle.function.checkBankAccountExists(bankId, accountId, callContext) @@ -1379,7 +1381,7 @@ trait APIMethods121 { lazy val addOtherAccountPrivateAlias : OBPEndpoint = { //add private alias to other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "private_alias" :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -1431,7 +1433,7 @@ trait APIMethods121 { lazy val updateCounterpartyPrivateAlias : OBPEndpoint = { //update private alias of other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "private_alias" :: Nil JsonPut json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -1482,7 +1484,7 @@ trait APIMethods121 { lazy val deleteCounterpartyPrivateAlias : OBPEndpoint = { //delete private alias of other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "private_alias" :: Nil JsonDelete _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -1531,7 +1533,7 @@ trait APIMethods121 { lazy val addCounterpartyMoreInfo : OBPEndpoint = { //add more info to other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "metadata" :: "more_info" :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -1580,7 +1582,7 @@ trait APIMethods121 { lazy val updateCounterpartyMoreInfo : OBPEndpoint = { //update more info of other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "metadata" :: "more_info" :: Nil JsonPut json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -1628,7 +1630,7 @@ trait APIMethods121 { lazy val deleteCounterpartyMoreInfo : OBPEndpoint = { //delete more info of other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "metadata" :: "more_info" :: Nil JsonDelete _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -1677,7 +1679,7 @@ trait APIMethods121 { lazy val addCounterpartyUrl : OBPEndpoint = { //add url to other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "metadata" :: "url" :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -1726,7 +1728,7 @@ trait APIMethods121 { lazy val updateCounterpartyUrl : OBPEndpoint = { //update url of other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "metadata" :: "url" :: Nil JsonPut json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -1774,7 +1776,7 @@ trait APIMethods121 { lazy val deleteCounterpartyUrl : OBPEndpoint = { //delete url of other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "metadata" :: "url" :: Nil JsonDelete _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -1822,7 +1824,7 @@ trait APIMethods121 { lazy val addCounterpartyImageUrl : OBPEndpoint = { //add image url to other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "metadata" :: "image_url" :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -1870,7 +1872,7 @@ trait APIMethods121 { lazy val updateCounterpartyImageUrl : OBPEndpoint = { //update image url of other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "metadata" :: "image_url" :: Nil JsonPut json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -1912,7 +1914,7 @@ trait APIMethods121 { lazy val deleteCounterpartyImageUrl : OBPEndpoint = { //delete image url of other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "metadata" :: "image_url" :: Nil JsonDelete _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -1959,7 +1961,7 @@ trait APIMethods121 { lazy val addCounterpartyOpenCorporatesUrl : OBPEndpoint = { //add open corporate url to other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "metadata" :: "open_corporates_url" :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -2008,7 +2010,7 @@ trait APIMethods121 { lazy val updateCounterpartyOpenCorporatesUrl : OBPEndpoint = { //update open corporate url of other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "metadata" :: "open_corporates_url" :: Nil JsonPut json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -2056,7 +2058,7 @@ trait APIMethods121 { lazy val deleteCounterpartyOpenCorporatesUrl : OBPEndpoint = { //delete open corporate url of other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "metadata" :: "open_corporates_url" :: Nil JsonDelete _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -2188,7 +2190,7 @@ trait APIMethods121 { lazy val deleteCounterpartyCorporateLocation : OBPEndpoint = { //delete corporate location of other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "metadata" :: "corporate_location" :: Nil JsonDelete _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -2325,7 +2327,7 @@ trait APIMethods121 { lazy val deleteCounterpartyPhysicalLocation : OBPEndpoint = { //delete physical location of other bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: "metadata" :: "physical_location" :: Nil JsonDelete _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -2472,7 +2474,7 @@ trait APIMethods121 { lazy val getTransactionNarrative : OBPEndpoint = { //get narrative case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transactions" :: TransactionId(transactionId) :: "metadata" :: "narrative" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (user, callContext) <- authenticatedAccess(cc) metadata <- moderatedTransactionMetadataFuture(bankId, accountId, viewId, transactionId, user, callContext) @@ -2514,7 +2516,7 @@ trait APIMethods121 { lazy val addTransactionNarrative : OBPEndpoint = { //add narrative case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transactions" :: TransactionId(transactionId) :: "metadata" :: "narrative" :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (user, callContext) <- authenticatedAccess(cc) narrativeJson <- NewStyle.function.tryons(InvalidJsonFormat, 400, callContext) { json.extract[TransactionNarrativeJSON] } @@ -2552,7 +2554,7 @@ trait APIMethods121 { lazy val updateTransactionNarrative : OBPEndpoint = { //update narrative case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transactions" :: TransactionId(transactionId) :: "metadata" :: "narrative" :: Nil JsonPut json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (user, callContext) <- authenticatedAccess(cc) narrativeJson <- NewStyle.function.tryons(InvalidJsonFormat, 400, callContext) { json.extract[TransactionNarrativeJSON] } @@ -2590,7 +2592,7 @@ trait APIMethods121 { lazy val deleteTransactionNarrative : OBPEndpoint = { //delete narrative case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transactions" :: TransactionId(transactionId) :: "metadata" :: "narrative" :: Nil JsonDelete _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (user, callContext) <- authenticatedAccess(cc) metadata <- moderatedTransactionMetadataFuture(bankId, accountId, viewId, transactionId, user, callContext) @@ -2628,7 +2630,7 @@ trait APIMethods121 { lazy val getCommentsForViewOnTransaction : OBPEndpoint = { //get comments case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transactions" :: TransactionId(transactionId) :: "metadata" :: "comments" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (user, callContext) <- authenticatedAccess(cc) metadata <- moderatedTransactionMetadataFuture(bankId, accountId, viewId, transactionId, user, callContext) @@ -2668,7 +2670,7 @@ trait APIMethods121 { lazy val addCommentForViewOnTransaction : OBPEndpoint = { //add comment case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transactions" :: TransactionId(transactionId) :: "metadata" :: "comments" :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(user), callContext) <- authenticatedAccess(cc) commentJson <- NewStyle.function.tryons(InvalidJsonFormat, 400, callContext) { json.extract[PostTransactionCommentJSON] } @@ -2711,7 +2713,7 @@ trait APIMethods121 { lazy val deleteCommentForViewOnTransaction : OBPEndpoint = { //delete comment case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transactions" :: TransactionId(transactionId) :: "metadata" :: "comments":: commentId :: Nil JsonDelete _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(user), callContext) <- authenticatedAccess(cc) (account, callContext) <- NewStyle.function.checkBankAccountExists(bankId, accountId, callContext) @@ -2749,7 +2751,7 @@ trait APIMethods121 { lazy val getTagsForViewOnTransaction : OBPEndpoint = { //get tags case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transactions" :: TransactionId(transactionId) :: "metadata" :: "tags" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (user, callContext) <- authenticatedAccess(cc) metadata <- moderatedTransactionMetadataFuture(bankId, accountId, viewId, transactionId, user, callContext) @@ -2789,7 +2791,7 @@ trait APIMethods121 { lazy val addTagForViewOnTransaction : OBPEndpoint = { //add a tag case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transactions" :: TransactionId(transactionId) :: "metadata" :: "tags" :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(user), callContext) <- authenticatedAccess(cc) tagJson <- NewStyle.function.tryons(InvalidJsonFormat, 400, callContext) { json.extract[PostTransactionTagJSON] } @@ -2831,7 +2833,7 @@ trait APIMethods121 { //delete a tag case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transactions" :: TransactionId(transactionId) :: "metadata" :: "tags" :: tagId :: Nil JsonDelete _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(user), callContext) <- authenticatedAccess(cc) view <- NewStyle.function.checkViewAccessAndReturnView(viewId, BankIdAccountId(bankId, accountId), Some(user), callContext) @@ -2869,7 +2871,7 @@ trait APIMethods121 { lazy val getImagesForViewOnTransaction : OBPEndpoint = { //get images case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transactions" :: TransactionId(transactionId) :: "metadata" :: "images" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (user, callContext) <- authenticatedAccess(cc) metadata <- moderatedTransactionMetadataFuture(bankId, accountId, viewId, transactionId, user, callContext) @@ -2910,7 +2912,7 @@ trait APIMethods121 { lazy val addImageForViewOnTransaction : OBPEndpoint = { //add an image case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transactions" :: TransactionId(transactionId) :: "metadata" :: "images" :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) imageJson <- NewStyle.function.tryons(InvalidJsonFormat, 400, callContext) { json.extract[PostTransactionImageJSON] } @@ -2955,7 +2957,7 @@ trait APIMethods121 { lazy val deleteImageForViewOnTransaction : OBPEndpoint = { //delete an image case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transactions" :: TransactionId(transactionId) :: "metadata" :: "images" :: imageId :: Nil JsonDelete _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(user), callContext) <- authenticatedAccess(cc) metadata <- moderatedTransactionMetadataFuture(bankId, accountId, viewId, transactionId, Full(user), callContext) @@ -2993,7 +2995,7 @@ trait APIMethods121 { lazy val getWhereTagForViewOnTransaction : OBPEndpoint = { //get where tag case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transactions" :: TransactionId(transactionId) :: "metadata" :: "where" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(user), callContext) <- authenticatedAccess(cc) metadata <- moderatedTransactionMetadataFuture(bankId, accountId, viewId, transactionId, Full(user), callContext) @@ -3035,7 +3037,7 @@ trait APIMethods121 { lazy val addWhereTagForViewOnTransaction : OBPEndpoint = { //add where tag case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transactions" :: TransactionId(transactionId) :: "metadata" :: "where" :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(user), callContext) <- authenticatedAccess(cc) metadata <- moderatedTransactionMetadataFuture(bankId, accountId, viewId, transactionId, Full(user), callContext) @@ -3081,7 +3083,7 @@ trait APIMethods121 { lazy val updateWhereTagForViewOnTransaction : OBPEndpoint = { //update where tag case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transactions" :: TransactionId(transactionId) :: "metadata" :: "where" :: Nil JsonPut json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(user), callContext) <- authenticatedAccess(cc) metadata <- moderatedTransactionMetadataFuture(bankId, accountId, viewId, transactionId, Full(user), callContext) @@ -3128,7 +3130,7 @@ trait APIMethods121 { lazy val deleteWhereTagForViewOnTransaction : OBPEndpoint = { //delete where tag case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transactions" :: TransactionId(transactionId) :: "metadata" :: "where" :: Nil JsonDelete _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (user, callContext) <- authenticatedAccess(cc) (account, callContext) <- NewStyle.function.checkBankAccountExists(bankId, accountId, callContext) @@ -3162,7 +3164,7 @@ trait APIMethods121 { lazy val getOtherAccountForTransaction : OBPEndpoint = { //get other account of a transaction case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transactions":: TransactionId(transactionId) :: "other_account" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (account, callContext) <- NewStyle.function.checkBankAccountExists(bankId, accountId, callContext) diff --git a/obp-api/src/main/scala/code/api/v1_3_0/APIMethods130.scala b/obp-api/src/main/scala/code/api/v1_3_0/APIMethods130.scala index d90eec2b0d..9718d681e7 100644 --- a/obp-api/src/main/scala/code/api/v1_3_0/APIMethods130.scala +++ b/obp-api/src/main/scala/code/api/v1_3_0/APIMethods130.scala @@ -4,6 +4,7 @@ import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON._ import code.api.util.APIUtil._ import code.api.util.ApiTag._ import code.api.util.ErrorMessages._ +import code.api.util.FutureUtil.EndpointContext import code.api.util.NewStyle.HttpCode import code.api.util.{ErrorMessages, NewStyle} import code.bankconnectors.Connector @@ -45,6 +46,7 @@ trait APIMethods130 { lazy val getCards : OBPEndpoint = { case "cards" :: Nil JsonGet _ => { cc => { + implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (cards,callContext) <- NewStyle.function.getPhysicalCardsForUser(u, callContext) diff --git a/obp-api/src/main/scala/code/api/v1_4_0/APIMethods140.scala b/obp-api/src/main/scala/code/api/v1_4_0/APIMethods140.scala index 977dc5bf75..459b3348c1 100644 --- a/obp-api/src/main/scala/code/api/v1_4_0/APIMethods140.scala +++ b/obp-api/src/main/scala/code/api/v1_4_0/APIMethods140.scala @@ -2,6 +2,7 @@ package code.api.v1_4_0 import code.api.util.ApiRole._ import code.api.util.ApiTag._ +import code.api.util.FutureUtil.EndpointContext import code.api.util.NewStyle.HttpCode import code.api.util._ import code.api.v1_4_0.JSONFactory1_4_0._ @@ -148,6 +149,7 @@ trait APIMethods140 extends MdcLoggable with APIMethods130 with APIMethods121{ lazy val addCustomerMessage : OBPEndpoint = { case "banks" :: BankId(bankId) :: "customer" :: customerId :: "messages" :: Nil JsonPost json -> _ => { cc =>{ + implicit val ec = EndpointContext(Some(cc)) for { (Full(user), callContext) <- authenticatedAccess(cc) failMsg = s"$InvalidJsonFormat The Json body should be the $AddCustomerMessageJson " @@ -414,7 +416,7 @@ trait APIMethods140 extends MdcLoggable with APIMethods130 with APIMethods121{ lazy val getTransactionRequestTypes: OBPEndpoint = { case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transaction-request-types" :: Nil JsonGet _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.isEnabledTransactionRequests(callContext) diff --git a/obp-api/src/main/scala/code/api/v2_0_0/APIMethods200.scala b/obp-api/src/main/scala/code/api/v2_0_0/APIMethods200.scala index 36efbac22b..3efb1c4926 100644 --- a/obp-api/src/main/scala/code/api/v2_0_0/APIMethods200.scala +++ b/obp-api/src/main/scala/code/api/v2_0_0/APIMethods200.scala @@ -1,6 +1,7 @@ package code.api.v2_0_0 import java.util.{Calendar, Date} + import code.api.Constant._ import code.TransactionTypes.TransactionType import code.api.{APIFailure, APIFailureNewStyle} @@ -9,6 +10,7 @@ import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON._ import code.api.util.APIUtil._ import code.api.util.ApiTag._ import code.api.util.ErrorMessages.UserNotLoggedIn +import code.api.util.FutureUtil.EndpointContext import code.api.util.NewStyle.HttpCode import code.api.util._ import code.api.v1_2_1.OBPAPI1_2_1._ @@ -232,7 +234,7 @@ trait APIMethods200 { lazy val publicAccountsAllBanks : OBPEndpoint = { //get public accounts for all banks case "accounts" :: "public" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (publicViews, publicAccountAccess) <- Future(Views.views.vend.publicViews) publicAccountsJson <- NewStyle.function.tryons(CannotGetAccounts, 400, Some(cc)){ @@ -273,7 +275,7 @@ trait APIMethods200 { lazy val getPrivateAccountsAtOneBank : OBPEndpoint = { case "banks" :: BankId(bankId) :: "accounts" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for{ (Full(u), callContext) <- authenticatedAccess(cc) (bank, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -320,7 +322,7 @@ trait APIMethods200 { lazy val corePrivateAccountsAtOneBank : OBPEndpoint = { // get private accounts for a single bank case "my" :: "banks" :: BankId(bankId) :: "accounts" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (bank, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -333,7 +335,7 @@ trait APIMethods200 { } // Also we support accounts/private to maintain compatibility with 1.4.0 case "my" :: "banks" :: BankId(bankId) :: "accounts" :: "private" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (bank, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -346,7 +348,7 @@ trait APIMethods200 { } // Supports idea of default bank case "bank" :: "accounts" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (bank, callContext) <- NewStyle.function.getBank(BankId(defaultBankId), callContext) @@ -387,7 +389,7 @@ trait APIMethods200 { lazy val privateAccountsAtOneBank : OBPEndpoint = { //get private accounts for a single bank case "banks" :: BankId(bankId) :: "accounts" :: "private" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (bank, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -424,7 +426,7 @@ trait APIMethods200 { lazy val publicAccountsAtOneBank : OBPEndpoint = { //get public accounts for a single bank case "banks" :: BankId(bankId) :: "accounts" :: "public" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (_, callContext) <- anonymousAccess(cc) (bank, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -459,6 +461,7 @@ trait APIMethods200 { lazy val getKycDocuments : OBPEndpoint = { case "customers" :: customerId :: "kyc_documents" :: Nil JsonGet _ => { cc => { + implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canGetAnyKycDocuments, callContext) @@ -492,6 +495,7 @@ trait APIMethods200 { lazy val getKycMedia : OBPEndpoint = { case "customers" :: customerId :: "kyc_media" :: Nil JsonGet _ => { cc => { + implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canGetAnyKycMedia, callContext) @@ -525,6 +529,7 @@ trait APIMethods200 { lazy val getKycChecks : OBPEndpoint = { case "customers" :: customerId :: "kyc_checks" :: Nil JsonGet _ => { cc => { + implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canGetAnyKycChecks, callContext) @@ -557,6 +562,7 @@ trait APIMethods200 { lazy val getKycStatuses : OBPEndpoint = { case "customers" :: customerId :: "kyc_statuses" :: Nil JsonGet _ => { cc => { + implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canGetAnyKycStatuses, callContext) @@ -627,6 +633,7 @@ trait APIMethods200 { case "banks" :: BankId(bankId) :: "customers" :: customerId :: "kyc_documents" :: documentId :: Nil JsonPut json -> _ => { // customerNumber is duplicated in postedData. remove from that? cc => { + implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.hasEntitlement(bankId.value, u.userId, ApiRole.canAddKycDocument, callContext) @@ -676,6 +683,7 @@ trait APIMethods200 { case "banks" :: BankId(bankId) :: "customers" :: customerId :: "kyc_media" :: mediaId :: Nil JsonPut json -> _ => { // customerNumber is in url and duplicated in postedData. remove from that? cc => { + implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.hasEntitlement(bankId.value, u.userId, ApiRole.canAddKycMedia, callContext) @@ -725,6 +733,7 @@ trait APIMethods200 { case "banks" :: BankId(bankId) :: "customers" :: customerId :: "kyc_check" :: checkId :: Nil JsonPut json -> _ => { // customerNumber is in url and duplicated in postedData. remove from that? cc => { + implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.hasEntitlement(bankId.value, u.userId, ApiRole.canAddKycCheck, callContext) @@ -775,6 +784,7 @@ trait APIMethods200 { case "banks" :: BankId(bankId) :: "customers" :: customerId :: "kyc_statuses" :: Nil JsonPut json -> _ => { // customerNumber is in url and duplicated in postedData. remove from that? cc => { + implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.hasEntitlement(bankId.value, u.userId, ApiRole.canAddKycStatus, callContext) @@ -1006,7 +1016,7 @@ trait APIMethods200 { lazy val getPermissionsForBankAccount : OBPEndpoint = { case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "permissions" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -1199,6 +1209,7 @@ trait APIMethods200 { lazy val getTransactionTypes : OBPEndpoint = { case "banks" :: BankId(bankId) :: "transaction-types" :: Nil JsonGet _ => { cc => { + implicit val ec = EndpointContext(Some(cc)) for { // Get Transaction Types from the active provider (_, callContext) <- getTransactionTypesIsPublic match { @@ -1967,7 +1978,7 @@ trait APIMethods200 { lazy val addEntitlement : OBPEndpoint = { //add access for specific user to a list of views case "users" :: userId :: "entitlements" :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.findByUserId(userId, callContext) @@ -2066,7 +2077,7 @@ trait APIMethods200 { lazy val deleteEntitlement: OBPEndpoint = { case "users" :: userId :: "entitlement" :: entitlementId :: Nil JsonDelete _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.hasEntitlement("", u.userId, canDeleteEntitlementAtAnyBank, cc.callContext) @@ -2104,7 +2115,7 @@ trait APIMethods200 { lazy val getAllEntitlements: OBPEndpoint = { case "entitlements" :: Nil JsonGet _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.hasEntitlement("", u.userId, canGetEntitlementsForAnyUserAtAnyBank,callContext) diff --git a/obp-api/src/main/scala/code/api/v2_1_0/APIMethods210.scala b/obp-api/src/main/scala/code/api/v2_1_0/APIMethods210.scala index a85bf277a5..291922c031 100644 --- a/obp-api/src/main/scala/code/api/v2_1_0/APIMethods210.scala +++ b/obp-api/src/main/scala/code/api/v2_1_0/APIMethods210.scala @@ -1,10 +1,12 @@ package code.api.v2_1_0 import java.util.Date + import code.TransactionTypes.TransactionType import code.api.util import code.api.util.ApiTag._ import code.api.util.ErrorMessages.TransactionDisabled +import code.api.util.FutureUtil.EndpointContext import code.api.util.NewStyle.HttpCode import code.api.util.{APIUtil, ApiRole, ErrorMessages, NewStyle} import code.api.v1_3_0.{JSONFactory1_3_0, _} @@ -146,7 +148,7 @@ trait APIMethods210 { lazy val getTransactionRequestTypesSupportedByBank: OBPEndpoint = { // Get transaction request types supported by the bank case "banks" :: BankId(bankId) :: "transaction-request-types" :: Nil JsonGet _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (_, callContext) <- getTransactionRequestTypesIsPublic match { case false => authenticatedAccess(cc) @@ -396,7 +398,7 @@ trait APIMethods210 { lazy val createTransactionRequest: OBPEndpoint = { case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transaction-request-types" :: TransactionRequestType(transactionRequestType) :: "transaction-requests" :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.isEnabledTransactionRequests(callContext) @@ -601,7 +603,7 @@ trait APIMethods210 { lazy val answerTransactionRequestChallenge: OBPEndpoint = { case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transaction-request-types" :: TransactionRequestType(transactionRequestType) :: "transaction-requests" :: TransactionRequestId(transReqId) :: "challenge" :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { // Check we have a User (Full(u), callContext) <- authenticatedAccess(cc) @@ -748,7 +750,7 @@ trait APIMethods210 { lazy val getRoles: OBPEndpoint = { case "roles" :: Nil JsonGet _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { _ <- authenticatedAccess(cc) } @@ -788,7 +790,7 @@ trait APIMethods210 { lazy val getEntitlementsByBankAndUser: OBPEndpoint = { case "banks" :: BankId(bankId) :: "users" :: userId :: "entitlements" :: Nil JsonGet _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(loggedInUser), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -961,7 +963,7 @@ trait APIMethods210 { lazy val addCardForBank: OBPEndpoint = { case "banks" :: BankId(bankId) :: "cards" :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.hasEntitlement(bankId.value, u.userId, ApiRole.canCreateCardsForBank, callContext) @@ -1045,7 +1047,7 @@ trait APIMethods210 { lazy val getUsers: OBPEndpoint = { case "users" :: Nil JsonGet _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canGetAnyUser, callContext) @@ -1095,6 +1097,7 @@ trait APIMethods210 { lazy val createTransactionType: OBPEndpoint = { case "banks" :: BankId(bankId) :: "transaction-types" :: Nil JsonPut json -> _ => { cc => { + implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -1453,6 +1456,7 @@ trait APIMethods210 { lazy val getCustomersForCurrentUserAtBank : OBPEndpoint = { case "banks" :: BankId(bankId) :: "customers" :: Nil JsonGet _ => { cc => { + implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -1675,6 +1679,7 @@ trait APIMethods210 { lazy val getMetrics : OBPEndpoint = { case "management" :: "metrics" :: Nil JsonGet _ => { cc => { + implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canReadMetrics, callContext) diff --git a/obp-api/src/main/scala/code/api/v3_0_0/APIMethods300.scala b/obp-api/src/main/scala/code/api/v3_0_0/APIMethods300.scala index 1b6923e809..418d9cc5ad 100644 --- a/obp-api/src/main/scala/code/api/v3_0_0/APIMethods300.scala +++ b/obp-api/src/main/scala/code/api/v3_0_0/APIMethods300.scala @@ -1,6 +1,7 @@ package code.api.v3_0_0 import java.util.regex.Pattern + import code.accountattribute.AccountAttributeX import code.accountholders.AccountHolders import code.api.{APIFailureNewStyle, Constant} @@ -11,6 +12,7 @@ import code.api.util.APIUtil.{getGlossaryItems, _} import code.api.util.ApiRole._ import code.api.util.ApiTag._ import code.api.util.ErrorMessages._ +import code.api.util.FutureUtil.EndpointContext import code.api.util.NewStyle.HttpCode import code.api.util._ import code.api.v1_2_1.JSONFactory @@ -107,7 +109,7 @@ trait APIMethods300 { lazy val getViewsForBankAccount : OBPEndpoint = { //get the available views on an bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "views" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) val res = for { (Full(u), callContext) <- authenticatedAccess(cc) @@ -168,7 +170,7 @@ trait APIMethods300 { lazy val createViewForBankAccount : OBPEndpoint = { //creates a view on an bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "views" :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) createViewJson <- Future { tryo{json.extract[CreateViewJson]} } map { @@ -216,7 +218,7 @@ trait APIMethods300 { lazy val getPermissionForUserForBankAccount : OBPEndpoint = { //get access for specific user case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "permissions" :: provider :: providerId :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(loggedInUser), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -266,7 +268,7 @@ trait APIMethods300 { lazy val updateViewForBankAccount : OBPEndpoint = { //updates a view on a bank account case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "views" :: ViewId(viewId) :: Nil JsonPut json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) updateJson <- Future { tryo{json.extract[UpdateViewJsonV300]} } map { @@ -332,7 +334,7 @@ trait APIMethods300 { apiTagAccount :: Nil) lazy val getPrivateAccountById : OBPEndpoint = { case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "account" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (account, callContext) <- NewStyle.function.checkBankAccountExists(bankId, accountId, callContext) @@ -376,7 +378,7 @@ trait APIMethods300 { lazy val getPublicAccountById : OBPEndpoint = { case "banks" :: BankId(bankId) :: "public" :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "account" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (account, callContext) <- NewStyle.function.getBankAccount(bankId, accountId, Some(cc)) view <- NewStyle.function.checkViewAccessAndReturnView(viewId, BankIdAccountId(account.bankId, account.accountId),cc.user, callContext) @@ -418,7 +420,7 @@ trait APIMethods300 { lazy val getCoreAccountById : OBPEndpoint = { //get account by id (assume owner view requested) case "my" :: "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "account" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (account, callContext) <- NewStyle.function.checkBankAccountExists(bankId, accountId, callContext) @@ -461,7 +463,7 @@ trait APIMethods300 { lazy val corePrivateAccountsAllBanks : OBPEndpoint = { //get private accounts for all banks case "my" :: "accounts" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) availablePrivateAccounts <- Views.views.vend.getPrivateBankAccountsFuture(u) @@ -513,7 +515,7 @@ trait APIMethods300 { lazy val getFirehoseAccountsAtOneBank : OBPEndpoint = { //get private accounts for all banks case "banks" :: BankId(bankId):: "firehose" :: "accounts" :: "views" :: ViewId(viewId):: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- Helper.booleanToFuture(failMsg = AccountFirehoseNotAllowedOnThisInstance , cc=cc.callContext) { @@ -602,7 +604,7 @@ trait APIMethods300 { lazy val getFirehoseTransactionsForBankAccount : OBPEndpoint = { //get private accounts for all banks case "banks" :: BankId(bankId):: "firehose" :: "accounts" :: AccountId(accountId) :: "views" :: ViewId(viewId) :: "transactions" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) val allowedEntitlements = canUseAccountFirehoseAtAnyBank :: ApiRole.canUseAccountFirehose :: Nil val allowedEntitlementsTxt = allowedEntitlements.mkString(" or ") for { @@ -674,7 +676,7 @@ trait APIMethods300 { lazy val getCoreTransactionsForBankAccount : OBPEndpoint = { case "my" :: "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "transactions" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(user), callContext) <- authenticatedAccess(cc) (bank, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -732,7 +734,7 @@ trait APIMethods300 { lazy val getTransactionsForBankAccount: OBPEndpoint = { case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transactions" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (user, callContext) <- authenticatedAccess(cc) (bank, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -801,7 +803,7 @@ trait APIMethods300 { val esw = new elasticsearchWarehouse lazy val dataWarehouseSearch: OBPEndpoint = { case "search" :: "warehouse" :: index :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canSearchWarehouse, callContext) @@ -880,7 +882,7 @@ trait APIMethods300 { ) lazy val dataWarehouseStatistics: OBPEndpoint = { case "search" :: "warehouse" :: "statistics" :: index :: field :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) //if (field == "/") throw new RuntimeException("No aggregation field supplied") with NoStackTrace for { (Full(u), callContext) <- authenticatedAccess(cc) @@ -936,7 +938,7 @@ trait APIMethods300 { lazy val getUser: OBPEndpoint = { case "users" :: "email" :: email :: "terminator" :: Nil JsonGet _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canGetAnyUser, callContext) @@ -969,7 +971,7 @@ trait APIMethods300 { lazy val getUserByUserId: OBPEndpoint = { case "users" :: "user_id" :: userId :: Nil JsonGet _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canGetAnyUser, callContext) @@ -1006,7 +1008,7 @@ trait APIMethods300 { lazy val getUserByUsername: OBPEndpoint = { case "users" :: "username" :: username :: Nil JsonGet _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canGetAnyUser, callContext) @@ -1043,7 +1045,7 @@ trait APIMethods300 { lazy val getAdapterInfoForBank: OBPEndpoint = { case "banks" :: BankId(bankId) :: "adapter" :: Nil JsonGet _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -1240,6 +1242,7 @@ trait APIMethods300 { lazy val getBranch: OBPEndpoint = { case "banks" :: BankId(bankId) :: "branches" :: BranchId(branchId) :: Nil JsonGet _ => { cc => { + implicit val ec = EndpointContext(Some(cc)) for { (_, callContext) <- getBranchesIsPublic match { case false => authenticatedAccess(cc) @@ -1326,6 +1329,7 @@ trait APIMethods300 { lazy val getBranches : OBPEndpoint = { case "banks" :: BankId(bankId) :: "branches" :: Nil JsonGet _ => { cc => { + implicit val ec = EndpointContext(Some(cc)) val limit = S.param("limit") val offset = S.param("offset") val city = S.param("city") @@ -1412,7 +1416,7 @@ trait APIMethods300 { ) lazy val getAtm: OBPEndpoint = { case "banks" :: BankId(bankId) :: "atms" :: AtmId(atmId) :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (_, callContext) <- getAtmsIsPublic match { case false => authenticatedAccess(cc) @@ -1458,6 +1462,7 @@ trait APIMethods300 { lazy val getAtms : OBPEndpoint = { case "banks" :: BankId(bankId) :: "atms" :: Nil JsonGet req => { cc => { + implicit val ec = EndpointContext(Some(cc)) val limit = S.param("limit") val offset = S.param("offset") for { @@ -1536,7 +1541,7 @@ trait APIMethods300 { lazy val getUsers: OBPEndpoint = { case "users" :: Nil JsonGet _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canGetAnyUser,callContext) @@ -1586,6 +1591,7 @@ trait APIMethods300 { // We have the Call Context (cc) object (provided through the OBPEndpoint type) // The Call Context contains the authorisation headers etc. cc => { + implicit val ec = EndpointContext(Some(cc)) for { // Extract the user from the headers and get an updated callContext (Full(u), callContext) <- authenticatedAccess(cc) @@ -1622,6 +1628,7 @@ trait APIMethods300 { lazy val getCurrentUser: OBPEndpoint = { case "users" :: "current" :: Nil JsonGet _ => { cc => { + implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) entitlements <- NewStyle.function.getEntitlementsByUserId(u.userId, callContext) @@ -1657,7 +1664,7 @@ trait APIMethods300 { lazy val privateAccountsAtOneBank : OBPEndpoint = { //get private accounts for a single bank case "banks" :: BankId(bankId) :: "accounts" :: "private" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -1696,7 +1703,7 @@ trait APIMethods300 { lazy val getPrivateAccountIdsbyBankId : OBPEndpoint = { //get private accounts for a single bank case "banks" :: BankId(bankId) :: "accounts" :: "account_ids" :: "private"::Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext)<- NewStyle.function.getBank(bankId, callContext) @@ -1735,7 +1742,7 @@ trait APIMethods300 { lazy val getOtherAccountsForBankAccount : OBPEndpoint = { case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (u, callContext) <- authenticatedAccess(cc) (account, callContext) <- NewStyle.function.checkBankAccountExists(bankId, accountId, callContext) @@ -1771,7 +1778,7 @@ trait APIMethods300 { lazy val getOtherAccountByIdForBankAccount : OBPEndpoint = { case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "other_accounts":: other_account_id :: Nil JsonGet _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (u, callContext) <- authenticatedAccess(cc) (account, callContext) <- NewStyle.function.checkBankAccountExists(bankId, accountId, callContext) @@ -1824,7 +1831,7 @@ trait APIMethods300 { lazy val addEntitlementRequest : OBPEndpoint = { case "entitlement-requests" :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) postedData <- Future { tryo{json.extract[CreateEntitlementRequestJSON]} } map { @@ -1876,7 +1883,7 @@ trait APIMethods300 { lazy val getAllEntitlementRequests : OBPEndpoint = { case "entitlement-requests" :: Nil JsonGet _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) val allowedEntitlements = canGetEntitlementRequestsAtAnyBank :: Nil val allowedEntitlementsTxt = allowedEntitlements.mkString(" or ") for { @@ -1915,7 +1922,7 @@ trait APIMethods300 { lazy val getEntitlementRequests : OBPEndpoint = { case "users" :: userId :: "entitlement-requests" :: Nil JsonGet _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) val allowedEntitlements = canGetEntitlementRequestsAtAnyBank :: Nil val allowedEntitlementsTxt = allowedEntitlements.mkString(" or ") for { @@ -1954,7 +1961,7 @@ trait APIMethods300 { lazy val getEntitlementRequestsForCurrentUser : OBPEndpoint = { case "my" :: "entitlement-requests" :: Nil JsonGet _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) entitlementRequests <- NewStyle.function.getEntitlementRequestsFuture(u.userId, callContext) @@ -1989,7 +1996,7 @@ trait APIMethods300 { lazy val deleteEntitlementRequest : OBPEndpoint = { case "entitlement-requests" :: entitlementRequestId :: Nil JsonDelete _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) val allowedEntitlements = canDeleteEntitlementRequestsAtAnyBank :: Nil val allowedEntitlementsTxt = UserHasMissingRoles + allowedEntitlements.mkString(" or ") for { @@ -2029,7 +2036,7 @@ trait APIMethods300 { lazy val getEntitlementsForCurrentUser : OBPEndpoint = { case "my" :: "entitlements" :: Nil JsonGet _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) entitlements <- NewStyle.function.getEntitlementsByUserId(u.userId, callContext) @@ -2059,7 +2066,7 @@ trait APIMethods300 { lazy val getApiGlossary : OBPEndpoint = { case "api" :: "glossary" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for{ _ <- if (glossaryDocsRequireRole){ for { @@ -2102,7 +2109,7 @@ trait APIMethods300 { lazy val getAccountsHeld : OBPEndpoint = { case "banks" :: BankId(bankId) :: "accounts-held" :: Nil JsonGet req => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) (_, callContext) <- NewStyle.function.getBank(bankId, callContext) @@ -2183,6 +2190,7 @@ trait APIMethods300 { lazy val getAggregateMetrics : OBPEndpoint = { case "management" :: "aggregate-metrics" :: Nil JsonGet _ => { cc => { + implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canReadAggregateMetrics, callContext) @@ -2233,7 +2241,7 @@ trait APIMethods300 { lazy val addScope : OBPEndpoint = { //add access for specific user to a list of views case "consumers" :: consumerId :: "scopes" :: Nil JsonPost json -> _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) @@ -2302,7 +2310,7 @@ trait APIMethods300 { lazy val deleteScope: OBPEndpoint = { case "consumers" :: consumerId :: "scope" :: scopeId :: Nil JsonDelete _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) consumer <- Future{callContext.get.consumer} map { @@ -2340,7 +2348,7 @@ trait APIMethods300 { lazy val getScopes: OBPEndpoint = { case "consumers" :: consumerId :: "scopes" :: Nil JsonGet _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) consumer <- Future{callContext.get.consumer} map { @@ -2375,7 +2383,7 @@ trait APIMethods300 { //The Json Body is totally the same as V121, just use new style endpoint. lazy val getBanks : OBPEndpoint = { case "banks" :: Nil JsonGet _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (_, callContext) <- anonymousAccess(cc) (banks, callContext) <- if(canOpenFuture("NewStyle.function.getBanks")) { @@ -2412,7 +2420,7 @@ trait APIMethods300 { lazy val bankById : OBPEndpoint = { //get bank by id case "banks" :: BankId(bankId) :: Nil JsonGet _ => { - cc => + cc => implicit val ec = EndpointContext(Some(cc)) for { (bank, callContext) <- NewStyle.function.getBank(bankId, Option(cc)) } yield