From eeb91e690a81c8e1c61225221c477eb96f698958 Mon Sep 17 00:00:00 2001 From: hongwei Date: Thu, 13 Jul 2023 19:40:52 +0800 Subject: [PATCH] refactor/removed the unused methods --- .../main/scala/code/api/util/NewStyle.scala | 16 ------------ .../scala/code/api/v4_0_0/APIMethods400.scala | 12 ++++++--- obp-api/src/main/scala/code/util/Helper.scala | 25 ------------------- 3 files changed, 9 insertions(+), 44 deletions(-) diff --git a/obp-api/src/main/scala/code/api/util/NewStyle.scala b/obp-api/src/main/scala/code/api/util/NewStyle.scala index 327c909d99..6d76959291 100644 --- a/obp-api/src/main/scala/code/api/util/NewStyle.scala +++ b/obp-api/src/main/scala/code/api/util/NewStyle.scala @@ -716,22 +716,6 @@ object NewStyle extends MdcLoggable{ } } } - - def canGrantAccessToView(bankId: BankId, accountId: AccountId, viewIdToBeGranted : ViewId, user: User, callContext: Option[CallContext]) : Future[Box[Boolean]] = { - Helper.wrapStatementToFuture(UserLacksPermissionCanGrantAccessToViewForTargetAccount) { - APIUtil.canGrantAccessToView(bankId, accountId, viewIdToBeGranted, user, callContext) - } - } - def canRevokeAccessToView(bankId: BankId, accountId: AccountId, viewIdToBeRevoked : ViewId, user: User, callContext: Option[CallContext]) : Future[Box[Boolean]] = { - Helper.wrapStatementToFuture(UserLacksPermissionCanRevokeAccessToViewForTargetAccount) { - APIUtil.canRevokeAccessToView(bankId, accountId,viewIdToBeRevoked, user, callContext) - } - } - def canRevokeAccessToAllView(bankId: BankId, accountId: AccountId, user: User, callContext: Option[CallContext]) : Future[Box[Boolean]] = { - Helper.wrapStatementToFuture(UserLacksPermissionCanRevokeAccessToViewForTargetAccount) { - APIUtil.canRevokeAccessToAllViews(bankId, accountId, user, callContext) - } - } def createSystemView(view: CreateViewJson, callContext: Option[CallContext]) : Future[View] = { Views.views.vend.createSystemView(view) map { unboxFullOrFail(_, callContext, s"$CreateSystemViewError") diff --git a/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala b/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala index e52ada7e60..13b55d7f7b 100644 --- a/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala +++ b/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala @@ -4393,7 +4393,9 @@ trait APIMethods400 { postJson <- NewStyle.function.tryons(failMsg, 400, cc.callContext) { json.extract[PostAccountAccessJsonV400] } - _ <- NewStyle.function.canGrantAccessToView(bankId, accountId, ViewId(postJson.view.view_id), u, callContext) + _ <- Helper.booleanToFuture(UserLacksPermissionCanGrantAccessToViewForTargetAccount, cc = cc.callContext) { + APIUtil.canGrantAccessToView(bankId, accountId, ViewId(postJson.view.view_id), u, callContext) + } (user, callContext) <- NewStyle.function.findByUserId(postJson.user_id, callContext) view <- getView(bankId, accountId, postJson.view, callContext) addedView <- grantAccountAccessToUser(bankId, accountId, user, view, callContext) @@ -4504,7 +4506,9 @@ trait APIMethods400 { json.extract[PostAccountAccessJsonV400] } viewId = ViewId(postJson.view.view_id) - _ <- NewStyle.function.canRevokeAccessToView(bankId, accountId, viewId, u, cc.callContext) + _ <- Helper.booleanToFuture(UserLacksPermissionCanGrantAccessToViewForTargetAccount, cc = cc.callContext) { + APIUtil.canRevokeAccessToView(bankId, accountId, viewId, u, callContext) + } (user, callContext) <- NewStyle.function.findByUserId(postJson.user_id, cc.callContext) view <- postJson.view.is_system match { case true => NewStyle.function.systemView(viewId, callContext) @@ -4556,7 +4560,9 @@ trait APIMethods400 { postJson <- NewStyle.function.tryons(failMsg, 400, cc.callContext) { json.extract[PostRevokeGrantAccountAccessJsonV400] } - _ <- NewStyle.function.canRevokeAccessToAllView(bankId, accountId, u, cc.callContext) + _ <- Helper.booleanToFuture(UserLacksPermissionCanGrantAccessToViewForTargetAccount, cc = cc.callContext) { + APIUtil.canRevokeAccessToAllViews(bankId, accountId, u, callContext) + } _ <- Future(Views.views.vend.revokeAccountAccessByUser(bankId, accountId, u, callContext)) map { unboxFullOrFail(_, callContext, s"Cannot revoke") } diff --git a/obp-api/src/main/scala/code/util/Helper.scala b/obp-api/src/main/scala/code/util/Helper.scala index 5a67a57887..4024cee9f2 100644 --- a/obp-api/src/main/scala/code/util/Helper.scala +++ b/obp-api/src/main/scala/code/util/Helper.scala @@ -117,31 +117,6 @@ object Helper{ x => fullBoxOrException(x ~> APIFailureNewStyle(failMsg, failCode, cc.map(_.toLight))) } } - /** - * Helper function which wrap some statement into Future. - * The function is curried i.e. - * use this parameter syntax ---> (failMsg: String)(statement: => Boolean) - * instead of this one ---------> (failMsg: String, statement: => Boolean) - * Below is an example of recommended usage. - * Please note that the second parameter is provided in curly bracket in order to mimics body of a function. - * booleanToFuture(failMsg = UserHasMissingRoles + CanGetAnyUser) { - * hasEntitlement("", u.userId, ApiRole.CanGetAnyUser) - * } - * @param failMsg is used in case that result of call of function booleanToBox returns Empty - * @param statement is call by name parameter. - * @return In case the statement is false the function returns Future[Failure(failMsg)]. - * Otherwise returns Future[Full()]. - */ - def wrapStatementToFuture(failMsg: String, failCode: Int = 400)(statement: => Boolean): Future[Box[Boolean]] = { - Future { - statement match { - case true => Full(statement) - case false => Empty - } - } map { - x => fullBoxOrException(x ~> APIFailureNewStyle(failMsg, failCode)) - } - } val deprecatedJsonGenerationMessage = "json generation handled elsewhere as it changes from api version to api version"