Skip to content

Commit

Permalink
refactor/removed the unused methods
Browse files Browse the repository at this point in the history
  • Loading branch information
hongwei1 committed Jul 13, 2023
1 parent 392fe30 commit eeb91e6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 44 deletions.
16 changes: 0 additions & 16 deletions obp-api/src/main/scala/code/api/util/NewStyle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 9 additions & 3 deletions obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
}
Expand Down
25 changes: 0 additions & 25 deletions obp-api/src/main/scala/code/util/Helper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit eeb91e6

Please sign in to comment.