Skip to content

Commit

Permalink
Merge pull request #2405 from hongwei1/feature/V510CustomViews
Browse files Browse the repository at this point in the history
Feature/v510 custom views
  • Loading branch information
simonredfern committed Jun 28, 2024
2 parents d285ce7 + 25b400f commit fc4057e
Show file tree
Hide file tree
Showing 13 changed files with 635 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import com.openbankproject.commons.util.{ApiVersion, FieldNameApiVersions, Refle
import net.liftweb.json
import java.net.URLEncoder

import code.api.v5_1_0.{AtmsJsonV510, _}
import code.api.v5_1_0.{AtmsJsonV510, CustomViewJsonV510, _}
import code.endpointMapping.EndpointMappingCommons
import net.liftweb.json.Extraction

Expand All @@ -52,6 +52,7 @@ import scala.collection.immutable.List
*/
object SwaggerDefinitionsJSON {

implicit def convertStringToBoolean(value:String) = value.toBoolean

lazy val regulatedEntitiesJsonV510: RegulatedEntitiesJsonV510 = RegulatedEntitiesJsonV510(List(regulatedEntityJsonV510))
lazy val regulatedEntityJsonV510: RegulatedEntityJsonV510 = RegulatedEntityJsonV510(
Expand Down Expand Up @@ -314,17 +315,47 @@ object SwaggerDefinitionsJSON {
"can_revoke_access_to_custom_views"
)

val createCustomViewJson = CreateCustomViewJson(
name = viewNameExample.value,
description= viewDescriptionExample.value,
metadata_view= metadataViewExample.value,
is_public = isPublicExample.value,
which_alias_to_use = whichAliasToUseExample.value,
hide_metadata_if_alias_used = hideMetadataIfAliasUsedExample.value.toBoolean,
allowed_permissions= allowedActionsV500,
)

val customViewJsonV510 = CustomViewJsonV510(
id = viewIdExample.value,
name = viewNameExample.value,
description = viewDescriptionExample.value,
metadata_view = metadataViewExample.value,
is_public = isPublicExample.value,
alias = whichAliasToUseExample.value,
hide_metadata_if_alias_used = hideMetadataIfAliasUsedExample.value.toBoolean,
allowed_permissions = allowedActionsV500
)

val createSystemViewJsonV500 = CreateViewJsonV500(
name = "_test",
description = "This view is for family",
metadata_view ="_test",
is_public = false,
which_alias_to_use = "family",
hide_metadata_if_alias_used = false,
name = viewNameExample.value,
description = viewDescriptionExample.value,
metadata_view =viewDescriptionExample.value,
is_public = isPublicExample.value,
which_alias_to_use = whichAliasToUseExample.value,
hide_metadata_if_alias_used = hideMetadataIfAliasUsedExample.value.toBoolean,
allowed_actions = allowedActionsV500,
// Version 5.0.0
can_grant_access_to_views = Some(List("owner")),
can_revoke_access_to_views = Some(List("owner"))
can_grant_access_to_views = Some(List(viewIdExample.value)),
can_revoke_access_to_views = Some(List(viewIdExample.value))
)

val updateCustomViewJson = UpdateCustomViewJson(
description = viewDescriptionExample.value,
metadata_view = metadataViewExample.value,
is_public = isPublicExample.value,
which_alias_to_use = whichAliasToUseExample.value,
hide_metadata_if_alias_used = hideMetadataIfAliasUsedExample.value.toBoolean,
allowed_permissions = allowedActionsV500
)

val updateViewJsonV300 = UpdateViewJsonV300(
Expand Down
15 changes: 14 additions & 1 deletion obp-api/src/main/scala/code/api/util/APIUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ import code.api.v2_1_0.OBPAPI2_1_0.Implementations2_1_0
import code.api.v2_2_0.OBPAPI2_2_0.Implementations2_2_0
import code.etag.MappedETag
import code.users.Users
import code.views.system.AccountAccess
import code.views.system.{AccountAccess, ViewDefinition}
import net.liftweb.mapper.By

import scala.collection.mutable
Expand Down Expand Up @@ -4962,4 +4962,17 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
.map(item => BankIdAccountId(BankId(item.bank_id.get), AccountId(item.account_id.get)))
.distinct // List pairs (bank_id, account_id)
}

//get all the permission Pair from one record, eg:
//List("can_see_transaction_this_bank_account","can_see_transaction_requests"....)
//Note, do not contain can_revoke_access_to_views and can_grant_access_to_views permission yet.
def getViewPermissions(view: ViewDefinition) = view.allFields.map(x => (x.name, x.get))
.filter(pair =>pair._2.isInstanceOf[Boolean])
.filter(pair => pair._1.startsWith("can"))
.filter(pair => pair._2.equals(true))
.map(pair =>
StringHelpers.snakify(pair._1)
.dropRight(1) //Remove the "_" in the end, eg canCreateStandingOrder_ --> canCreateStandingOrder
).toSet

}
11 changes: 7 additions & 4 deletions obp-api/src/main/scala/code/api/util/ErrorMessages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ object ErrorMessages {
s"OBP-20048: If target viewId is system view, the current view.can_revoke_access_to_views does not contains it. Or" +
s"if target viewId is custom view, the current view.can_revoke_access_to_custom_views is false."

val SourceViewHasLessPermission = "OBP-20049: Source view contains less permissions than target view."

val UserNotSuperAdmin = "OBP-20050: Current User is not a Super Admin!"

val ElasticSearchIndexNotFound = "OBP-20051: Elasticsearch index or indices not found."
Expand Down Expand Up @@ -406,8 +408,8 @@ object ErrorMessages {
val ApiCollectionEndpointNotFound = "OBP-30082: ApiCollectionEndpoint not found."
val CreateApiCollectionEndpointError = "OBP-30083: Could not create ApiCollectionEndpoint."
val DeleteApiCollectionEndpointError = "OBP-30084: Could not delete ApiCollectionEndpoint."
val ApiCollectionEndpointAlreadyExisting = "OBP-30085: The ApiCollectionEndpoint is already Existing."
val ApiCollectionAlreadyExisting = "OBP-30086: The ApiCollection is already Existing."
val ApiCollectionEndpointAlreadyExists = "OBP-30085: The ApiCollectionEndpoint is already exists."
val ApiCollectionAlreadyExists = "OBP-30086: The ApiCollection is already exists."

val DoubleEntryTransactionNotFound = "OBP-30087: Double Entry Transaction not found."

Expand Down Expand Up @@ -499,7 +501,7 @@ object ErrorMessages {
val DeleteSystemViewError = "OBP-30251: Could not delete the system view"
val SystemViewNotFound = "OBP-30252: System view not found. Please specify a valid value for VIEW_ID"
val UpdateSystemViewError = "OBP-30253: Could not update the system view"
val ExistingSystemViewError = "OBP-30254: There is already a view with permalink"
val SystemViewAlreadyExistsError = "OBP-30254: The system view is already exists."
val EmptyNameOfSystemViewError = "OBP-30255: You cannot create a View with an empty Name"
val DeleteCustomViewError = "OBP-30256: Could not delete the custom view"
val CannotFindCustomViewError = "OBP-30257: Could not find the custom view"
Expand All @@ -511,6 +513,7 @@ object ErrorMessages {
val GetCounterpartyLimitError = "OBP-30263: Counterparty limit not found. Please specify a valid value for BANK_ID, ACCOUNT_ID, VIEW_ID or COUNTERPARTY_ID."
val CounterpartyLimitAlreadyExists = "OBP-30264: Counterparty limit already exists. Please specify a different value for BANK_ID, ACCOUNT_ID, VIEW_ID or COUNTERPARTY_ID."
val DeleteCounterpartyLimitError = "OBP-30265: Could not delete the counterparty limit."
val CustomViewAlreadyExistsError = "OBP-30266: The custom view is already exists."

val TaxResidenceNotFound = "OBP-30300: Tax Residence not found by TAX_RESIDENCE_ID. "
val CustomerAddressNotFound = "OBP-30310: Customer's Address not found by CUSTOMER_ADDRESS_ID. "
Expand Down Expand Up @@ -731,7 +734,7 @@ object ErrorMessages {
// MethodRouting Exceptions (OBP-7XXXX)
val InvalidBankIdRegex = "OBP-70001: Incorrect regex for bankIdPattern."
val MethodRoutingNotFoundByMethodRoutingId = "OBP-70002: MethodRouting not found. Please specify a valid value for method_routing_id."
val ExistingMethodRoutingError = "OBP-70003: Method Routing is already existing."
val MethodRoutingAlreadyExistsError = "OBP-70003: Method Routing is already exists."

// Cascade Deletion Exceptions (OBP-8XXXX)
val CouldNotDeleteCascade = "OBP-80001: Could not delete cascade."
Expand Down
2 changes: 1 addition & 1 deletion obp-api/src/main/scala/code/api/util/ExampleValue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ object ExampleValue {
lazy val accountOtpExample = ConnectorField(NoExampleProvided,NoDescriptionProvided)
glossaryItems += makeGlossaryItem("account_otp", accountOtpExample)

lazy val hideMetadataIfAliasUsedExample = ConnectorField(NoExampleProvided,NoDescriptionProvided)
lazy val hideMetadataIfAliasUsedExample = ConnectorField("true",NoDescriptionProvided)
glossaryItems += makeGlossaryItem("hide_metadata_if_alias_used", hideMetadataIfAliasUsedExample)

lazy val canSeeBankAccountCurrencyExample = ConnectorField(NoExampleProvided,NoDescriptionProvided)
Expand Down
2 changes: 1 addition & 1 deletion obp-api/src/main/scala/code/api/util/NewStyle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2923,7 +2923,7 @@ object NewStyle extends MdcLoggable{
}

val notExists = if(exists) Empty else Full(true)
(unboxFullOrFail(notExists, callContext, s"$ExistingMethodRoutingError Please modify the following parameters:" +
(unboxFullOrFail(notExists, callContext, s"$MethodRoutingAlreadyExistsError Please modify the following parameters:" +
s"is_bank_id_exact_match(${methodRouting.isBankIdExactMatch}), " +
s"method_name(${methodRouting.methodName}), " +
s"bank_id_pattern(${methodRouting.bankIdPattern.getOrElse("")})"
Expand Down
6 changes: 3 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 @@ -9016,7 +9016,7 @@ trait APIMethods400 extends MdcLoggable {
json.extract[PostApiCollectionJson400]
}
apiCollection <- Future{MappedApiCollectionsProvider.getApiCollectionByUserIdAndCollectionName(cc.userId, postJson.api_collection_name)}
_ <- Helper.booleanToFuture(failMsg = s"$ApiCollectionAlreadyExisting Current api_collection_name(${postJson.api_collection_name}) is already existing for the log in user.", cc=cc.callContext) {
_ <- Helper.booleanToFuture(failMsg = s"$ApiCollectionAlreadyExists Current api_collection_name(${postJson.api_collection_name}) is already existing for the log in user.", cc=cc.callContext) {
apiCollection.isEmpty
}
(apiCollection, callContext) <- NewStyle.function.createApiCollection(
Expand Down Expand Up @@ -9299,7 +9299,7 @@ trait APIMethods400 extends MdcLoggable {
}
(apiCollection, callContext) <- NewStyle.function.getApiCollectionByUserIdAndCollectionName(cc.userId, apiCollectionName, Some(cc))
apiCollectionEndpoint <- Future{MappedApiCollectionEndpointsProvider.getApiCollectionEndpointByApiCollectionIdAndOperationId(apiCollection.apiCollectionId, postJson.operation_id)}
_ <- Helper.booleanToFuture(failMsg = s"$ApiCollectionEndpointAlreadyExisting Current OPERATION_ID(${postJson.operation_id}) is already in API_COLLECTION_NAME($apiCollectionName) ", cc=callContext) {
_ <- Helper.booleanToFuture(failMsg = s"$ApiCollectionEndpointAlreadyExists Current OPERATION_ID(${postJson.operation_id}) is already in API_COLLECTION_NAME($apiCollectionName) ", cc=callContext) {
apiCollectionEndpoint.isEmpty
}
(apiCollectionEndpoint, callContext) <- NewStyle.function.createApiCollectionEndpoint(
Expand Down Expand Up @@ -9348,7 +9348,7 @@ trait APIMethods400 extends MdcLoggable {
}
(apiCollection, callContext) <- NewStyle.function.getApiCollectionById(apiCollectionId, Some(cc))
apiCollectionEndpoint <- Future{MappedApiCollectionEndpointsProvider.getApiCollectionEndpointByApiCollectionIdAndOperationId(apiCollection.apiCollectionId, postJson.operation_id)}
_ <- Helper.booleanToFuture(failMsg = s"$ApiCollectionEndpointAlreadyExisting Current OPERATION_ID(${postJson.operation_id}) is already in API_COLLECTION_ID($apiCollectionId) ", cc=callContext) {
_ <- Helper.booleanToFuture(failMsg = s"$ApiCollectionEndpointAlreadyExists Current OPERATION_ID(${postJson.operation_id}) is already in API_COLLECTION_ID($apiCollectionId) ", cc=callContext) {
apiCollectionEndpoint.isEmpty
}
(apiCollectionEndpoint, callContext) <- NewStyle.function.createApiCollectionEndpoint(
Expand Down
Loading

0 comments on commit fc4057e

Please sign in to comment.