diff --git a/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala b/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala index 5690b0f50..e44df81d3 100644 --- a/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala +++ b/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala @@ -406,7 +406,7 @@ class Boot extends MdcLoggable { } // ensure our relational database's tables are created/fit the schema - val connector = code.api.Constant.Connector.openOrThrowException(s"$MandatoryPropertyIsNotSet. The missing prop is `connector` ") + val connector = code.api.Constant.CONNECTOR.openOrThrowException(s"$MandatoryPropertyIsNotSet. The missing prop is `connector` ") val runningMode = Props.mode match { case Props.RunModes.Production => "Production mode" @@ -788,7 +788,7 @@ class Boot extends MdcLoggable { // export one Connector's methods as endpoints, it is just for develop APIUtil.getPropsValue("connector.name.export.as.endpoints").foreach { connectorName => // validate whether "connector.name.export.as.endpoints" have set a correct value - code.api.Constant.Connector match { + code.api.Constant.CONNECTOR match { case Full("star") => val starConnectorTypes = APIUtil.getPropsValue("starConnector_supported_types","mapped") .trim diff --git a/obp-api/src/main/scala/code/api/constant/constant.scala b/obp-api/src/main/scala/code/api/constant/constant.scala index 8eb0f2be6..8e4cf7952 100644 --- a/obp-api/src/main/scala/code/api/constant/constant.scala +++ b/obp-api/src/main/scala/code/api/constant/constant.scala @@ -23,7 +23,7 @@ object Constant extends MdcLoggable { final val h2DatabaseDefaultUrlValue = "jdbc:h2:mem:OBPTest_H2_v2.1.214;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=10" final val HostName = APIUtil.getPropsValue("hostname").openOrThrowException(ErrorMessages.HostnameNotSpecified) - final val Connector = APIUtil.getPropsValue("connector") + final val CONNECTOR = APIUtil.getPropsValue("connector") final val openidConnectEnabled = APIUtil.getPropsAsBoolValue("openid_connect.enabled", false) final val bgRemoveSignOfAmounts = APIUtil.getPropsAsBoolValue("BG_remove_sign_of_amounts", false) diff --git a/obp-api/src/main/scala/code/api/util/APIUtil.scala b/obp-api/src/main/scala/code/api/util/APIUtil.scala index a80c555dc..3f255eeee 100644 --- a/obp-api/src/main/scala/code/api/util/APIUtil.scala +++ b/obp-api/src/main/scala/code/api/util/APIUtil.scala @@ -3470,7 +3470,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ )= createOBPId(s"$thisBankId$thisAccountId$counterpartyName$otherAccountRoutingScheme$otherAccountRoutingAddress") def isDataFromOBPSide (methodName: String, argNameToValue: Array[(String, AnyRef)] = Array.empty): Boolean = { - val connectorNameInProps = code.api.Constant.Connector.openOrThrowException(attemptedToOpenAnEmptyBox) + val connectorNameInProps = code.api.Constant.CONNECTOR.openOrThrowException(attemptedToOpenAnEmptyBox) //if the connector == mapped, then the data is always over obp database if(connectorNameInProps == "mapped") { true @@ -3713,9 +3713,9 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ lazy val view = APIUtil.checkViewAccessAndReturnView(viewId, bankAccountId, Some(user), callContext) - lazy val canAddTransactionRequestToAnyAccount = view.map(_.canAddTransactionRequestToAnyAccount).getOrElse(false) + lazy val canAddTransactionRequestToAnyAccount = view.map(_.allowed_actions.exists(_ == CAN_ADD_TRANSACTION_REQUEST_TO_ANY_ACCOUNT)).getOrElse(false) - lazy val canAddTransactionRequestToBeneficiary = view.map(_.canAddTransactionRequestToBeneficiary).getOrElse(false) + lazy val canAddTransactionRequestToBeneficiary = view.map(_.allowed_actions.exists( _ == CAN_ADD_TRANSACTION_REQUEST_TO_BENEFICIARY )).getOrElse(false) //1st check the admin level role/entitlement `canCreateAnyTransactionRequest` if (hasCanCreateAnyTransactionRequestRole) { Full(true) @@ -4183,8 +4183,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ allCanGrantAccessToViewsPermissions.contains(targetViewId.value) } else{ //2. if targetViewId is customView, we only need to check the `canGrantAccessToCustomViews`. - val allCanGrantAccessToCustomViewsPermissions: List[Boolean] = permission.map(_.views.map(_.canGrantAccessToCustomViews)).getOrElse(Nil) - + val allCanGrantAccessToCustomViewsPermissions: List[Boolean] = permission.map(_.views.map(_.allowed_actions.exists(_ == CAN_GRANT_ACCESS_TO_CUSTOM_VIEWS))).getOrElse(Nil) allCanGrantAccessToCustomViewsPermissions.contains(true) } } @@ -4194,13 +4193,13 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ //1st: get the view val view: Box[View] = Views.views.vend.getViewByBankIdAccountIdViewIdUserPrimaryKey(bankIdAccountIdViewId, user.userPrimaryKey) - //2rd: If targetViewId is systemView. we need to check `view.canGrantAccessToViews` field. + //2nd: If targetViewId is systemView. we need to check `view.canGrantAccessToViews` field. if(isValidSystemViewId(targetViewId.value)){ val canGrantAccessToSystemViews: Box[List[String]] = view.map(_.canGrantAccessToViews.getOrElse(Nil)) canGrantAccessToSystemViews.getOrElse(Nil).contains(targetViewId.value) } else{ //3rd. if targetViewId is customView, we need to check `view.canGrantAccessToCustomViews` field. - view.map(_.canGrantAccessToCustomViews).getOrElse(false) + view.map(_.allowed_actions.exists(_ == CAN_GRANT_ACCESS_TO_CUSTOM_VIEWS)).getOrElse(false) } } @@ -4219,7 +4218,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ //if the targetViewIds contains custom view ids, we need to check the both canGrantAccessToCustomViews and canGrantAccessToSystemViews if (targetViewIds.map(_.value).distinct.find(isValidCustomViewId).isDefined){ //check if we can grant all customViews Access. - val allCanGrantAccessToCustomViewsPermissions: List[Boolean] = permissionBox.map(_.views.map(_.canGrantAccessToCustomViews)).getOrElse(Nil) + val allCanGrantAccessToCustomViewsPermissions: List[Boolean] = permissionBox.map(_.views.map(_.allowed_actions.exists(_ ==CAN_GRANT_ACCESS_TO_CUSTOM_VIEWS))).getOrElse(Nil) val canGrantAccessToAllCustomViews = allCanGrantAccessToCustomViewsPermissions.contains(true) //we need merge both system and custom access canGrantAllSystemViewsIdsTobeGranted && canGrantAccessToAllCustomViews @@ -4238,7 +4237,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ canRevokeAccessToSystemViews.getOrElse(Nil).contains(targetViewId.value) } else { //3rd. if targetViewId is customView, we need to check `view.canGrantAccessToCustomViews` field. - view.map(_.canRevokeAccessToCustomViews).getOrElse(false) + view.map(_.allowed_actions.exists(_ == CAN_REVOKE_ACCESS_TO_CUSTOM_VIEWS)).getOrElse(false) } } @@ -4255,7 +4254,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ allCanRevokeAccessToSystemViews.contains(targetViewId.value) } else { //2. if targetViewId is customView, we only need to check the `canRevokeAccessToCustomViews`. - val allCanRevokeAccessToCustomViewsPermissions: List[Boolean] = permission.map(_.views.map(_.canRevokeAccessToCustomViews)).getOrElse(Nil) + val allCanRevokeAccessToCustomViewsPermissions: List[Boolean] = permission.map(_.views.map(_.allowed_actions.exists( _ ==CAN_REVOKE_ACCESS_TO_CUSTOM_VIEWS))).getOrElse(Nil) allCanRevokeAccessToCustomViewsPermissions.contains(true) } @@ -4279,7 +4278,8 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ //if allTargetViewIds contains customViewId,we need to check both `canRevokeAccessToCustomViews` and `canRevokeAccessToSystemViews` fields if (allTargetViewIds.find(isValidCustomViewId).isDefined) { //check if we can revoke all customViews Access - val allCanRevokeAccessToCustomViewsPermissions: List[Boolean] = permissionBox.map(_.views.map(_.canRevokeAccessToCustomViews)).getOrElse(Nil) + val allCanRevokeAccessToCustomViewsPermissions: List[Boolean] = permissionBox.map(_.views.map(_.allowed_actions.exists( _ ==CAN_REVOKE_ACCESS_TO_CUSTOM_VIEWS))).getOrElse(Nil) + val canRevokeAccessToAllCustomViews = allCanRevokeAccessToCustomViewsPermissions.contains(true) //we need merge both system and custom access canRevokeAccessToAllSystemTargetViews && canRevokeAccessToAllCustomViews diff --git a/obp-api/src/main/scala/code/api/util/migration/Migration.scala b/obp-api/src/main/scala/code/api/util/migration/Migration.scala index 78c117351..ddc8966c4 100644 --- a/obp-api/src/main/scala/code/api/util/migration/Migration.scala +++ b/obp-api/src/main/scala/code/api/util/migration/Migration.scala @@ -60,7 +60,7 @@ object Migration extends MdcLoggable { def executeScripts(startedBeforeSchemifier: Boolean): Boolean = executeScript { dummyScript() addAccountAccessConsumerId() - populateMigrationOfViewDefinitionPermissions(startedBeforeSchemifier) +// populateMigrationOfViewDefinitionPermissions(startedBeforeSchemifier) generateAndPopulateMissingCustomerUUIDs(startedBeforeSchemifier) generateAndPopulateMissingConsumersUUIDs(startedBeforeSchemifier) populateTableRateLimiting() @@ -96,8 +96,8 @@ object Migration extends MdcLoggable { alterMappedCustomerAttribute(startedBeforeSchemifier) dropMappedBadLoginAttemptIndex() alterMetricColumnUrlLength() - populateViewDefinitionCanAddTransactionRequestToBeneficiary() - populateViewDefinitionCanSeeTransactionStatus() +// populateViewDefinitionCanAddTransactionRequestToBeneficiary() +// populateViewDefinitionCanSeeTransactionStatus() alterCounterpartyLimitFieldType() populateMigrationOfViewPermissions(startedBeforeSchemifier) } @@ -115,32 +115,32 @@ object Migration extends MdcLoggable { } } - private def populateViewDefinitionCanAddTransactionRequestToBeneficiary(): Boolean = { - val name = nameOf(populateViewDefinitionCanAddTransactionRequestToBeneficiary) - runOnce(name) { - MigrationOfViewDefinitionCanAddTransactionRequestToBeneficiary.populateTheField(name) - } - } +// private def populateViewDefinitionCanAddTransactionRequestToBeneficiary(): Boolean = { +// val name = nameOf(populateViewDefinitionCanAddTransactionRequestToBeneficiary) +// runOnce(name) { +// MigrationOfViewDefinitionCanAddTransactionRequestToBeneficiary.populateTheField(name) +// } +// } - private def populateViewDefinitionCanSeeTransactionStatus(): Boolean = { - val name = nameOf(populateViewDefinitionCanSeeTransactionStatus) - runOnce(name) { - MigrationOfViewDefinitionCanSeeTransactionStatus.populateTheField(name) - } - } +// private def populateViewDefinitionCanSeeTransactionStatus(): Boolean = { +// val name = nameOf(populateViewDefinitionCanSeeTransactionStatus) +// runOnce(name) { +// MigrationOfViewDefinitionCanSeeTransactionStatus.populateTheField(name) +// } +// } - private def populateMigrationOfViewDefinitionPermissions(startedBeforeSchemifier: Boolean): Boolean = { - if (startedBeforeSchemifier == true) { - logger.warn(s"Migration.database.populateMigrationOfViewDefinitionPermissions(true) cannot be run before Schemifier.") - true - } else { - val name = nameOf(populateMigrationOfViewDefinitionPermissions(startedBeforeSchemifier)) - runOnce(name) { - MigrationOfViewDefinitionPermissions.populate(name) - } - } - } +// private def populateMigrationOfViewDefinitionPermissions(startedBeforeSchemifier: Boolean): Boolean = { +// if (startedBeforeSchemifier == true) { +// logger.warn(s"Migration.database.populateMigrationOfViewDefinitionPermissions(true) cannot be run before Schemifier.") +// true +// } else { +// val name = nameOf(populateMigrationOfViewDefinitionPermissions(startedBeforeSchemifier)) +// runOnce(name) { +// MigrationOfViewDefinitionPermissions.populate(name) +// } +// } +// } private def populateMigrationOfViewPermissions(startedBeforeSchemifier: Boolean): Boolean = { if (startedBeforeSchemifier == true) { diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionCanAddTransactionRequestToBeneficiary.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionCanAddTransactionRequestToBeneficiary.scala index 32fec4883..8d4a11aa5 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionCanAddTransactionRequestToBeneficiary.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionCanAddTransactionRequestToBeneficiary.scala @@ -1,47 +1,47 @@ -package code.api.util.migration - -import code.api.Constant.SYSTEM_OWNER_VIEW_ID - -import java.time.format.DateTimeFormatter -import java.time.{ZoneId, ZonedDateTime} -import code.api.util.APIUtil -import code.api.util.migration.Migration.{DbFunction, saveLog} -import code.model.Consumer -import code.views.system.ViewDefinition - -object MigrationOfViewDefinitionCanAddTransactionRequestToBeneficiary { - - val oneDayAgo = ZonedDateTime.now(ZoneId.of("UTC")).minusDays(1) - val oneYearInFuture = ZonedDateTime.now(ZoneId.of("UTC")).plusYears(1) - val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") - - def populateTheField(name: String): Boolean = { - DbFunction.tableExists(ViewDefinition) match { - case true => - val startDate = System.currentTimeMillis() - val commitId: String = APIUtil.gitCommit - var isSuccessful = false - - val view = ViewDefinition.findSystemView(SYSTEM_OWNER_VIEW_ID).map(_.canAddTransactionRequestToBeneficiary_(true).saveMe()) - - - val endDate = System.currentTimeMillis() - val comment: String = - s"""set $SYSTEM_OWNER_VIEW_ID.canAddTransactionRequestToBeneficiary_ to {true}""".stripMargin - val value = view.map(_.canAddTransactionRequestToBeneficiary_.get).getOrElse(false) - isSuccessful = value - saveLog(name, commitId, isSuccessful, startDate, endDate, comment) - isSuccessful - - case false => - val startDate = System.currentTimeMillis() - val commitId: String = APIUtil.gitCommit - val isSuccessful = false - val endDate = System.currentTimeMillis() - val comment: String = - s"""${Consumer._dbTableNameLC} table does not exist""".stripMargin - saveLog(name, commitId, isSuccessful, startDate, endDate, comment) - isSuccessful - } - } -} +//package code.api.util.migration +// +//import code.api.Constant.SYSTEM_OWNER_VIEW_ID +// +//import java.time.format.DateTimeFormatter +//import java.time.{ZoneId, ZonedDateTime} +//import code.api.util.APIUtil +//import code.api.util.migration.Migration.{DbFunction, saveLog} +//import code.model.Consumer +//import code.views.system.ViewDefinition +// +//object MigrationOfViewDefinitionCanAddTransactionRequestToBeneficiary { +// +// val oneDayAgo = ZonedDateTime.now(ZoneId.of("UTC")).minusDays(1) +// val oneYearInFuture = ZonedDateTime.now(ZoneId.of("UTC")).plusYears(1) +// val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") +// +// def populateTheField(name: String): Boolean = { +// DbFunction.tableExists(ViewDefinition) match { +// case true => +// val startDate = System.currentTimeMillis() +// val commitId: String = APIUtil.gitCommit +// var isSuccessful = false +// +// val view = ViewDefinition.findSystemView(SYSTEM_OWNER_VIEW_ID).map(_.canAddTransactionRequestToBeneficiary_(true).saveMe()) +// +// +// val endDate = System.currentTimeMillis() +// val comment: String = +// s"""set $SYSTEM_OWNER_VIEW_ID.canAddTransactionRequestToBeneficiary_ to {true}""".stripMargin +// val value = view.map(_.canAddTransactionRequestToBeneficiary_.get).getOrElse(false) +// isSuccessful = value +// saveLog(name, commitId, isSuccessful, startDate, endDate, comment) +// isSuccessful +// +// case false => +// val startDate = System.currentTimeMillis() +// val commitId: String = APIUtil.gitCommit +// val isSuccessful = false +// val endDate = System.currentTimeMillis() +// val comment: String = +// s"""${Consumer._dbTableNameLC} table does not exist""".stripMargin +// saveLog(name, commitId, isSuccessful, startDate, endDate, comment) +// isSuccessful +// } +// } +//} diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionCanSeeTransactionStatus.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionCanSeeTransactionStatus.scala index 63c3d026a..894701af4 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionCanSeeTransactionStatus.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionCanSeeTransactionStatus.scala @@ -1,80 +1,80 @@ -package code.api.util.migration - -import code.api.Constant._ -import code.api.util.APIUtil -import code.api.util.migration.Migration.{DbFunction, saveLog} -import code.model.Consumer -import code.views.system.ViewDefinition - -import java.time.format.DateTimeFormatter -import java.time.{ZoneId, ZonedDateTime} - -object MigrationOfViewDefinitionCanSeeTransactionStatus { - - val oneDayAgo = ZonedDateTime.now(ZoneId.of("UTC")).minusDays(1) - val oneYearInFuture = ZonedDateTime.now(ZoneId.of("UTC")).plusYears(1) - val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") - - def populateTheField(name: String): Boolean = { - DbFunction.tableExists(ViewDefinition) match { - case true => - val startDate = System.currentTimeMillis() - val commitId: String = APIUtil.gitCommit - var isSuccessful = false - - val view = ViewDefinition.findSystemView(SYSTEM_OWNER_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) - val view1 = ViewDefinition.findSystemView(SYSTEM_READ_TRANSACTIONS_BERLIN_GROUP_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) - val view2 = ViewDefinition.findSystemView(SYSTEM_READ_TRANSACTIONS_DETAIL_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) - val view3 = ViewDefinition.findSystemView(SYSTEM_READ_TRANSACTIONS_DEBITS_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) - val view4 = ViewDefinition.findSystemView(SYSTEM_READ_TRANSACTIONS_BASIC_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) - val view8 = ViewDefinition.findSystemView(SYSTEM_AUDITOR_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) - val view5 = ViewDefinition.findSystemView(SYSTEM_STAGE_ONE_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) - val view6 = ViewDefinition.findSystemView(SYSTEM_STANDARD_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) - val view7 = ViewDefinition.findSystemView(SYSTEM_FIREHOSE_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) - val view9 = ViewDefinition.findSystemView(SYSTEM_ACCOUNTANT_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) - val view10 = ViewDefinition.findSystemView(SYSTEM_MANAGE_CUSTOM_VIEWS_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) - - - val endDate = System.currentTimeMillis() - val comment: String = - s"""set $SYSTEM_OWNER_VIEW_ID.canSeeTransactionStatus_ to {true}; - |set $SYSTEM_READ_TRANSACTIONS_BERLIN_GROUP_VIEW_ID.canSeeTransactionStatus_ to {true} - |set $SYSTEM_READ_TRANSACTIONS_DETAIL_VIEW_ID.canSeeTransactionStatus_ to {true}; - |set $SYSTEM_READ_TRANSACTIONS_DEBITS_VIEW_ID.canSeeTransactionStatus_ to {true}; - |set $SYSTEM_READ_TRANSACTIONS_BASIC_VIEW_ID.canSeeTransactionStatus_ to {true}; - |set $SYSTEM_AUDITOR_VIEW_ID.canSeeTransactionStatus_ to {true}; - |set $SYSTEM_STAGE_ONE_VIEW_ID.canSeeTransactionStatus_ to {true}; - |set $SYSTEM_STANDARD_VIEW_ID.canSeeTransactionStatus_ to {true}; - |set $SYSTEM_FIREHOSE_VIEW_ID.canSeeTransactionStatus_ to {true}; - |set $SYSTEM_ACCOUNTANT_VIEW_ID.canSeeTransactionStatus_ to {true}; - |set $SYSTEM_MANAGE_CUSTOM_VIEWS_VIEW_ID.canSeeTransactionStatus_ to {true}; - |""".stripMargin - val value = view.map(_.canSeeTransactionStatus_.get).getOrElse(false) - val value1 = view1.map(_.canSeeTransactionStatus_.get).getOrElse(false) - val value2 = view1.map(_.canSeeTransactionStatus_.get).getOrElse(false) - val value3 = view3.map(_.canSeeTransactionStatus_.get).getOrElse(false) - val value4 = view4.map(_.canSeeTransactionStatus_.get).getOrElse(false) - val value5 = view5.map(_.canSeeTransactionStatus_.get).getOrElse(false) - val value6 = view6.map(_.canSeeTransactionStatus_.get).getOrElse(false) - val value7 = view7.map(_.canSeeTransactionStatus_.get).getOrElse(false) - val value8 = view8.map(_.canSeeTransactionStatus_.get).getOrElse(false) - val value9 = view9.map(_.canSeeTransactionStatus_.get).getOrElse(false) - val value10 = view10.map(_.canSeeTransactionStatus_.get).getOrElse(false) - - isSuccessful = value && value1 && value2 && value3 && value4 && value5 && value6 && value7 && value8 && value9 && value10 - - saveLog(name, commitId, isSuccessful, startDate, endDate, comment) - isSuccessful - - case false => - val startDate = System.currentTimeMillis() - val commitId: String = APIUtil.gitCommit - val isSuccessful = false - val endDate = System.currentTimeMillis() - val comment: String = - s"""${Consumer._dbTableNameLC} table does not exist""".stripMargin - saveLog(name, commitId, isSuccessful, startDate, endDate, comment) - isSuccessful - } - } -} +//package code.api.util.migration +// +//import code.api.Constant._ +//import code.api.util.APIUtil +//import code.api.util.migration.Migration.{DbFunction, saveLog} +//import code.model.Consumer +//import code.views.system.ViewDefinition +// +//import java.time.format.DateTimeFormatter +//import java.time.{ZoneId, ZonedDateTime} +// +//object MigrationOfViewDefinitionCanSeeTransactionStatus { +// +// val oneDayAgo = ZonedDateTime.now(ZoneId.of("UTC")).minusDays(1) +// val oneYearInFuture = ZonedDateTime.now(ZoneId.of("UTC")).plusYears(1) +// val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") +// +// def populateTheField(name: String): Boolean = { +// DbFunction.tableExists(ViewDefinition) match { +// case true => +// val startDate = System.currentTimeMillis() +// val commitId: String = APIUtil.gitCommit +// var isSuccessful = false +// +// val view = ViewDefinition.findSystemView(SYSTEM_OWNER_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) +// val view1 = ViewDefinition.findSystemView(SYSTEM_READ_TRANSACTIONS_BERLIN_GROUP_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) +// val view2 = ViewDefinition.findSystemView(SYSTEM_READ_TRANSACTIONS_DETAIL_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) +// val view3 = ViewDefinition.findSystemView(SYSTEM_READ_TRANSACTIONS_DEBITS_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) +// val view4 = ViewDefinition.findSystemView(SYSTEM_READ_TRANSACTIONS_BASIC_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) +// val view8 = ViewDefinition.findSystemView(SYSTEM_AUDITOR_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) +// val view5 = ViewDefinition.findSystemView(SYSTEM_STAGE_ONE_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) +// val view6 = ViewDefinition.findSystemView(SYSTEM_STANDARD_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) +// val view7 = ViewDefinition.findSystemView(SYSTEM_FIREHOSE_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) +// val view9 = ViewDefinition.findSystemView(SYSTEM_ACCOUNTANT_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) +// val view10 = ViewDefinition.findSystemView(SYSTEM_MANAGE_CUSTOM_VIEWS_VIEW_ID).map(_.canSeeTransactionStatus_(true).saveMe()) +// +// +// val endDate = System.currentTimeMillis() +// val comment: String = +// s"""set $SYSTEM_OWNER_VIEW_ID.canSeeTransactionStatus_ to {true}; +// |set $SYSTEM_READ_TRANSACTIONS_BERLIN_GROUP_VIEW_ID.canSeeTransactionStatus_ to {true} +// |set $SYSTEM_READ_TRANSACTIONS_DETAIL_VIEW_ID.canSeeTransactionStatus_ to {true}; +// |set $SYSTEM_READ_TRANSACTIONS_DEBITS_VIEW_ID.canSeeTransactionStatus_ to {true}; +// |set $SYSTEM_READ_TRANSACTIONS_BASIC_VIEW_ID.canSeeTransactionStatus_ to {true}; +// |set $SYSTEM_AUDITOR_VIEW_ID.canSeeTransactionStatus_ to {true}; +// |set $SYSTEM_STAGE_ONE_VIEW_ID.canSeeTransactionStatus_ to {true}; +// |set $SYSTEM_STANDARD_VIEW_ID.canSeeTransactionStatus_ to {true}; +// |set $SYSTEM_FIREHOSE_VIEW_ID.canSeeTransactionStatus_ to {true}; +// |set $SYSTEM_ACCOUNTANT_VIEW_ID.canSeeTransactionStatus_ to {true}; +// |set $SYSTEM_MANAGE_CUSTOM_VIEWS_VIEW_ID.canSeeTransactionStatus_ to {true}; +// |""".stripMargin +// val value = view.map(_.canSeeTransactionStatus_.get).getOrElse(false) +// val value1 = view1.map(_.canSeeTransactionStatus_.get).getOrElse(false) +// val value2 = view1.map(_.canSeeTransactionStatus_.get).getOrElse(false) +// val value3 = view3.map(_.canSeeTransactionStatus_.get).getOrElse(false) +// val value4 = view4.map(_.canSeeTransactionStatus_.get).getOrElse(false) +// val value5 = view5.map(_.canSeeTransactionStatus_.get).getOrElse(false) +// val value6 = view6.map(_.canSeeTransactionStatus_.get).getOrElse(false) +// val value7 = view7.map(_.canSeeTransactionStatus_.get).getOrElse(false) +// val value8 = view8.map(_.canSeeTransactionStatus_.get).getOrElse(false) +// val value9 = view9.map(_.canSeeTransactionStatus_.get).getOrElse(false) +// val value10 = view10.map(_.canSeeTransactionStatus_.get).getOrElse(false) +// +// isSuccessful = value && value1 && value2 && value3 && value4 && value5 && value6 && value7 && value8 && value9 && value10 +// +// saveLog(name, commitId, isSuccessful, startDate, endDate, comment) +// isSuccessful +// +// case false => +// val startDate = System.currentTimeMillis() +// val commitId: String = APIUtil.gitCommit +// val isSuccessful = false +// val endDate = System.currentTimeMillis() +// val comment: String = +// s"""${Consumer._dbTableNameLC} table does not exist""".stripMargin +// saveLog(name, commitId, isSuccessful, startDate, endDate, comment) +// isSuccessful +// } +// } +//} diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionPermissions.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionPermissions.scala index 0c2fac0ce..2499248a1 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionPermissions.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionPermissions.scala @@ -1,97 +1,97 @@ -package code.api.util.migration - -import code.api.Constant.{DEFAULT_CAN_GRANT_AND_REVOKE_ACCESS_TO_VIEWS, SYSTEM_OWNER_VIEW_ID, SYSTEM_STANDARD_VIEW_ID} -import code.api.util.APIUtil -import code.api.util.migration.Migration.{DbFunction, saveLog} -import code.views.system.ViewDefinition -import net.liftweb.mapper.{By, DB, NullRef} -import net.liftweb.util.DefaultConnectionIdentifier - -object MigrationOfViewDefinitionPermissions { - def populate(name: String): Boolean = { - DbFunction.tableExists(ViewDefinition) match { - case true => - val startDate = System.currentTimeMillis() - val commitId: String = APIUtil.gitCommit - val ownerView = ViewDefinition.find( - NullRef(ViewDefinition.bank_id), - NullRef(ViewDefinition.account_id), - By(ViewDefinition.view_id, SYSTEM_OWNER_VIEW_ID), - By(ViewDefinition.isSystem_,true) - ).map(view => - view - .canSeeTransactionRequestTypes_(true) - .canSeeTransactionRequests_(true) - .canSeeAvailableViewsForBankAccount_(true) - .canUpdateBankAccountLabel_(true) - .canSeeViewsWithPermissionsForOneUser_(true) - .canSeeViewsWithPermissionsForAllUsers_(true) - .canCreateCustomView_(false) - .canDeleteCustomView_(false) - .canUpdateCustomView_(false) - .canGrantAccessToCustomViews_(false) - .canRevokeAccessToCustomViews_(false) - .canGrantAccessToViews_(DEFAULT_CAN_GRANT_AND_REVOKE_ACCESS_TO_VIEWS.mkString(",")) - .canRevokeAccessToViews_(DEFAULT_CAN_GRANT_AND_REVOKE_ACCESS_TO_VIEWS.mkString(",")) - .save - ) - - val standardView = ViewDefinition.find( - NullRef(ViewDefinition.bank_id), - NullRef(ViewDefinition.account_id), - By(ViewDefinition.view_id, SYSTEM_STANDARD_VIEW_ID), - By(ViewDefinition.isSystem_,true) - ).map(view => - view - .canSeeTransactionRequestTypes_(true) - .canSeeTransactionRequests_(true) - .canSeeAvailableViewsForBankAccount_(true) - .canUpdateBankAccountLabel_(true) - .canSeeViewsWithPermissionsForOneUser_(true) - .canSeeViewsWithPermissionsForAllUsers_(true) - .canCreateCustomView_(false) - .canDeleteCustomView_(false) - .canUpdateCustomView_(false) - .canGrantAccessToCustomViews_(false) - .canRevokeAccessToCustomViews_(false) - .canGrantAccessToViews_(DEFAULT_CAN_GRANT_AND_REVOKE_ACCESS_TO_VIEWS.mkString(",")) - .canRevokeAccessToViews_(DEFAULT_CAN_GRANT_AND_REVOKE_ACCESS_TO_VIEWS.mkString(",")) - .save - ) - - - val isSuccessful = ownerView.isDefined && standardView.isDefined - val endDate = System.currentTimeMillis() - - val comment: String = - s"""ViewDefinition system $SYSTEM_OWNER_VIEW_ID and $SYSTEM_STANDARD_VIEW_ID views, update the following rows to true: - |${ViewDefinition.canSeeTransactionRequestTypes_.dbColumnName} - |${ViewDefinition.canSeeTransactionRequests_.dbColumnName} - |${ViewDefinition.canSeeAvailableViewsForBankAccount_.dbColumnName} - |${ViewDefinition.canUpdateBankAccountLabel_.dbColumnName} - |${ViewDefinition.canCreateCustomView_.dbColumnName} - |${ViewDefinition.canDeleteCustomView_.dbColumnName} - |${ViewDefinition.canUpdateCustomView_.dbColumnName} - |${ViewDefinition.canSeeViewsWithPermissionsForAllUsers_.dbColumnName} - |${ViewDefinition.canSeeViewsWithPermissionsForOneUser_.dbColumnName} - |${ViewDefinition.canGrantAccessToCustomViews_.dbColumnName} - |${ViewDefinition.canRevokeAccessToCustomViews_.dbColumnName} - |${ViewDefinition.canGrantAccessToViews_.dbColumnName} - |${ViewDefinition.canRevokeAccessToViews_.dbColumnName} - |Duration: ${endDate - startDate} ms; - """.stripMargin - saveLog(name, commitId, isSuccessful, startDate, endDate, comment) - isSuccessful - - case false => - val startDate = System.currentTimeMillis() - val commitId: String = APIUtil.gitCommit - val isSuccessful = false - val endDate = System.currentTimeMillis() - val comment: String = - s"""ViewDefinition does not exist!""".stripMargin - saveLog(name, commitId, isSuccessful, startDate, endDate, comment) - isSuccessful - } - } -} +//package code.api.util.migration +// +//import code.api.Constant.{DEFAULT_CAN_GRANT_AND_REVOKE_ACCESS_TO_VIEWS, SYSTEM_OWNER_VIEW_ID, SYSTEM_STANDARD_VIEW_ID} +//import code.api.util.APIUtil +//import code.api.util.migration.Migration.{DbFunction, saveLog} +//import code.views.system.ViewDefinition +//import net.liftweb.mapper.{By, DB, NullRef} +//import net.liftweb.util.DefaultConnectionIdentifier +// +//object MigrationOfViewDefinitionPermissions { +// def populate(name: String): Boolean = { +// DbFunction.tableExists(ViewDefinition) match { +// case true => +// val startDate = System.currentTimeMillis() +// val commitId: String = APIUtil.gitCommit +// val ownerView = ViewDefinition.find( +// NullRef(ViewDefinition.bank_id), +// NullRef(ViewDefinition.account_id), +// By(ViewDefinition.view_id, SYSTEM_OWNER_VIEW_ID), +// By(ViewDefinition.isSystem_,true) +// ).map(view => +// view +// .canSeeTransactionRequestTypes_(true) +// .canSeeTransactionRequests_(true) +// .canSeeAvailableViewsForBankAccount_(true) +// .canUpdateBankAccountLabel_(true) +// .canSeeViewsWithPermissionsForOneUser_(true) +// .canSeeViewsWithPermissionsForAllUsers_(true) +// .canCreateCustomView_(false) +// .canDeleteCustomView_(false) +// .canUpdateCustomView_(false) +// .canGrantAccessToCustomViews_(false) +// .canRevokeAccessToCustomViews_(false) +// .canGrantAccessToViews_(DEFAULT_CAN_GRANT_AND_REVOKE_ACCESS_TO_VIEWS.mkString(",")) +// .canRevokeAccessToViews_(DEFAULT_CAN_GRANT_AND_REVOKE_ACCESS_TO_VIEWS.mkString(",")) +// .save +// ) +// +// val standardView = ViewDefinition.find( +// NullRef(ViewDefinition.bank_id), +// NullRef(ViewDefinition.account_id), +// By(ViewDefinition.view_id, SYSTEM_STANDARD_VIEW_ID), +// By(ViewDefinition.isSystem_,true) +// ).map(view => +// view +// .canSeeTransactionRequestTypes_(true) +// .canSeeTransactionRequests_(true) +// .canSeeAvailableViewsForBankAccount_(true) +// .canUpdateBankAccountLabel_(true) +// .canSeeViewsWithPermissionsForOneUser_(true) +// .canSeeViewsWithPermissionsForAllUsers_(true) +// .canCreateCustomView_(false) +// .canDeleteCustomView_(false) +// .canUpdateCustomView_(false) +// .canGrantAccessToCustomViews_(false) +// .canRevokeAccessToCustomViews_(false) +// .canGrantAccessToViews_(DEFAULT_CAN_GRANT_AND_REVOKE_ACCESS_TO_VIEWS.mkString(",")) +// .canRevokeAccessToViews_(DEFAULT_CAN_GRANT_AND_REVOKE_ACCESS_TO_VIEWS.mkString(",")) +// .save +// ) +// +// +// val isSuccessful = ownerView.isDefined && standardView.isDefined +// val endDate = System.currentTimeMillis() +// +// val comment: String = +// s"""ViewDefinition system $SYSTEM_OWNER_VIEW_ID and $SYSTEM_STANDARD_VIEW_ID views, update the following rows to true: +// |${ViewDefinition.canSeeTransactionRequestTypes_.dbColumnName} +// |${ViewDefinition.canSeeTransactionRequests_.dbColumnName} +// |${ViewDefinition.canSeeAvailableViewsForBankAccount_.dbColumnName} +// |${ViewDefinition.canUpdateBankAccountLabel_.dbColumnName} +// |${ViewDefinition.canCreateCustomView_.dbColumnName} +// |${ViewDefinition.canDeleteCustomView_.dbColumnName} +// |${ViewDefinition.canUpdateCustomView_.dbColumnName} +// |${ViewDefinition.canSeeViewsWithPermissionsForAllUsers_.dbColumnName} +// |${ViewDefinition.canSeeViewsWithPermissionsForOneUser_.dbColumnName} +// |${ViewDefinition.canGrantAccessToCustomViews_.dbColumnName} +// |${ViewDefinition.canRevokeAccessToCustomViews_.dbColumnName} +// |${ViewDefinition.canGrantAccessToViews_.dbColumnName} +// |${ViewDefinition.canRevokeAccessToViews_.dbColumnName} +// |Duration: ${endDate - startDate} ms; +// """.stripMargin +// saveLog(name, commitId, isSuccessful, startDate, endDate, comment) +// isSuccessful +// +// case false => +// val startDate = System.currentTimeMillis() +// val commitId: String = APIUtil.gitCommit +// val isSuccessful = false +// val endDate = System.currentTimeMillis() +// val comment: String = +// s"""ViewDefinition does not exist!""".stripMargin +// saveLog(name, commitId, isSuccessful, startDate, endDate, comment) +// isSuccessful +// } +// } +//} diff --git a/obp-api/src/main/scala/code/api/util/newstyle/BalanceNewStyle.scala b/obp-api/src/main/scala/code/api/util/newstyle/BalanceNewStyle.scala index 094ece2e8..7619a03b6 100644 --- a/obp-api/src/main/scala/code/api/util/newstyle/BalanceNewStyle.scala +++ b/obp-api/src/main/scala/code/api/util/newstyle/BalanceNewStyle.scala @@ -1,12 +1,14 @@ package code.api.util.newstyle +import code.api.Constant._ import code.api.util.APIUtil.{OBPReturnType, unboxFullOrFail} -import code.api.util.ErrorMessages.{InvalidConnectorResponse} +import code.api.util.ErrorMessages.InvalidConnectorResponse import code.api.util.{APIUtil, CallContext} import code.bankconnectors.Connector import code.views.Views -import com.openbankproject.commons.model.{AccountBalances, AccountsBalances, BankId, BankIdAccountId, User, ViewId} import com.github.dwickern.macros.NameOf.nameOf +import com.openbankproject.commons.model._ + import scala.concurrent.Future object BalanceNewStyle { @@ -20,7 +22,7 @@ object BalanceNewStyle { Future { val (views, accountAccesses) = Views.views.vend.getAccountAccessAtBankThroughView(user, bankId, viewId) // Filter views which can read the balance - val canSeeBankAccountBalanceViews = views.filter(_.canSeeBankAccountBalance) + val canSeeBankAccountBalanceViews = views.filter(_.allowed_actions.exists( _ == CAN_SEE_BANK_ACCOUNT_BALANCE)) // Filter accounts the user has permission to see balances and remove duplicates val allowedAccounts = APIUtil.intersectAccountAccessAndView(accountAccesses, canSeeBankAccountBalanceViews) allowedAccounts @@ -35,7 +37,7 @@ object BalanceNewStyle { Future { val (views, accountAccesses) = Views.views.vend.privateViewsUserCanAccessAtBank(user, bankId) // Filter views which can read the balance - val canSeeBankAccountBalanceViews = views.filter(_.canSeeBankAccountBalance) + val canSeeBankAccountBalanceViews = views.filter(_.allowed_actions.exists( _ == CAN_SEE_BANK_ACCOUNT_BALANCE)) // Filter accounts the user has permission to see balances and remove duplicates val allowedAccounts = APIUtil.intersectAccountAccessAndView(accountAccesses, canSeeBankAccountBalanceViews) allowedAccounts 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 4fa5bd0c4..0a49ae910 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 @@ -1,5 +1,6 @@ package code.api.v1_2_1 +import code.api.Constant._ import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON._ import code.api.cache.Caching import code.api.util.APIUtil._ @@ -14,8 +15,6 @@ import code.model.{BankAccountX, BankX, ModeratedTransactionMetadata, UserX, toB import code.util.Helper import code.util.Helper.booleanToBox import code.views.Views -import code.views.system.ViewDefinition -import com.github.dwickern.macros.NameOf.nameOf import com.openbankproject.commons.ExecutionContext.Implicits.global import com.openbankproject.commons.model._ import com.openbankproject.commons.util.ApiVersion @@ -478,10 +477,10 @@ trait APIMethods121 { (Full(u), callContext) <- authenticatedAccess(cc) json <- NewStyle.function.tryons(InvalidJsonFormat, 400, callContext) { json.extract[UpdateAccountJSON] } (account, callContext) <- NewStyle.function.checkBankAccountExists(bankId, accountId, callContext) - anyViewContainsCanUpdateBankAccountLabelPermission = Views.views.vend.permission(BankIdAccountId(account.bankId, account.accountId), u) - .map(_.views.map(_.canUpdateBankAccountLabel).find(_.==(true)).getOrElse(false)).getOrElse(false) + permission <- NewStyle.function.permission(account.bankId, account.accountId, u, callContext) + anyViewContainsCanUpdateBankAccountLabelPermission = permission.views.map(_.allowed_actions.exists(_ == CAN_UPDATE_BANK_ACCOUNT_LABEL)).find(true == _).getOrElse(false) _ <- Helper.booleanToFuture( - s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canUpdateBankAccountLabel_)).dropRight(1)}` permission on any your views", + s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_UPDATE_BANK_ACCOUNT_LABEL)}` permission on any your views", cc = callContext ) { anyViewContainsCanUpdateBankAccountLabelPermission @@ -541,10 +540,10 @@ trait APIMethods121 { u <- cc.user ?~ UserNotLoggedIn bankAccount <- BankAccountX(bankId, accountId) ?~! BankAccountNotFound permission <- Views.views.vend.permission(BankIdAccountId(bankAccount.bankId, bankAccount.accountId), u) - anyViewContainsCanSeeAvailableViewsForBankAccountPermission = permission.views.map(_.canSeeAvailableViewsForBankAccount).find(_.==(true)).getOrElse(false) + anyViewContainsCanSeeAvailableViewsForBankAccountPermission = permission.views.map(_.allowed_actions.exists(_ == CAN_SEE_AVAILABLE_VIEWS_FOR_BANK_ACCOUNT)).find(_.==(true)).getOrElse(false) _ <- Helper.booleanToBox( anyViewContainsCanSeeAvailableViewsForBankAccountPermission, - s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canSeeAvailableViewsForBankAccount_)).dropRight(1)}` permission on any your views" + s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_SEE_AVAILABLE_VIEWS_FOR_BANK_ACCOUNT)}` permission on any your views" ) views <- Full(Views.views.vend.availableViewsForAccount(BankIdAccountId(bankAccount.bankId, bankAccount.accountId))) } yield { @@ -606,10 +605,10 @@ trait APIMethods121 { createViewJsonV121.allowed_actions ) anyViewContainsCanCreateCustomViewPermission = Views.views.vend.permission(BankIdAccountId(account.bankId, account.accountId), u) - .map(_.views.map(_.canCreateCustomView).find(_.==(true)).getOrElse(false)).getOrElse(false) + .map(_.views.map(_.allowed_actions.exists(_ == CAN_CREATE_CUSTOM_VIEW)).find(_.==(true)).getOrElse(false)).getOrElse(false) _ <- booleanToBox( anyViewContainsCanCreateCustomViewPermission, - s"${ErrorMessages.CreateCustomViewError} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canCreateCustomView_)).dropRight(1)}` permission on any your views" + s"${ErrorMessages.CreateCustomViewError} You need the `${StringHelpers.snakify(CAN_CREATE_CUSTOM_VIEW)}` permission on any your views" ) view <- Views.views.vend.createCustomView(BankIdAccountId(bankId,accountId), createViewJson)?~ CreateCustomViewError } yield { @@ -668,10 +667,10 @@ trait APIMethods121 { allowed_actions = updateJsonV121.allowed_actions ) anyViewContainsCanUpdateCustomViewPermission = Views.views.vend.permission(BankIdAccountId(account.bankId, account.accountId), u) - .map(_.views.map(_.canUpdateCustomView).find(_.==(true)).getOrElse(false)).getOrElse(false) + .map(_.views.map(_.allowed_actions.exists(_ == CAN_UPDATE_CUSTOM_VIEW)).find(_.==(true)).getOrElse(false)).getOrElse(false) _ <- booleanToBox( anyViewContainsCanUpdateCustomViewPermission, - s"${ErrorMessages.CreateCustomViewError} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canUpdateCustomView_)).dropRight(1)}` permission on any your views" + s"${ErrorMessages.CreateCustomViewError} You need the `${StringHelpers.snakify(CAN_UPDATE_CUSTOM_VIEW)}` permission on any your views" ) updatedView <- Views.views.vend.updateCustomView(BankIdAccountId(bankId, accountId),viewId, updateViewJson) ?~ CreateCustomViewError } yield { @@ -714,9 +713,9 @@ trait APIMethods121 { _ <- NewStyle.function.customView(viewId, BankIdAccountId(bankId, accountId), callContext) anyViewContainsCanDeleteCustomViewPermission = Views.views.vend.permission(BankIdAccountId(account.bankId, account.accountId), u) - .map(_.views.map(_.canDeleteCustomView).find(_.==(true)).getOrElse(false)).getOrElse(false) + .map(_.views.map(_.allowed_actions.exists(_ == CAN_DELETE_CUSTOM_VIEW)).find(_.==(true)).getOrElse(false)).getOrElse(false) _ <- Helper.booleanToFuture( - s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canDeleteCustomView_)).dropRight(1)}` permission on any your views", + s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_DELETE_CUSTOM_VIEW)}` permission on any your views", cc = callContext ) { anyViewContainsCanDeleteCustomViewPermission @@ -753,10 +752,10 @@ trait APIMethods121 { u <- cc.user ?~ UserNotLoggedIn account <- BankAccountX(bankId, accountId) ?~! BankAccountNotFound anyViewContainsCanSeeViewsWithPermissionsForAllUsersPermission = Views.views.vend.permission(BankIdAccountId(account.bankId, account.accountId), u) - .map(_.views.map(_.canSeeViewsWithPermissionsForAllUsers).find(_.==(true)).getOrElse(false)).getOrElse(false) + .map(_.views.map(_.allowed_actions.exists(_ == CAN_SEE_VIEWS_WITH_PERMISSIONS_FOR_ALL_USERS)).find(_.==(true)).getOrElse(false)).getOrElse(false) _ <- booleanToBox( anyViewContainsCanSeeViewsWithPermissionsForAllUsersPermission, - s"${ErrorMessages.CreateCustomViewError} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canSeeViewsWithPermissionsForAllUsers_)).dropRight(1)}` permission on any your views" + s"${ErrorMessages.CreateCustomViewError} You need the `${StringHelpers.snakify(CAN_SEE_VIEWS_WITH_PERMISSIONS_FOR_ALL_USERS)}` permission on any your views" ) permissions = Views.views.vend.permissions(BankIdAccountId(bankId, accountId)) } yield { @@ -797,11 +796,11 @@ trait APIMethods121 { loggedInUser <- cc.user ?~ UserNotLoggedIn account <- BankAccountX(bankId, accountId) ?~! BankAccountNotFound loggedInUserPermissionBox = Views.views.vend.permission(BankIdAccountId(bankId, accountId), loggedInUser) - anyViewContainsCanSeeViewsWithPermissionsForOneUserPermission = loggedInUserPermissionBox.map(_.views.map(_.canSeeViewsWithPermissionsForOneUser) + anyViewContainsCanSeeViewsWithPermissionsForOneUserPermission = loggedInUserPermissionBox.map(_.views.map(_.allowed_actions.exists(_ == CAN_SEE_VIEWS_WITH_PERMISSIONS_FOR_ONE_USER)) .find(_.==(true)).getOrElse(false)).getOrElse(false) _ <- booleanToBox( anyViewContainsCanSeeViewsWithPermissionsForOneUserPermission, - s"${ErrorMessages.CreateCustomViewError} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canSeeViewsWithPermissionsForOneUser_)).dropRight(1)}` permission on any your views" + s"${ErrorMessages.CreateCustomViewError} You need the `${StringHelpers.snakify(CAN_SEE_VIEWS_WITH_PERMISSIONS_FOR_ONE_USER)}` permission on any your views" ) userFromURL <- UserX.findByProviderId(provider, providerId) ?~! UserNotFoundByProviderAndProvideId permission <- Views.views.vend.permission(BankIdAccountId(bankId, accountId), userFromURL) diff --git a/obp-api/src/main/scala/code/api/v1_2_1/JSONFactory1.2.1.scala b/obp-api/src/main/scala/code/api/v1_2_1/JSONFactory1.2.1.scala index 84db9b773..129383913 100644 --- a/obp-api/src/main/scala/code/api/v1_2_1/JSONFactory1.2.1.scala +++ b/obp-api/src/main/scala/code/api/v1_2_1/JSONFactory1.2.1.scala @@ -26,6 +26,7 @@ TESOBE (http://www.tesobe.com/) */ package code.api.v1_2_1 +import code.api.Constant._ import code.api.util.APIUtil import code.api.util.APIUtil._ import code.api.util.ErrorMessages.MandatoryPropertyIsNotSet @@ -372,7 +373,7 @@ object JSONFactory{ val phone = APIUtil.getPropsValue("hosted_by.phone", "+49 (0)30 8145 3994") val organisationWebsite = APIUtil.getPropsValue("organisation_website", "https://www.tesobe.com") - val connector = code.api.Constant.Connector.openOrThrowException(s"$MandatoryPropertyIsNotSet. The missing prop is `connector` ") + val connector = code.api.Constant.CONNECTOR.openOrThrowException(s"$MandatoryPropertyIsNotSet. The missing prop is `connector` ") val hostedBy = new HostedBy(organisation, email, phone, organisationWebsite) val apiInfoJSON = new APIInfoJSON(apiVersion.vDottedApiVersion, apiVersionStatus, gitCommit, connector, hostedBy) @@ -413,65 +414,65 @@ object JSONFactory{ is_public = view.isPublic, alias = alias, hide_metadata_if_alias_used = view.hideOtherAccountMetadataIfAlias, - can_add_comment = view.canAddComment, - can_add_corporate_location = view.canAddCorporateLocation, - can_add_image = view.canAddImage, - can_add_image_url = view.canAddImageURL, - can_add_more_info = view.canAddMoreInfo, - can_add_open_corporates_url = view.canAddOpenCorporatesUrl, - can_add_physical_location = view.canAddPhysicalLocation, - can_add_private_alias = view.canAddPrivateAlias, - can_add_public_alias = view.canAddPublicAlias, - can_add_tag = view.canAddTag, - can_add_url = view.canAddURL, - can_add_where_tag = view.canAddWhereTag, - can_delete_comment = view.canDeleteComment, - can_delete_corporate_location = view.canDeleteCorporateLocation, - can_delete_image = view.canDeleteImage, - can_delete_physical_location = view.canDeletePhysicalLocation, - can_delete_tag = view.canDeleteTag, - can_delete_where_tag = view.canDeleteWhereTag, - can_edit_owner_comment = view.canEditOwnerComment, - can_see_bank_account_balance = view.canSeeBankAccountBalance, - can_see_bank_account_bank_name = view.canSeeBankAccountBankName, - can_see_bank_account_currency = view.canSeeBankAccountCurrency, - can_see_bank_account_iban = view.canSeeBankAccountIban, - can_see_bank_account_label = view.canSeeBankAccountLabel, - can_see_bank_account_national_identifier = view.canSeeBankAccountNationalIdentifier, - can_see_bank_account_number = view.canSeeBankAccountNumber, - can_see_bank_account_owners = view.canSeeBankAccountOwners, - can_see_bank_account_swift_bic = view.canSeeBankAccountSwift_bic, - can_see_bank_account_type = view.canSeeBankAccountType, - can_see_comments = view.canSeeComments, - can_see_corporate_location = view.canSeeCorporateLocation, - can_see_image_url = view.canSeeImageUrl, - can_see_images = view.canSeeImages, - can_see_more_info = view.canSeeMoreInfo, - can_see_open_corporates_url = view.canSeeOpenCorporatesUrl, - can_see_other_account_bank_name = view.canSeeOtherAccountBankName, - can_see_other_account_iban = view.canSeeOtherAccountIBAN, - can_see_other_account_kind = view.canSeeOtherAccountKind, - can_see_other_account_metadata = view.canSeeOtherAccountMetadata, - can_see_other_account_national_identifier = view.canSeeOtherAccountNationalIdentifier, - can_see_other_account_number = view.canSeeOtherAccountNumber, - can_see_other_account_swift_bic = view.canSeeOtherAccountSWIFT_BIC, - can_see_owner_comment = view.canSeeOwnerComment, - can_see_physical_location = view.canSeePhysicalLocation, - can_see_private_alias = view.canSeePrivateAlias, - can_see_public_alias = view.canSeePublicAlias, - can_see_tags = view.canSeeTags, - can_see_transaction_amount = view.canSeeTransactionAmount, - can_see_transaction_balance = view.canSeeTransactionBalance, - can_see_transaction_currency = view.canSeeTransactionCurrency, - can_see_transaction_description = view.canSeeTransactionDescription, - can_see_transaction_finish_date = view.canSeeTransactionFinishDate, - can_see_transaction_metadata = view.canSeeTransactionMetadata, - can_see_transaction_other_bank_account = view.canSeeTransactionOtherBankAccount, - can_see_transaction_start_date = view.canSeeTransactionStartDate, - can_see_transaction_this_bank_account = view.canSeeTransactionThisBankAccount, - can_see_transaction_type = view.canSeeTransactionType, - can_see_url = view.canSeeUrl, - can_see_where_tag = view.canSeeWhereTag + can_add_comment = view.allowed_actions.exists(_ == CAN_ADD_COMMENT), + can_add_corporate_location = view.allowed_actions.exists(_ == CAN_ADD_CORPORATE_LOCATION), + can_add_image = view.allowed_actions.exists(_ == CAN_ADD_IMAGE), + can_add_image_url = view.allowed_actions.exists(_ == CAN_ADD_IMAGE_URL), + can_add_more_info = view.allowed_actions.exists(_ == CAN_ADD_MORE_INFO), + can_add_open_corporates_url = view.allowed_actions.exists(_ == CAN_ADD_OPEN_CORPORATES_URL), + can_add_physical_location = view.allowed_actions.exists(_ == CAN_ADD_PHYSICAL_LOCATION), + can_add_private_alias = view.allowed_actions.exists(_ == CAN_ADD_PRIVATE_ALIAS), + can_add_public_alias = view.allowed_actions.exists(_ == CAN_ADD_PUBLIC_ALIAS), + can_add_tag = view.allowed_actions.exists(_ == CAN_ADD_TAG), + can_add_url = view.allowed_actions.exists(_ == CAN_ADD_URL), + can_add_where_tag = view.allowed_actions.exists(_ == CAN_ADD_WHERE_TAG), + can_delete_comment = view.allowed_actions.exists(_ == CAN_DELETE_COMMENT), + can_delete_corporate_location = view.allowed_actions.exists(_ == CAN_DELETE_CORPORATE_LOCATION), + can_delete_image = view.allowed_actions.exists(_ == CAN_DELETE_IMAGE), + can_delete_physical_location = view.allowed_actions.exists(_ == CAN_DELETE_PHYSICAL_LOCATION), + can_delete_tag = view.allowed_actions.exists(_ == CAN_DELETE_TAG), + can_delete_where_tag = view.allowed_actions.exists(_ == CAN_DELETE_WHERE_TAG), + can_edit_owner_comment = view.allowed_actions.exists(_ == CAN_EDIT_OWNER_COMMENT), + can_see_bank_account_balance = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_BALANCE), + can_see_bank_account_bank_name = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_BANK_NAME), + can_see_bank_account_currency = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_CURRENCY), + can_see_bank_account_iban = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_IBAN), + can_see_bank_account_label = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_LABEL), + can_see_bank_account_national_identifier = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_NATIONAL_IDENTIFIER), + can_see_bank_account_number = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_NUMBER), + can_see_bank_account_owners = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_OWNERS), + can_see_bank_account_swift_bic = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_SWIFT_BIC), + can_see_bank_account_type = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_TYPE), + can_see_comments = view.allowed_actions.exists(_ == CAN_SEE_COMMENTS), + can_see_corporate_location = view.allowed_actions.exists(_ == CAN_SEE_CORPORATE_LOCATION), + can_see_image_url = view.allowed_actions.exists(_ == CAN_SEE_IMAGE_URL), + can_see_images = view.allowed_actions.exists(_ == CAN_SEE_IMAGES), + can_see_more_info = view.allowed_actions.exists(_ == CAN_SEE_MORE_INFO), + can_see_open_corporates_url = view.allowed_actions.exists(_ == CAN_SEE_OPEN_CORPORATES_URL), + can_see_other_account_bank_name = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_BANK_NAME), + can_see_other_account_iban = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_IBAN), + can_see_other_account_kind = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_KIND), + can_see_other_account_metadata = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_METADATA), + can_see_other_account_national_identifier = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_NATIONAL_IDENTIFIER), + can_see_other_account_number = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_NUMBER), + can_see_other_account_swift_bic = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_SWIFT_BIC), + can_see_owner_comment = view.allowed_actions.exists(_ == CAN_SEE_OWNER_COMMENT), + can_see_physical_location = view.allowed_actions.exists(_ == CAN_SEE_PHYSICAL_LOCATION), + can_see_private_alias = view.allowed_actions.exists(_ == CAN_SEE_PRIVATE_ALIAS), + can_see_public_alias = view.allowed_actions.exists(_ == CAN_SEE_PUBLIC_ALIAS), + can_see_tags = view.allowed_actions.exists(_ == CAN_SEE_TAGS), + can_see_transaction_amount = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_AMOUNT), + can_see_transaction_balance = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_BALANCE), + can_see_transaction_currency = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_CURRENCY), + can_see_transaction_description = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_DESCRIPTION), + can_see_transaction_finish_date = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_FINISH_DATE), + can_see_transaction_metadata = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_METADATA), + can_see_transaction_other_bank_account = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_OTHER_BANK_ACCOUNT), + can_see_transaction_start_date = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_START_DATE), + can_see_transaction_this_bank_account = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_THIS_BANK_ACCOUNT), + can_see_transaction_type = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_TYPE), + can_see_url = view.allowed_actions.exists(_ == CAN_SEE_URL), + can_see_where_tag = view.allowed_actions.exists(_ == CAN_SEE_WHERE_TAG) ) } 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 15dbbda2b..e100c508d 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 @@ -2,6 +2,7 @@ package code.api.v2_0_0 import code.TransactionTypes.TransactionType import code.api.APIFailureNewStyle +import code.api.Constant._ import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON._ import code.api.util.APIUtil._ import code.api.util.ApiTag._ @@ -25,8 +26,6 @@ import code.users.Users import code.util.Helper import code.util.Helper.{booleanToBox, booleanToFuture} import code.views.Views -import code.views.system.ViewDefinition -import com.github.dwickern.macros.NameOf.nameOf import com.openbankproject.commons.ExecutionContext.Implicits.global import com.openbankproject.commons.model._ import com.openbankproject.commons.util.ApiVersion @@ -1051,9 +1050,9 @@ trait APIMethods200 { (_, callContext) <- NewStyle.function.getBank(bankId, callContext) (account, callContext) <- NewStyle.function.getBankAccount(bankId, accountId, callContext) anyViewContainsCanSeeViewsWithPermissionsForAllUsersPermission = Views.views.vend.permission(BankIdAccountId(account.bankId, account.accountId), u) - .map(_.views.map(_.canSeeViewsWithPermissionsForAllUsers).find(_.==(true)).getOrElse(false)).getOrElse(false) + .map(_.views.map(_.allowed_actions.exists(_ == CAN_SEE_VIEWS_WITH_PERMISSIONS_FOR_ALL_USERS)).find(_.==(true)).getOrElse(false)).getOrElse(false) _ <- Helper.booleanToFuture( - s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canSeeViewsWithPermissionsForAllUsers_)).dropRight(1)}` permission on any your views", + s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_SEE_VIEWS_WITH_PERMISSIONS_FOR_ALL_USERS)}` permission on any your views", cc = callContext ) { anyViewContainsCanSeeViewsWithPermissionsForAllUsersPermission @@ -1093,11 +1092,12 @@ trait APIMethods200 { (bank, callContext) <- BankX(bankId, Some(cc)) ?~! BankNotFound // Check bank exists. account <- BankAccountX(bank.bankId, accountId) ?~! {ErrorMessages.AccountNotFound} // Check Account exists. loggedInUserPermissionBox = Views.views.vend.permission(BankIdAccountId(bankId, accountId), loggedInUser) - anyViewContainsCanSeePermissionForOneUserPermission = loggedInUserPermissionBox.map(_.views.map(_.canSeeViewsWithPermissionsForOneUser) + anyViewContainsCanSeePermissionForOneUserPermission = loggedInUserPermissionBox.map(_.views.map(_.allowed_actions.exists( _ == CAN_SEE_VIEWS_WITH_PERMISSIONS_FOR_ONE_USER)) .find(_.==(true)).getOrElse(false)).getOrElse(false) + _ <- booleanToBox( anyViewContainsCanSeePermissionForOneUserPermission, - s"${ErrorMessages.CreateCustomViewError} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canSeeViewsWithPermissionsForOneUser_)).dropRight(1)}` permission on any your views" + s"${ErrorMessages.CreateCustomViewError} You need the `${StringHelpers.snakify(CAN_SEE_VIEWS_WITH_PERMISSIONS_FOR_ONE_USER)}` permission on any your views" ) userFromURL <- UserX.findByProviderId(provider, providerId) ?~! UserNotFoundByProviderAndProvideId permission <- Views.views.vend.permission(BankIdAccountId(bankId, accountId), userFromURL) 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 bb3e0d058..88ca6fd5e 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,6 +1,7 @@ package code.api.v2_1_0 import code.TransactionTypes.TransactionType +import code.api.Constant.CAN_SEE_TRANSACTION_REQUESTS import code.api.util.ApiTag._ import code.api.util.ErrorMessages.TransactionDisabled import code.api.util.FutureUtil.EndpointContext @@ -24,8 +25,6 @@ import code.sandbox.SandboxData import code.usercustomerlinks.UserCustomerLink import code.users.Users import code.util.Helper.booleanToBox -import code.views.system.ViewDefinition -import com.github.dwickern.macros.NameOf.nameOf import com.openbankproject.commons.dto.GetProductsParam import com.openbankproject.commons.model._ import com.openbankproject.commons.model.enums.TransactionRequestTypes._ @@ -744,8 +743,8 @@ trait APIMethods210 { (bank, callContext ) <- BankX(bankId, Some(cc)) ?~! {BankNotFound} (fromAccount, callContext) <- BankAccountX(bankId, accountId, Some(cc)) ?~! {AccountNotFound} view <- APIUtil.checkViewAccessAndReturnView(viewId, BankIdAccountId(bankId, accountId), Some(u), callContext) - _ <- Helper.booleanToBox(view.canSeeTransactionRequests, - s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canSeeTransactionRequests_)).dropRight(1)}` permission on the View(${viewId.value} )") + _ <- Helper.booleanToBox(view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_REQUESTS), + s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_SEE_TRANSACTION_REQUESTS)}` permission on the View(${viewId.value} )") (transactionRequests,callContext) <- Connector.connector.vend.getTransactionRequests210(u, fromAccount, callContext) } yield { diff --git a/obp-api/src/main/scala/code/api/v2_1_0/JSONFactory2.1.0.scala b/obp-api/src/main/scala/code/api/v2_1_0/JSONFactory2.1.0.scala index b31c322da..a28849d92 100644 --- a/obp-api/src/main/scala/code/api/v2_1_0/JSONFactory2.1.0.scala +++ b/obp-api/src/main/scala/code/api/v2_1_0/JSONFactory2.1.0.scala @@ -26,12 +26,9 @@ TESOBE (http://www.tesobe.com/) */ package code.api.v2_1_0 -import java.lang -import java.util.Date - +import code.api.Constant._ import code.api.util.ApiRole -import code.api.v1_2_1.{BankRoutingJsonV121} -import com.openbankproject.commons.model.{AccountRoutingJsonV121, AmountOfMoneyJsonV121} +import code.api.v1_2_1.BankRoutingJsonV121 import code.api.v1_4_0.JSONFactory1_4_0._ import code.api.v2_0_0.JSONFactory200.{UserJsonV200, UsersJsonV200, createEntitlementJSONs} import code.api.v2_0_0.TransactionRequestChargeJsonV200 @@ -40,13 +37,12 @@ import code.entitlement.Entitlement import code.metrics.APIMetric import code.model.dataAccess.ResourceUser import code.model.{Consumer, _} -import com.openbankproject.commons.model.Product -import code.transactionrequests.TransactionRequests._ import code.users.Users import com.openbankproject.commons.model._ import net.liftweb.common.{Box, Full} -import scala.collection.immutable.List +import java.lang +import java.util.Date @@ -804,66 +800,66 @@ object JSONFactory210{ is_public = view.isPublic, alias = alias, hide_metadata_if_alias_used = view.hideOtherAccountMetadataIfAlias, - can_add_comment = view.canAddComment, - can_add_corporate_location = view.canAddCorporateLocation, - can_add_image = view.canAddImage, - can_add_image_url = view.canAddImageURL, - can_add_more_info = view.canAddMoreInfo, - can_add_open_corporates_url = view.canAddOpenCorporatesUrl, - can_add_physical_location = view.canAddPhysicalLocation, - can_add_private_alias = view.canAddPrivateAlias, - can_add_public_alias = view.canAddPublicAlias, - can_add_tag = view.canAddTag, - can_add_url = view.canAddURL, - can_add_where_tag = view.canAddWhereTag, - can_add_counterparty = view.canAddCounterparty, - can_delete_comment = view.canDeleteComment, - can_delete_corporate_location = view.canDeleteCorporateLocation, - can_delete_image = view.canDeleteImage, - can_delete_physical_location = view.canDeletePhysicalLocation, - can_delete_tag = view.canDeleteTag, - can_delete_where_tag = view.canDeleteWhereTag, - can_edit_owner_comment = view.canEditOwnerComment, - can_see_bank_account_balance = view.canSeeBankAccountBalance, - can_see_bank_account_bank_name = view.canSeeBankAccountBankName, - can_see_bank_account_currency = view.canSeeBankAccountCurrency, - can_see_bank_account_iban = view.canSeeBankAccountIban, - can_see_bank_account_label = view.canSeeBankAccountLabel, - can_see_bank_account_national_identifier = view.canSeeBankAccountNationalIdentifier, - can_see_bank_account_number = view.canSeeBankAccountNumber, - can_see_bank_account_owners = view.canSeeBankAccountOwners, - can_see_bank_account_swift_bic = view.canSeeBankAccountSwift_bic, - can_see_bank_account_type = view.canSeeBankAccountType, - can_see_comments = view.canSeeComments, - can_see_corporate_location = view.canSeeCorporateLocation, - can_see_image_url = view.canSeeImageUrl, - can_see_images = view.canSeeImages, - can_see_more_info = view.canSeeMoreInfo, - can_see_open_corporates_url = view.canSeeOpenCorporatesUrl, - can_see_other_account_bank_name = view.canSeeOtherAccountBankName, - can_see_other_account_iban = view.canSeeOtherAccountIBAN, - can_see_other_account_kind = view.canSeeOtherAccountKind, - can_see_other_account_metadata = view.canSeeOtherAccountMetadata, - can_see_other_account_national_identifier = view.canSeeOtherAccountNationalIdentifier, - can_see_other_account_number = view.canSeeOtherAccountNumber, - can_see_other_account_swift_bic = view.canSeeOtherAccountSWIFT_BIC, - can_see_owner_comment = view.canSeeOwnerComment, - can_see_physical_location = view.canSeePhysicalLocation, - can_see_private_alias = view.canSeePrivateAlias, - can_see_public_alias = view.canSeePublicAlias, - can_see_tags = view.canSeeTags, - can_see_transaction_amount = view.canSeeTransactionAmount, - can_see_transaction_balance = view.canSeeTransactionBalance, - can_see_transaction_currency = view.canSeeTransactionCurrency, - can_see_transaction_description = view.canSeeTransactionDescription, - can_see_transaction_finish_date = view.canSeeTransactionFinishDate, - can_see_transaction_metadata = view.canSeeTransactionMetadata, - can_see_transaction_other_bank_account = view.canSeeTransactionOtherBankAccount, - can_see_transaction_start_date = view.canSeeTransactionStartDate, - can_see_transaction_this_bank_account = view.canSeeTransactionThisBankAccount, - can_see_transaction_type = view.canSeeTransactionType, - can_see_url = view.canSeeUrl, - can_see_where_tag = view.canSeeWhereTag + can_add_comment = view.allowed_actions.exists(_ == CAN_ADD_COMMENT), + can_add_corporate_location = view.allowed_actions.exists(_ == CAN_ADD_CORPORATE_LOCATION), + can_add_image = view.allowed_actions.exists(_ == CAN_ADD_IMAGE), + can_add_image_url = view.allowed_actions.exists(_ == CAN_ADD_IMAGE_URL), + can_add_more_info = view.allowed_actions.exists(_ == CAN_ADD_MORE_INFO), + can_add_open_corporates_url = view.allowed_actions.exists(_ == CAN_ADD_OPEN_CORPORATES_URL), + can_add_physical_location = view.allowed_actions.exists(_ == CAN_ADD_PHYSICAL_LOCATION), + can_add_private_alias = view.allowed_actions.exists(_ == CAN_ADD_PRIVATE_ALIAS), + can_add_public_alias = view.allowed_actions.exists(_ == CAN_ADD_PUBLIC_ALIAS), + can_add_tag = view.allowed_actions.exists(_ == CAN_ADD_TAG), + can_add_url = view.allowed_actions.exists(_ == CAN_ADD_URL), + can_add_where_tag = view.allowed_actions.exists(_ == CAN_ADD_WHERE_TAG), + can_add_counterparty = view.allowed_actions.exists(_ == CAN_ADD_COUNTERPARTY), + can_delete_comment = view.allowed_actions.exists(_ == CAN_DELETE_COMMENT), + can_delete_corporate_location = view.allowed_actions.exists(_ == CAN_DELETE_CORPORATE_LOCATION), + can_delete_image = view.allowed_actions.exists(_ == CAN_DELETE_IMAGE), + can_delete_physical_location = view.allowed_actions.exists(_ == CAN_DELETE_PHYSICAL_LOCATION), + can_delete_tag = view.allowed_actions.exists(_ == CAN_DELETE_TAG), + can_delete_where_tag = view.allowed_actions.exists(_ == CAN_DELETE_WHERE_TAG), + can_edit_owner_comment = view.allowed_actions.exists(_ == CAN_EDIT_OWNER_COMMENT), + can_see_bank_account_balance = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_BALANCE), + can_see_bank_account_bank_name = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_BANK_NAME), + can_see_bank_account_currency = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_CURRENCY), + can_see_bank_account_iban = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_IBAN), + can_see_bank_account_label = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_LABEL), + can_see_bank_account_national_identifier = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_NATIONAL_IDENTIFIER), + can_see_bank_account_number = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_NUMBER), + can_see_bank_account_owners = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_OWNERS), + can_see_bank_account_swift_bic = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_SWIFT_BIC), + can_see_bank_account_type = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_TYPE), + can_see_comments = view.allowed_actions.exists(_ == CAN_SEE_COMMENTS), + can_see_corporate_location = view.allowed_actions.exists(_ == CAN_SEE_CORPORATE_LOCATION), + can_see_image_url = view.allowed_actions.exists(_ == CAN_SEE_IMAGE_URL), + can_see_images = view.allowed_actions.exists(_ == CAN_SEE_IMAGES), + can_see_more_info = view.allowed_actions.exists(_ == CAN_SEE_MORE_INFO), + can_see_open_corporates_url = view.allowed_actions.exists(_ == CAN_SEE_OPEN_CORPORATES_URL), + can_see_other_account_bank_name = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_BANK_NAME), + can_see_other_account_iban = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_IBAN), + can_see_other_account_kind = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_KIND), + can_see_other_account_metadata = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_METADATA), + can_see_other_account_national_identifier = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_NATIONAL_IDENTIFIER), + can_see_other_account_number = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_NUMBER), + can_see_other_account_swift_bic = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_SWIFT_BIC), + can_see_owner_comment = view.allowed_actions.exists(_ == CAN_SEE_OWNER_COMMENT), + can_see_physical_location = view.allowed_actions.exists(_ == CAN_SEE_PHYSICAL_LOCATION), + can_see_private_alias = view.allowed_actions.exists(_ == CAN_SEE_PRIVATE_ALIAS), + can_see_public_alias = view.allowed_actions.exists(_ == CAN_SEE_PUBLIC_ALIAS), + can_see_tags = view.allowed_actions.exists(_ == CAN_SEE_TAGS), + can_see_transaction_amount = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_AMOUNT), + can_see_transaction_balance = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_BALANCE), + can_see_transaction_currency = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_CURRENCY), + can_see_transaction_description = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_DESCRIPTION), + can_see_transaction_finish_date = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_FINISH_DATE), + can_see_transaction_metadata = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_METADATA), + can_see_transaction_other_bank_account = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_OTHER_BANK_ACCOUNT), + can_see_transaction_start_date = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_START_DATE), + can_see_transaction_this_bank_account = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_THIS_BANK_ACCOUNT), + can_see_transaction_type = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_TYPE), + can_see_url = view.allowed_actions.exists(_ == CAN_SEE_URL), + can_see_where_tag = view.allowed_actions.exists(_ == CAN_SEE_WHERE_TAG) ) } diff --git a/obp-api/src/main/scala/code/api/v2_2_0/APIMethods220.scala b/obp-api/src/main/scala/code/api/v2_2_0/APIMethods220.scala index 5d7edbcab..7820b7891 100644 --- a/obp-api/src/main/scala/code/api/v2_2_0/APIMethods220.scala +++ b/obp-api/src/main/scala/code/api/v2_2_0/APIMethods220.scala @@ -1,5 +1,6 @@ package code.api.v2_2_0 +import code.api.Constant._ import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON._ import code.api.util.APIUtil._ import code.api.util.ApiRole._ @@ -23,8 +24,7 @@ import code.model.dataAccess.BankAccountCreation import code.util.Helper import code.util.Helper._ import code.views.Views -import code.views.system.ViewDefinition -import com.github.dwickern.macros.NameOf.nameOf +import code.views.system.ViewPermission import com.openbankproject.commons.ExecutionContext.Implicits.global import com.openbankproject.commons.model._ import com.openbankproject.commons.util.ApiVersion @@ -135,9 +135,9 @@ trait APIMethods220 { (Full(u), callContext) <- authenticatedAccess(cc) (account, callContext) <- NewStyle.function.checkBankAccountExists(bankId, accountId, callContext) permission <- NewStyle.function.permission(bankId, accountId, u, callContext) - anyViewContainsCanSeeAvailableViewsForBankAccountPermission = permission.views.map(_.canSeeAvailableViewsForBankAccount).find(_.==(true)).getOrElse(false) + anyViewContainsCanSeeAvailableViewsForBankAccountPermission = permission.views.map(_.allowed_actions.exists(_ == CAN_SEE_AVAILABLE_VIEWS_FOR_BANK_ACCOUNT)).find(true == _).getOrElse(false) _ <- Helper.booleanToFuture( - s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canSeeAvailableViewsForBankAccount_)).dropRight(1)}` permission on any your views", + s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${CAN_SEE_AVAILABLE_VIEWS_FOR_BANK_ACCOUNT}` permission on any your views", cc= callContext ){ anyViewContainsCanSeeAvailableViewsForBankAccountPermission @@ -202,12 +202,13 @@ trait APIMethods220 { createViewJsonV121.which_alias_to_use, createViewJsonV121.hide_metadata_if_alias_used, createViewJsonV121.allowed_actions - ) - anyViewContainsCanCreateCustomViewPermission = Views.views.vend.permission(BankIdAccountId(account.bankId, account.accountId), u) - .map(_.views.map(_.canCreateCustomView).find(_.==(true)).getOrElse(false)).getOrElse(false) + ) + permission <- Views.views.vend.permission(BankIdAccountId(account.bankId, account.accountId), u) + anyViewContainsCanCreateCustomViewPermission = permission.views.map(_.allowed_actions.exists(_ ==CAN_CREATE_CUSTOM_VIEW)).find(_ == true).getOrElse(false) + _ <- booleanToBox( anyViewContainsCanCreateCustomViewPermission, - s"${ErrorMessages.CreateCustomViewError} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canCreateCustomView_)).dropRight(1)}` permission on any your views" + s"${ErrorMessages.CreateCustomViewError} You need the `${CAN_CREATE_CUSTOM_VIEW}` permission on any your views" ) view <- Views.views.vend.createCustomView(BankIdAccountId(bankId, accountId), createViewJson) ?~ CreateCustomViewError } yield { @@ -262,11 +263,13 @@ trait APIMethods220 { hide_metadata_if_alias_used = updateJsonV121.hide_metadata_if_alias_used, allowed_actions = updateJsonV121.allowed_actions ) - anyViewContainsCancanUpdateCustomViewPermission = Views.views.vend.permission(BankIdAccountId(account.bankId, account.accountId), u) - .map(_.views.map(_.canUpdateCustomView).find(_.==(true)).getOrElse(false)).getOrElse(false) + + permission <- Views.views.vend.permission(BankIdAccountId(account.bankId, account.accountId), u) + anyViewContainsCancanUpdateCustomViewPermission = permission.views.map(_.allowed_actions.exists(_ == CAN_UPDATE_CUSTOM_VIEW)).find(true == _).getOrElse(false) + _ <- booleanToBox( anyViewContainsCancanUpdateCustomViewPermission, - s"${ErrorMessages.CreateCustomViewError} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canUpdateCustomView_)).dropRight(1)}` permission on any your views" + s"${ErrorMessages.CreateCustomViewError} You need the `${StringHelpers.snakify(CAN_UPDATE_CUSTOM_VIEW)}` permission on any your views" ) updatedView <- Views.views.vend.updateCustomView(BankIdAccountId(bankId, accountId), viewId, updateViewJson) ?~ CreateCustomViewError } yield { @@ -366,8 +369,11 @@ trait APIMethods220 { (Full(u), callContext) <- authenticatedAccess(cc) (account, callContext) <- NewStyle.function.checkBankAccountExists(bankId, accountId, callContext) view <- NewStyle.function.checkViewAccessAndReturnView(viewId, BankIdAccountId(account.bankId, account.accountId), Some(u), callContext) - _ <- Helper.booleanToFuture(failMsg = s"${NoViewPermission} can_get_counterparty", cc=callContext) { - view.canGetCounterparty == true + _ <- Helper.booleanToFuture( + s"${ErrorMessages.NoViewPermission} You need the `${StringHelpers.snakify(CAN_GET_COUNTERPARTY)}` permission on the View(${viewId.value} )", + cc = callContext + ) { + ViewPermission.findViewPermissions(view).exists(_.permission.get == CAN_GET_COUNTERPARTY) } (counterparties, callContext) <- NewStyle.function.getCounterparties(bankId,accountId,viewId, callContext) //Here we need create the metadata for all the explicit counterparties. maybe show them in json response. @@ -416,9 +422,14 @@ trait APIMethods220 { (Full(u), callContext) <- authenticatedAccess(cc) (account, callContext) <- NewStyle.function.checkBankAccountExists(bankId, accountId, callContext) view <- NewStyle.function.checkViewAccessAndReturnView(viewId, BankIdAccountId(account.bankId, account.accountId), Some(u), callContext) - _ <- Helper.booleanToFuture(failMsg = s"${NoViewPermission}can_get_counterparty", cc=callContext) { - view.canGetCounterparty == true + + _ <- Helper.booleanToFuture( + s"${ErrorMessages.NoViewPermission} You need the `${StringHelpers.snakify(CAN_GET_COUNTERPARTY)}` permission on the View(${viewId.value} )", + cc = callContext + ) { + ViewPermission.findViewPermissions(view).exists(_.permission.get == CAN_GET_COUNTERPARTY) } + counterpartyMetadata <- NewStyle.function.getMetadata(bankId, accountId, counterpartyId.value, callContext) (counterparty, callContext) <- NewStyle.function.getCounterpartyTrait(bankId, accountId, counterpartyId.value, callContext) } yield { @@ -1190,9 +1201,12 @@ trait APIMethods220 { json.extract[PostCounterpartyJSON] } view <- NewStyle.function.checkViewAccessAndReturnView(viewId, BankIdAccountId(bankId, accountId), Some(u), callContext) - - _ <- Helper.booleanToFuture(s"$NoViewPermission can_add_counterparty. Please use a view with that permission or add the permission to this view.", cc=callContext) {view.canAddCounterparty} - + _ <- Helper.booleanToFuture( + s"${ErrorMessages.NoViewPermission} You need the `${StringHelpers.snakify(CAN_ADD_COUNTERPARTY)}` permission on the View(${viewId.value} )", + cc = callContext + ) { + ViewPermission.findViewPermissions(view).exists(_.permission.get == CAN_ADD_COUNTERPARTY) + } (counterparty, callContext) <- Connector.connector.vend.checkCounterpartyExists(postJson.name, bankId.value, accountId.value, viewId.value, callContext) _ <- Helper.booleanToFuture(CounterpartyAlreadyExists.replace("value for BANK_ID or ACCOUNT_ID or VIEW_ID or NAME.", diff --git a/obp-api/src/main/scala/code/api/v2_2_0/JSONFactory2.2.0.scala b/obp-api/src/main/scala/code/api/v2_2_0/JSONFactory2.2.0.scala index da14fd454..c0f649796 100644 --- a/obp-api/src/main/scala/code/api/v2_2_0/JSONFactory2.2.0.scala +++ b/obp-api/src/main/scala/code/api/v2_2_0/JSONFactory2.2.0.scala @@ -26,31 +26,27 @@ TESOBE (http://www.tesobe.com/) */ package code.api.v2_2_0 -import java.util.Date - import code.actorsystem.ObpActorConfig -import code.api.util.{APIUtil, ApiPropsWithAlias, CustomJsonFormats, OptionalFieldSerializer} +import code.api.Constant._ import code.api.util.APIUtil.{EndpointInfo, MessageDoc, getPropsValue} +import code.api.util.{APIUtil, ApiPropsWithAlias, CustomJsonFormats, OptionalFieldSerializer} import code.api.v1_2_1.BankRoutingJsonV121 -import com.openbankproject.commons.model.{AccountRoutingJsonV121, AmountOfMoneyJsonV121} import code.api.v1_4_0.JSONFactory1_4_0._ import code.api.v2_1_0.{JSONFactory210, LocationJsonV210, PostCounterpartyBespokeJson, ResourceUserJSON} import code.atms.Atms.Atm import code.branches.Branches.{Branch, DriveUpString, LobbyString} -import com.openbankproject.commons.model.FXRate import code.metrics.ConnectorMetric -import code.model.dataAccess.ResourceUser import code.model._ -import com.openbankproject.commons.model.Product +import code.model.dataAccess.ResourceUser import code.users.Users import code.util.Helper import com.openbankproject.commons.model._ -import com.openbankproject.commons.util.{ReflectUtils, RequiredFieldValidation, RequiredFields} +import com.openbankproject.commons.util.{ReflectUtils, RequiredFields} import net.liftweb.common.{Box, Full} import net.liftweb.json.Extraction.decompose import net.liftweb.json.JsonAST.JValue -import scala.collection.immutable.List +import java.util.Date case class ViewsJSONV220( @@ -395,66 +391,66 @@ object JSONFactory220 { is_public = view.isPublic, alias = alias, hide_metadata_if_alias_used = view.hideOtherAccountMetadataIfAlias, - can_add_comment = view.canAddComment, - can_add_corporate_location = view.canAddCorporateLocation, - can_add_image = view.canAddImage, - can_add_image_url = view.canAddImageURL, - can_add_more_info = view.canAddMoreInfo, - can_add_open_corporates_url = view.canAddOpenCorporatesUrl, - can_add_physical_location = view.canAddPhysicalLocation, - can_add_private_alias = view.canAddPrivateAlias, - can_add_public_alias = view.canAddPublicAlias, - can_add_tag = view.canAddTag, - can_add_url = view.canAddURL, - can_add_where_tag = view.canAddWhereTag, - can_add_counterparty = view.canAddCounterparty, - can_delete_comment = view.canDeleteComment, - can_delete_corporate_location = view.canDeleteCorporateLocation, - can_delete_image = view.canDeleteImage, - can_delete_physical_location = view.canDeletePhysicalLocation, - can_delete_tag = view.canDeleteTag, - can_delete_where_tag = view.canDeleteWhereTag, - can_edit_owner_comment = view.canEditOwnerComment, - can_see_bank_account_balance = view.canSeeBankAccountBalance, - can_see_bank_account_bank_name = view.canSeeBankAccountBankName, - can_see_bank_account_currency = view.canSeeBankAccountCurrency, - can_see_bank_account_iban = view.canSeeBankAccountIban, - can_see_bank_account_label = view.canSeeBankAccountLabel, - can_see_bank_account_national_identifier = view.canSeeBankAccountNationalIdentifier, - can_see_bank_account_number = view.canSeeBankAccountNumber, - can_see_bank_account_owners = view.canSeeBankAccountOwners, - can_see_bank_account_swift_bic = view.canSeeBankAccountSwift_bic, - can_see_bank_account_type = view.canSeeBankAccountType, - can_see_comments = view.canSeeComments, - can_see_corporate_location = view.canSeeCorporateLocation, - can_see_image_url = view.canSeeImageUrl, - can_see_images = view.canSeeImages, - can_see_more_info = view.canSeeMoreInfo, - can_see_open_corporates_url = view.canSeeOpenCorporatesUrl, - can_see_other_account_bank_name = view.canSeeOtherAccountBankName, - can_see_other_account_iban = view.canSeeOtherAccountIBAN, - can_see_other_account_kind = view.canSeeOtherAccountKind, - can_see_other_account_metadata = view.canSeeOtherAccountMetadata, - can_see_other_account_national_identifier = view.canSeeOtherAccountNationalIdentifier, - can_see_other_account_number = view.canSeeOtherAccountNumber, - can_see_other_account_swift_bic = view.canSeeOtherAccountSWIFT_BIC, - can_see_owner_comment = view.canSeeOwnerComment, - can_see_physical_location = view.canSeePhysicalLocation, - can_see_private_alias = view.canSeePrivateAlias, - can_see_public_alias = view.canSeePublicAlias, - can_see_tags = view.canSeeTags, - can_see_transaction_amount = view.canSeeTransactionAmount, - can_see_transaction_balance = view.canSeeTransactionBalance, - can_see_transaction_currency = view.canSeeTransactionCurrency, - can_see_transaction_description = view.canSeeTransactionDescription, - can_see_transaction_finish_date = view.canSeeTransactionFinishDate, - can_see_transaction_metadata = view.canSeeTransactionMetadata, - can_see_transaction_other_bank_account = view.canSeeTransactionOtherBankAccount, - can_see_transaction_start_date = view.canSeeTransactionStartDate, - can_see_transaction_this_bank_account = view.canSeeTransactionThisBankAccount, - can_see_transaction_type = view.canSeeTransactionType, - can_see_url = view.canSeeUrl, - can_see_where_tag = view.canSeeWhereTag + can_add_comment = view.allowed_actions.exists(_ == CAN_ADD_COMMENT), + can_add_corporate_location = view.allowed_actions.exists(_ == CAN_ADD_CORPORATE_LOCATION), + can_add_image = view.allowed_actions.exists(_ == CAN_ADD_IMAGE), + can_add_image_url = view.allowed_actions.exists(_ == CAN_ADD_IMAGE_URL), + can_add_more_info = view.allowed_actions.exists(_ == CAN_ADD_MORE_INFO), + can_add_open_corporates_url = view.allowed_actions.exists(_ == CAN_ADD_OPEN_CORPORATES_URL), + can_add_physical_location = view.allowed_actions.exists(_ == CAN_ADD_PHYSICAL_LOCATION), + can_add_private_alias = view.allowed_actions.exists(_ == CAN_ADD_PRIVATE_ALIAS), + can_add_public_alias = view.allowed_actions.exists(_ == CAN_ADD_PUBLIC_ALIAS), + can_add_tag = view.allowed_actions.exists(_ == CAN_ADD_TAG), + can_add_url = view.allowed_actions.exists(_ == CAN_ADD_URL), + can_add_where_tag = view.allowed_actions.exists(_ == CAN_ADD_WHERE_TAG), + can_add_counterparty = view.allowed_actions.exists(_ == CAN_ADD_COUNTERPARTY), + can_delete_comment = view.allowed_actions.exists(_ == CAN_DELETE_COMMENT), + can_delete_corporate_location = view.allowed_actions.exists(_ == CAN_DELETE_CORPORATE_LOCATION), + can_delete_image = view.allowed_actions.exists(_ == CAN_DELETE_IMAGE), + can_delete_physical_location = view.allowed_actions.exists(_ == CAN_DELETE_PHYSICAL_LOCATION), + can_delete_tag = view.allowed_actions.exists(_ == CAN_DELETE_TAG), + can_delete_where_tag = view.allowed_actions.exists(_ == CAN_DELETE_WHERE_TAG), + can_edit_owner_comment = view.allowed_actions.exists(_ == CAN_EDIT_OWNER_COMMENT), + can_see_bank_account_balance = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_BALANCE), + can_see_bank_account_bank_name = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_BANK_NAME), + can_see_bank_account_currency = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_CURRENCY), + can_see_bank_account_iban = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_IBAN), + can_see_bank_account_label = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_LABEL), + can_see_bank_account_national_identifier = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_NATIONAL_IDENTIFIER), + can_see_bank_account_number = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_NUMBER), + can_see_bank_account_owners = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_OWNERS), + can_see_bank_account_swift_bic = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_SWIFT_BIC), + can_see_bank_account_type = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_TYPE), + can_see_comments = view.allowed_actions.exists(_ == CAN_SEE_COMMENTS), + can_see_corporate_location = view.allowed_actions.exists(_ == CAN_SEE_CORPORATE_LOCATION), + can_see_image_url = view.allowed_actions.exists(_ == CAN_SEE_IMAGE_URL), + can_see_images = view.allowed_actions.exists(_ == CAN_SEE_IMAGES), + can_see_more_info = view.allowed_actions.exists(_ == CAN_SEE_MORE_INFO), + can_see_open_corporates_url = view.allowed_actions.exists(_ == CAN_SEE_OPEN_CORPORATES_URL), + can_see_other_account_bank_name = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_BANK_NAME), + can_see_other_account_iban = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_IBAN), + can_see_other_account_kind = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_KIND), + can_see_other_account_metadata = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_METADATA), + can_see_other_account_national_identifier = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_NATIONAL_IDENTIFIER), + can_see_other_account_number = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_NUMBER), + can_see_other_account_swift_bic = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_SWIFT_BIC), + can_see_owner_comment = view.allowed_actions.exists(_ == CAN_SEE_OWNER_COMMENT), + can_see_physical_location = view.allowed_actions.exists(_ == CAN_SEE_PHYSICAL_LOCATION), + can_see_private_alias = view.allowed_actions.exists(_ == CAN_SEE_PRIVATE_ALIAS), + can_see_public_alias = view.allowed_actions.exists(_ == CAN_SEE_PUBLIC_ALIAS), + can_see_tags = view.allowed_actions.exists(_ == CAN_SEE_TAGS), + can_see_transaction_amount = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_AMOUNT), + can_see_transaction_balance = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_BALANCE), + can_see_transaction_currency = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_CURRENCY), + can_see_transaction_description = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_DESCRIPTION), + can_see_transaction_finish_date = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_FINISH_DATE), + can_see_transaction_metadata = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_METADATA), + can_see_transaction_other_bank_account = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_OTHER_BANK_ACCOUNT), + can_see_transaction_start_date = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_START_DATE), + can_see_transaction_this_bank_account = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_THIS_BANK_ACCOUNT), + can_see_transaction_type = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_TYPE), + can_see_url = view.allowed_actions.exists(_ == CAN_SEE_URL), + can_see_where_tag = view.allowed_actions.exists(_ == CAN_SEE_WHERE_TAG) ) } 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 d774b2f93..c75b91a52 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,7 +1,7 @@ package code.api.v3_0_0 import code.accountattribute.AccountAttributeX -import code.api.Constant.{PARAM_LOCALE, PARAM_TIMESTAMP} +import code.api.Constant._ import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON.{banksJSON, branchJsonV300, _} import code.api.util.APIUtil.{getGlossaryItems, _} @@ -28,7 +28,6 @@ import code.users.Users import code.util.Helper import code.util.Helper.{ObpS, booleanToFuture} import code.views.Views -import code.views.system.ViewDefinition import com.github.dwickern.macros.NameOf.nameOf import com.grum.geocalc.{Coordinate, EarthCalc, Point} import com.openbankproject.commons.ExecutionContext.Implicits.global @@ -141,9 +140,9 @@ trait APIMethods300 { (Full(u), callContext) <- authenticatedAccess(cc) (bankAccount, callContext) <- NewStyle.function.getBankAccount(bankId, accountId, callContext) permission <- NewStyle.function.permission(bankId, accountId, u, callContext) - anyViewContainsCanSeeAvailableViewsForBankAccountPermission = permission.views.map(_.canSeeAvailableViewsForBankAccount).find(_.==(true)).getOrElse(false) + anyViewContainsCanSeeAvailableViewsForBankAccountPermission = permission.views.map(_.allowed_actions.exists(_ == CAN_SEE_AVAILABLE_VIEWS_FOR_BANK_ACCOUNT)).find(_.==(true)).getOrElse(false) _ <- Helper.booleanToFuture( - s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canSeeAvailableViewsForBankAccount_)).dropRight(1)}` permission on any your views", + s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_SEE_AVAILABLE_VIEWS_FOR_BANK_ACCOUNT)}` permission on any your views", cc = callContext ) { anyViewContainsCanSeeAvailableViewsForBankAccountPermission @@ -211,10 +210,10 @@ trait APIMethods300 { (account, callContext) <- NewStyle.function.getBankAccount(bankId, accountId, callContext) anyViewContainsCanCreateCustomViewPermission = Views.views.vend.permission(BankIdAccountId(account.bankId, account.accountId), u) - .map(_.views.map(_.canCreateCustomView).find(_.==(true)).getOrElse(false)).getOrElse(false) + .map(_.views.map(_.allowed_actions.exists(_ == CAN_CREATE_CUSTOM_VIEW)).find(_.==(true)).getOrElse(false)).getOrElse(false) _ <- Helper.booleanToFuture( - s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canCreateCustomView_)).dropRight(1)}` permission on any your views", + s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_CREATE_CUSTOM_VIEW)}` permission on any your views", cc = callContext ) {anyViewContainsCanCreateCustomViewPermission} (view, callContext) <- NewStyle.function.createCustomView(BankIdAccountId(bankId, accountId), createViewJson, callContext) @@ -251,9 +250,9 @@ trait APIMethods300 { (_, callContext) <- NewStyle.function.getBank(bankId, callContext) (account, callContext) <- NewStyle.function.checkBankAccountExists(bankId, accountId, callContext) anyViewContainsCanSeePermissionForOneUserPermission = Views.views.vend.permission(BankIdAccountId(account.bankId, account.accountId), loggedInUser) - .map(_.views.map(_.canSeeViewsWithPermissionsForOneUser).find(_.==(true)).getOrElse(false)).getOrElse(false) + .map(_.views.map(_.allowed_actions.exists(_ == CAN_SEE_VIEWS_WITH_PERMISSIONS_FOR_ONE_USER)).find(_.==(true)).getOrElse(false)).getOrElse(false) _ <- Helper.booleanToFuture( - s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canSeeViewsWithPermissionsForOneUser_)).dropRight(1)}` permission on any your views", + s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_SEE_VIEWS_WITH_PERMISSIONS_FOR_ONE_USER)}` permission on any your views", cc = callContext ) { anyViewContainsCanSeePermissionForOneUserPermission @@ -317,10 +316,10 @@ trait APIMethods300 { (account, callContext) <- NewStyle.function.getBankAccount(bankId, accountId, callContext) anyViewContainsCancanUpdateCustomViewPermission = Views.views.vend.permission(BankIdAccountId(account.bankId, account.accountId), u) - .map(_.views.map(_.canUpdateCustomView).find(_.==(true)).getOrElse(false)).getOrElse(false) + .map(_.views.map(_.allowed_actions.exists(_ == CAN_UPDATE_CUSTOM_VIEW)).find(_.==(true)).getOrElse(false)).getOrElse(false) _ <- Helper.booleanToFuture( - s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canUpdateCustomView_)).dropRight(1)}` permission on any your views", + s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_UPDATE_CUSTOM_VIEW)}` permission on any your views", cc = callContext ) { anyViewContainsCancanUpdateCustomViewPermission diff --git a/obp-api/src/main/scala/code/api/v3_0_0/JSONFactory3.0.0.scala b/obp-api/src/main/scala/code/api/v3_0_0/JSONFactory3.0.0.scala index 5a5319d99..90360ec62 100644 --- a/obp-api/src/main/scala/code/api/v3_0_0/JSONFactory3.0.0.scala +++ b/obp-api/src/main/scala/code/api/v3_0_0/JSONFactory3.0.0.scala @@ -26,14 +26,12 @@ Berlin 13359, Germany */ package code.api.v3_0_0 -import java.lang -import java.util.Date - +import code.api.Constant._ import code.api.util.APIUtil._ import code.api.util.Glossary.GlossaryItem import code.api.util.{APIUtil, PegdownOptions} import code.api.v1_2_1.JSONFactory._ -import code.api.v1_2_1.{UserJSONV121, _} +import code.api.v1_2_1._ import code.api.v1_4_0.JSONFactory1_4_0._ import code.api.v2_0_0.EntitlementJSONs import code.api.v2_0_0.JSONFactory200.{UserJsonV200, UsersJsonV200} @@ -51,10 +49,11 @@ import code.model.dataAccess.ResourceUser import code.scope.Scope import code.views.Views import com.openbankproject.commons.dto.CustomerAndAttribute -import com.openbankproject.commons.model.{Customer, _} +import com.openbankproject.commons.model._ import net.liftweb.common.{Box, Full} -import scala.collection.immutable.List +import java.lang +import java.util.Date //import code.api.v1_4_0.JSONFactory1_4_0._ import code.api.v2_0_0.JSONFactory200 @@ -740,81 +739,81 @@ object JSONFactory300{ is_system = view.isSystem, alias = alias, hide_metadata_if_alias_used = view.hideOtherAccountMetadataIfAlias, - can_add_comment = view.canAddComment, - can_add_corporate_location = view.canAddCorporateLocation, - can_add_image = view.canAddImage, - can_add_image_url = view.canAddImageURL, - can_add_more_info = view.canAddMoreInfo, - can_add_open_corporates_url = view.canAddOpenCorporatesUrl, - can_add_physical_location = view.canAddPhysicalLocation, - can_add_private_alias = view.canAddPrivateAlias, - can_add_public_alias = view.canAddPublicAlias, - can_add_tag = view.canAddTag, - can_add_url = view.canAddURL, - can_add_where_tag = view.canAddWhereTag, - can_delete_comment = view.canDeleteComment, - can_add_counterparty = view.canAddCounterparty, - can_delete_corporate_location = view.canDeleteCorporateLocation, - can_delete_image = view.canDeleteImage, - can_delete_physical_location = view.canDeletePhysicalLocation, - can_delete_tag = view.canDeleteTag, - can_delete_where_tag = view.canDeleteWhereTag, - can_edit_owner_comment = view.canEditOwnerComment, - can_see_bank_account_balance = view.canSeeBankAccountBalance, - can_query_available_funds = view.canQueryAvailableFunds, - can_see_bank_account_bank_name = view.canSeeBankAccountBankName, - can_see_bank_account_currency = view.canSeeBankAccountCurrency, - can_see_bank_account_iban = view.canSeeBankAccountIban, - can_see_bank_account_label = view.canSeeBankAccountLabel, - can_see_bank_account_national_identifier = view.canSeeBankAccountNationalIdentifier, - can_see_bank_account_number = view.canSeeBankAccountNumber, - can_see_bank_account_owners = view.canSeeBankAccountOwners, - can_see_bank_account_swift_bic = view.canSeeBankAccountSwift_bic, - can_see_bank_account_type = view.canSeeBankAccountType, - can_see_comments = view.canSeeComments, - can_see_corporate_location = view.canSeeCorporateLocation, - can_see_image_url = view.canSeeImageUrl, - can_see_images = view.canSeeImages, - can_see_more_info = view.canSeeMoreInfo, - can_see_open_corporates_url = view.canSeeOpenCorporatesUrl, - can_see_other_account_bank_name = view.canSeeOtherAccountBankName, - can_see_other_account_iban = view.canSeeOtherAccountIBAN, - can_see_other_account_kind = view.canSeeOtherAccountKind, - can_see_other_account_metadata = view.canSeeOtherAccountMetadata, - can_see_other_account_national_identifier = view.canSeeOtherAccountNationalIdentifier, - can_see_other_account_number = view.canSeeOtherAccountNumber, - can_see_other_account_swift_bic = view.canSeeOtherAccountSWIFT_BIC, - can_see_owner_comment = view.canSeeOwnerComment, - can_see_physical_location = view.canSeePhysicalLocation, - can_see_private_alias = view.canSeePrivateAlias, - can_see_public_alias = view.canSeePublicAlias, - can_see_tags = view.canSeeTags, - can_see_transaction_amount = view.canSeeTransactionAmount, - can_see_transaction_balance = view.canSeeTransactionBalance, - can_see_transaction_currency = view.canSeeTransactionCurrency, - can_see_transaction_description = view.canSeeTransactionDescription, - can_see_transaction_finish_date = view.canSeeTransactionFinishDate, - can_see_transaction_metadata = view.canSeeTransactionMetadata, - can_see_transaction_other_bank_account = view.canSeeTransactionOtherBankAccount, - can_see_transaction_start_date = view.canSeeTransactionStartDate, - can_see_transaction_this_bank_account = view.canSeeTransactionThisBankAccount, - can_see_transaction_type = view.canSeeTransactionType, - can_see_url = view.canSeeUrl, - can_see_where_tag = view.canSeeWhereTag, + can_add_comment = view.allowed_actions.exists(_ == CAN_ADD_COMMENT), + can_add_corporate_location = view.allowed_actions.exists(_ == CAN_ADD_CORPORATE_LOCATION), + can_add_image = view.allowed_actions.exists(_ == CAN_ADD_IMAGE), + can_add_image_url = view.allowed_actions.exists(_ == CAN_ADD_IMAGE_URL), + can_add_more_info = view.allowed_actions.exists(_ == CAN_ADD_MORE_INFO), + can_add_open_corporates_url = view.allowed_actions.exists(_ == CAN_ADD_OPEN_CORPORATES_URL), + can_add_physical_location = view.allowed_actions.exists(_ == CAN_ADD_PHYSICAL_LOCATION), + can_add_private_alias = view.allowed_actions.exists(_ == CAN_ADD_PRIVATE_ALIAS), + can_add_public_alias = view.allowed_actions.exists(_ == CAN_ADD_PUBLIC_ALIAS), + can_add_tag = view.allowed_actions.exists(_ == CAN_ADD_TAG), + can_add_url = view.allowed_actions.exists(_ == CAN_ADD_URL), + can_add_where_tag = view.allowed_actions.exists(_ == CAN_ADD_WHERE_TAG), + can_delete_comment = view.allowed_actions.exists(_ == CAN_DELETE_COMMENT), + can_add_counterparty = view.allowed_actions.exists(_ == CAN_ADD_COUNTERPARTY), + can_delete_corporate_location = view.allowed_actions.exists(_ == CAN_DELETE_CORPORATE_LOCATION), + can_delete_image = view.allowed_actions.exists(_ == CAN_DELETE_IMAGE), + can_delete_physical_location = view.allowed_actions.exists(_ == CAN_DELETE_PHYSICAL_LOCATION), + can_delete_tag = view.allowed_actions.exists(_ == CAN_DELETE_TAG), + can_delete_where_tag = view.allowed_actions.exists(_ == CAN_DELETE_WHERE_TAG), + can_edit_owner_comment = view.allowed_actions.exists(_ == CAN_EDIT_OWNER_COMMENT), + can_see_bank_account_balance = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_BALANCE), + can_query_available_funds = view.allowed_actions.exists(_ == CAN_QUERY_AVAILABLE_FUNDS), + can_see_bank_account_bank_name = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_BANK_NAME), + can_see_bank_account_currency = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_CURRENCY), + can_see_bank_account_iban = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_IBAN), + can_see_bank_account_label = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_LABEL), + can_see_bank_account_national_identifier = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_NATIONAL_IDENTIFIER), + can_see_bank_account_number = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_NUMBER), + can_see_bank_account_owners = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_OWNERS), + can_see_bank_account_swift_bic = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_SWIFT_BIC), + can_see_bank_account_type = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_TYPE), + can_see_comments = view.allowed_actions.exists(_ == CAN_SEE_COMMENTS), + can_see_corporate_location = view.allowed_actions.exists(_ == CAN_SEE_CORPORATE_LOCATION), + can_see_image_url = view.allowed_actions.exists(_ == CAN_SEE_IMAGE_URL), + can_see_images = view.allowed_actions.exists(_ == CAN_SEE_IMAGES), + can_see_more_info = view.allowed_actions.exists(_ == CAN_SEE_MORE_INFO), + can_see_open_corporates_url = view.allowed_actions.exists(_ == CAN_SEE_OPEN_CORPORATES_URL), + can_see_other_account_bank_name = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_BANK_NAME), + can_see_other_account_iban = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_IBAN), + can_see_other_account_kind = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_KIND), + can_see_other_account_metadata = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_METADATA), + can_see_other_account_national_identifier = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_NATIONAL_IDENTIFIER), + can_see_other_account_number = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_NUMBER), + can_see_other_account_swift_bic = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_SWIFT_BIC), + can_see_owner_comment = view.allowed_actions.exists(_ == CAN_SEE_OWNER_COMMENT), + can_see_physical_location = view.allowed_actions.exists(_ == CAN_SEE_PHYSICAL_LOCATION), + can_see_private_alias = view.allowed_actions.exists(_ == CAN_SEE_PRIVATE_ALIAS), + can_see_public_alias = view.allowed_actions.exists(_ == CAN_SEE_PUBLIC_ALIAS), + can_see_tags = view.allowed_actions.exists(_ == CAN_SEE_TAGS), + can_see_transaction_amount = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_AMOUNT), + can_see_transaction_balance = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_BALANCE), + can_see_transaction_currency = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_CURRENCY), + can_see_transaction_description = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_DESCRIPTION), + can_see_transaction_finish_date = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_FINISH_DATE), + can_see_transaction_metadata = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_METADATA), + can_see_transaction_other_bank_account = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_OTHER_BANK_ACCOUNT), + can_see_transaction_start_date = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_START_DATE), + can_see_transaction_this_bank_account = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_THIS_BANK_ACCOUNT), + can_see_transaction_type = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_TYPE), + can_see_url = view.allowed_actions.exists(_ == CAN_SEE_URL), + can_see_where_tag = view.allowed_actions.exists(_ == CAN_SEE_WHERE_TAG), //V300 new - can_see_bank_routing_scheme = view.canSeeBankRoutingScheme, - can_see_bank_routing_address = view.canSeeBankRoutingAddress, - can_see_bank_account_routing_scheme = view.canSeeBankAccountRoutingScheme, - can_see_bank_account_routing_address = view.canSeeBankAccountRoutingAddress, - can_see_other_bank_routing_scheme = view.canSeeOtherBankRoutingScheme, - can_see_other_bank_routing_address = view.canSeeOtherBankRoutingAddress, - can_see_other_account_routing_scheme = view.canSeeOtherAccountRoutingScheme, - can_see_other_account_routing_address= view.canSeeOtherAccountRoutingAddress, - can_add_transaction_request_to_own_account = view.canAddTransactionRequestToOwnAccount, //added following two for payments - can_add_transaction_request_to_any_account = view.canAddTransactionRequestToAnyAccount, - can_see_bank_account_credit_limit = view.canSeeBankAccountCreditLimit, - can_create_direct_debit = view.canCreateDirectDebit, - can_create_standing_order = view.canCreateStandingOrder + can_see_bank_routing_scheme = view.allowed_actions.exists(_ == CAN_SEE_BANK_ROUTING_SCHEME), + can_see_bank_routing_address = view.allowed_actions.exists(_ == CAN_SEE_BANK_ROUTING_ADDRESS), + can_see_bank_account_routing_scheme = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_ROUTING_SCHEME), + can_see_bank_account_routing_address = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_ROUTING_ADDRESS), + can_see_other_bank_routing_scheme = view.allowed_actions.exists(_ == CAN_SEE_OTHER_BANK_ROUTING_SCHEME), + can_see_other_bank_routing_address = view.allowed_actions.exists(_ == CAN_SEE_OTHER_BANK_ROUTING_ADDRESS), + can_see_other_account_routing_scheme = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_ROUTING_SCHEME), + can_see_other_account_routing_address= view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_ROUTING_ADDRESS), + can_add_transaction_request_to_own_account = view.allowed_actions.exists(_ == CAN_ADD_TRANSACTION_REQUEST_TO_OWN_ACCOUNT), //added following two for payments + can_add_transaction_request_to_any_account = view.allowed_actions.exists(_ == CAN_ADD_TRANSACTION_REQUEST_TO_ANY_ACCOUNT), + can_see_bank_account_credit_limit = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_CREDIT_LIMIT), + can_create_direct_debit = view.allowed_actions.exists(_ == CAN_CREATE_DIRECT_DEBIT), + can_create_standing_order = view.allowed_actions.exists(_ == CAN_CREATE_STANDING_ORDER) ) } def createBasicViewJSON(view : View) : BasicViewJson = { diff --git a/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala b/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala index 80692cf30..fc3483af0 100644 --- a/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala +++ b/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala @@ -1,7 +1,7 @@ package code.api.v3_1_0 import code.api.Constant -import code.api.Constant.localIdentityProvider +import code.api.Constant._ import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON._ import code.api.ResourceDocs1_4_0.{MessageDocsSwaggerDefinitions, ResourceDocsAPIMethodsUtil, SwaggerDefinitionsJSON, SwaggerJSONFactory} import code.api.cache.Caching @@ -37,7 +37,6 @@ import code.users.Users import code.util.Helper import code.util.Helper.ObpS import code.views.Views -import code.views.system.ViewDefinition import code.webhook.AccountWebhook import code.webuiprops.{MappedWebUiPropsProvider, WebUiPropsCommons} import com.github.dwickern.macros.NameOf.nameOf @@ -654,8 +653,8 @@ trait APIMethods310 { (_, callContext) <- NewStyle.function.getBank(bankId, callContext) (account, callContext) <- NewStyle.function.checkBankAccountExists(bankId, accountId, callContext) view <- NewStyle.function.checkViewAccessAndReturnView(viewId, BankIdAccountId(bankId, accountId), Some(u), callContext) - _ <- Helper.booleanToFuture(failMsg = s"$ViewDoesNotPermitAccess + You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canQueryAvailableFunds_)).dropRight(1)}` permission on any your views", cc=callContext) { - view.canQueryAvailableFunds + _ <- Helper.booleanToFuture(failMsg = s"$ViewDoesNotPermitAccess + You need the `${StringHelpers.snakify(CAN_QUERY_AVAILABLE_FUNDS)}` permission on any your views", cc=callContext) { + view.allowed_actions.exists(_ ==CAN_QUERY_AVAILABLE_FUNDS) } httpParams: List[HTTPParam] <- NewStyle.function.extractHttpParamsFromUrl(cc.url) _ <- Helper.booleanToFuture(failMsg = MissingQueryParams + amount, cc=callContext) { @@ -672,7 +671,7 @@ trait APIMethods310 { _ <- NewStyle.function.moderatedBankAccountCore(account, view, Full(u), callContext) } yield { val ccy = httpParams.filter(_.name == currency).map(_.values.head).head - val fundsAvailable = (view.canQueryAvailableFunds, account.balance, account.currency) match { + val fundsAvailable = ( view.allowed_actions.exists(_ ==CAN_QUERY_AVAILABLE_FUNDS), account.balance, account.currency) match { case (false, _, _) => "" // 1st condition: MUST have a view can_query_available_funds case (true, _, c) if c != ccy => "no" // 2nd condition: Currency has to be matched case (true, b, _) if b.compare(available) >= 0 => "yes" // We have the vew, the right currency and enough funds @@ -1125,9 +1124,9 @@ trait APIMethods310 { (fromAccount, callContext) <- NewStyle.function.checkBankAccountExists(bankId, accountId, callContext) view <- NewStyle.function.checkAccountAccessAndGetView(viewId, BankIdAccountId(bankId, accountId), Full(u), callContext) _ <- Helper.booleanToFuture( - s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canSeeTransactionRequests_)).dropRight(1)}` permission on the View(${viewId.value})", + s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_SEE_TRANSACTION_REQUESTS)}` permission on the View(${viewId.value})", cc=callContext){ - view.canSeeTransactionRequests + view.allowed_actions.exists(_ ==CAN_SEE_TRANSACTION_REQUESTS) } (transactionRequests, callContext) <- Future(Connector.connector.vend.getTransactionRequests210(u, fromAccount, callContext)) map { unboxFullOrFail(_, callContext, GetTransactionRequestsException) @@ -1870,7 +1869,7 @@ trait APIMethods310 { cc => implicit val ec = EndpointContext(Some(cc)) for { (_, callContext) <- anonymousAccess(cc) - connectorVersion = code.api.Constant.Connector.openOrThrowException(s"$MandatoryPropertyIsNotSet The missing props is 'connector'") + connectorVersion = code.api.Constant.CONNECTOR.openOrThrowException(s"$MandatoryPropertyIsNotSet The missing props is 'connector'") starConnectorProps = APIUtil.getPropsValue("starConnector_supported_types").openOr("notfound") //TODO we need to decide what kind of connector should we use. obpApiLoopback = ObpApiLoopback( 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 d14433bd5..a4b499940 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 @@ -1,35 +1,30 @@ package code.api.v4_0_0 -import java.net.URLEncoder -import java.text.SimpleDateFormat -import java.util -import java.util.{Calendar, Date} -import code.DynamicData.{DynamicData, DynamicDataProvider} +import code.DynamicData.DynamicData import code.DynamicEndpoint.DynamicEndpointSwagger import code.accountattribute.AccountAttributeX -import code.api.Constant.{CREATE_LOCALISED_RESOURCE_DOC_JSON_TTL, PARAM_LOCALE, PARAM_TIMESTAMP, SYSTEM_OWNER_VIEW_ID, localIdentityProvider} +import code.api.Constant._ import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON.{jsonDynamicResourceDoc, _} -import code.api.UKOpenBanking.v2_0_0.OBP_UKOpenBanking_200 -import code.api.UKOpenBanking.v3_1_0.OBP_UKOpenBanking_310 -import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON._ import code.api.dynamic.endpoint.helper.practise.{DynamicEndpointCodeGenerator, PractiseEndpoint} -import code.api.dynamic.endpoint.helper.{CompiledObjects, DynamicEndpointHelper, DynamicEndpoints} +import code.api.dynamic.endpoint.helper.{CompiledObjects, DynamicEndpointHelper} +import code.api.dynamic.entity.helper.DynamicEntityInfo import code.api.util.APIUtil.{fullBoxOrException, _} import code.api.util.ApiRole._ import code.api.util.ApiTag._ import code.api.util.DynamicUtil.Validation import code.api.util.ErrorMessages.{BankNotFound, _} import code.api.util.ExampleValue._ -import code.api.util.Glossary.{getGlossaryItem, getGlossaryItemSimple} +import code.api.util.FutureUtil.EndpointContext +import code.api.util.Glossary.getGlossaryItem import code.api.util.NewStyle.HttpCode -import code.api.util.NewStyle.function.{isValidCurrencyISOCode => isValidCurrencyISOCodeNS, _} +import code.api.util.NewStyle.function._ import code.api.util._ import code.api.util.migration.Migration import code.api.util.newstyle.AttributeDefinition._ import code.api.util.newstyle.Consumer._ -import code.api.util.newstyle.{BalanceNewStyle, UserCustomerLinkNewStyle} import code.api.util.newstyle.UserCustomerLinkNewStyle.getUserCustomerLinks +import code.api.util.newstyle.{BalanceNewStyle, UserCustomerLinkNewStyle} import code.api.v1_2_1.{JSONFactory, PostTransactionTagJSON} import code.api.v1_4_0.JSONFactory1_4_0 import code.api.v1_4_0.JSONFactory1_4_0.TransactionRequestAccountJsonV140 @@ -38,21 +33,15 @@ import code.api.v2_0_0.{CreateEntitlementJSON, CreateUserCustomerLinkJson, Entit import code.api.v2_1_0._ import code.api.v3_0_0.{CreateScopeJson, JSONFactory300} import code.api.v3_1_0._ +import code.api.v4_0_0.APIMethods400.{createTransactionRequest, transactionRequestGeneralText} import code.api.v4_0_0.JSONFactory400._ -import code.fx.{MappedFXRate, fx} -import code.api.dynamic.endpoint.helper._ -import code.api.dynamic.endpoint.helper.practise.PractiseEndpoint -import code.api.dynamic.entity.helper.{DynamicEntityHelper, DynamicEntityInfo} -import code.api.util.FutureUtil.EndpointContext -import code.api.v4_0_0.APIMethods400.{createTransactionRequest, lowAmount, sharedChargePolicy, transactionRequestGeneralText} -import code.api.v4_0_0.TransactionRequestBodyAgentJsonV400 import code.api.{ChargePolicy, Constant, JsonResponseException} import code.apicollection.MappedApiCollectionsProvider import code.apicollectionendpoint.MappedApiCollectionEndpointsProvider import code.authtypevalidation.JsonAuthTypeValidation import code.bankconnectors.{Connector, DynamicConnector, InternalConnector} import code.connectormethod.{JsonConnectorMethod, JsonConnectorMethodMethodBody} -import code.consent.{ConsentRequests, ConsentStatus, Consents} +import code.consent.{ConsentStatus, Consents} import code.dynamicEntity.{DynamicEntityCommons, ReferenceType} import code.dynamicMessageDoc.JsonDynamicMessageDoc import code.dynamicResourceDoc.JsonDynamicResourceDoc @@ -62,13 +51,11 @@ import code.fx.fx import code.loginattempts.LoginAttempt import code.metadata.counterparties.{Counterparties, MappedCounterparty} import code.metadata.tags.Tags -import code.model.dataAccess.{AuthUser, BankAccountCreation} import code.model._ +import code.model.dataAccess.{AuthUser, BankAccountCreation} import code.ratelimiting.RateLimitingDI import code.scope.Scope import code.snippet.{WebUIPlaceholder, WebUITemplate} -import code.transactionChallenge.MappedExpectedChallengeAnswer -import code.transactionrequests.MappedTransactionRequestProvider import code.usercustomerlinks.UserCustomerLink import code.userlocks.UserLocksProvider import code.users.Users @@ -76,41 +63,39 @@ import code.util.Helper.{MdcLoggable, ObpS, SILENCE_IS_GOLDEN, booleanToFuture} import code.util.{Helper, JsonSchemaUtil} import code.validation.JsonValidation import code.views.Views -import code.views.system.ViewDefinition -import code.webhook.{AccountWebhook, BankAccountNotificationWebhookTrait, SystemAccountNotificationWebhookTrait} +import code.webhook.{BankAccountNotificationWebhookTrait, SystemAccountNotificationWebhookTrait} import code.webuiprops.MappedWebUiPropsProvider.getWebUiPropsValue import com.github.dwickern.macros.NameOf.nameOf import com.networknt.schema.ValidationMessage import com.openbankproject.commons.ExecutionContext.Implicits.global import com.openbankproject.commons.dto.GetProductsParam +import com.openbankproject.commons.model._ import com.openbankproject.commons.model.enums.ChallengeType.OBP_TRANSACTION_REQUEST_CHALLENGE import com.openbankproject.commons.model.enums.DynamicEntityOperation._ -import com.openbankproject.commons.model.enums.{TransactionRequestStatus, _} -import com.openbankproject.commons.model._ import com.openbankproject.commons.model.enums.TransactionRequestTypes._ -import com.openbankproject.commons.model.enums.PaymentServiceTypes._ -import com.openbankproject.commons.util.{ApiVersion, JsonUtils, ScannedApiVersion} +import com.openbankproject.commons.model.enums.{TransactionRequestStatus, _} +import com.openbankproject.commons.util.{ApiVersion, ScannedApiVersion} import deletion._ import net.liftweb.common._ import net.liftweb.http.rest.RestHelper -import net.liftweb.http.{JsonResponse, Req, S} import net.liftweb.json.JsonAST.JValue import net.liftweb.json.JsonDSL._ import net.liftweb.json.Serialization.write import net.liftweb.json._ -import net.liftweb.mapper.By import net.liftweb.util.Helpers.{now, tryo} import net.liftweb.util.Mailer.{From, PlainMailBodyType, Subject, To, XHTMLMailBodyType} import net.liftweb.util.{Helpers, Mailer, StringHelpers} import org.apache.commons.lang3.StringUtils -import java.time.{LocalDate, ZoneId, ZonedDateTime} -import java.util.Date +import java.net.URLEncoder +import java.text.SimpleDateFormat +import java.time.{LocalDate, ZoneId} +import java.util +import java.util.{Calendar, Date} import scala.collection.immutable.{List, Nil} import scala.collection.mutable.ArrayBuffer import scala.concurrent.Future import scala.jdk.CollectionConverters.collectionAsScalaIterableConverter -import scala.math.BigDecimal import scala.xml.XML trait APIMethods400 extends MdcLoggable { @@ -2320,9 +2305,9 @@ trait APIMethods400 extends MdcLoggable { json.extract[UpdateAccountJsonV400] } anyViewContainsCanUpdateBankAccountLabelPermission = Views.views.vend.permission(BankIdAccountId(account.bankId, account.accountId), u) - .map(_.views.map(_.canUpdateBankAccountLabel).find(_.==(true)).getOrElse(false)).getOrElse(false) + .map(_.views.map(_.allowed_actions.exists(_ == CAN_UPDATE_BANK_ACCOUNT_LABEL)).find(_.==(true)).getOrElse(false)).getOrElse(false) _ <- Helper.booleanToFuture( - s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canUpdateBankAccountLabel_)).dropRight(1)}` permission on any your views", + s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_UPDATE_BANK_ACCOUNT_LABEL)}` permission on any your views", cc = callContext ) { anyViewContainsCanUpdateBankAccountLabelPermission @@ -2564,7 +2549,7 @@ trait APIMethods400 extends MdcLoggable { for { (user @Full(u), _, account, view, callContext) <- SS.userBankAccountView _ <- Helper.booleanToFuture(failMsg = s"$NoViewPermission can_add_tag. Current ViewId($viewId)", cc=callContext) { - view.canAddTag + view.allowed_actions.exists( _ == CAN_ADD_TAG) } tagJson <- NewStyle.function.tryons(s"$InvalidJsonFormat The Json body should be the $PostTransactionTagJSON ", 400, callContext) { json.extract[PostTransactionTagJSON] @@ -2608,7 +2593,7 @@ trait APIMethods400 extends MdcLoggable { for { (user @Full(u), _, account, view, callContext) <- SS.userBankAccountView _ <- Helper.booleanToFuture(failMsg = s"$NoViewPermission can_delete_tag. Current ViewId($viewId)", cc=callContext) { - view.canDeleteTag + view.allowed_actions.exists(_ ==CAN_DELETE_TAG) } deleted <- Future(Tags.tags.vend.deleteTagOnAccount(bankId, accountId)(tagId)) map { i => (connectorEmptyResponse(i, callContext), callContext) @@ -2650,7 +2635,7 @@ trait APIMethods400 extends MdcLoggable { for { (user @Full(u), _, account, view, callContext) <- SS.userBankAccountView _ <- Helper.booleanToFuture(failMsg = s"$NoViewPermission can_see_tags. Current ViewId($viewId)", cc=callContext) { - view.canSeeTags + view.allowed_actions.exists(_ ==CAN_SEE_TAGS) } tags <- Future(Tags.tags.vend.getTagsOnAccount(bankId, accountId)(viewId)) } yield { @@ -3688,7 +3673,7 @@ trait APIMethods400 extends MdcLoggable { for { (user @Full(u), _, account, view, callContext) <- SS.userBankAccountView _ <- Helper.booleanToFuture(failMsg = s"$NoViewPermission can_create_direct_debit. Current ViewId($viewId)", cc=callContext) { - view.canCreateDirectDebit + view.allowed_actions.exists(_ ==CAN_CREATE_DIRECT_DEBIT) } failMsg = s"$InvalidJsonFormat The Json body should be the $PostDirectDebitJsonV400 " postJson <- NewStyle.function.tryons(failMsg, 400, callContext) { @@ -3807,7 +3792,7 @@ trait APIMethods400 extends MdcLoggable { for { (user @Full(u), _, account, view, callContext) <- SS.userBankAccountView _ <- Helper.booleanToFuture(failMsg = s"$NoViewPermission can_create_standing_order. Current ViewId($viewId)", cc=callContext) { - view.canCreateStandingOrder + view.allowed_actions.exists(_ ==CAN_CREATE_STANDING_ORDER) } failMsg = s"$InvalidJsonFormat The Json body should be the $PostStandingOrderJsonV400 " postJson <- NewStyle.function.tryons(failMsg, 400, callContext) { @@ -4738,9 +4723,9 @@ trait APIMethods400 extends MdcLoggable { _ <- NewStyle.function.isEnabledTransactionRequests(callContext) view <- NewStyle.function.checkAccountAccessAndGetView(viewId, BankIdAccountId(bankId, accountId), Full(u), callContext) _ <- Helper.booleanToFuture( - s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canSeeTransactionRequests_)).dropRight(1)}` permission on the View(${viewId.value})", + s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_SEE_TRANSACTION_REQUESTS)}` permission on the View(${viewId.value})", cc = callContext) { - view.canSeeTransactionRequests + view.allowed_actions.exists(_ ==CAN_SEE_TRANSACTION_REQUESTS) } (transactionRequest, callContext) <- NewStyle.function.getTransactionRequestImpl(requestId, callContext) } yield { @@ -7500,7 +7485,7 @@ trait APIMethods400 extends MdcLoggable { } _ <- Helper.booleanToFuture(s"$NoViewPermission can_add_counterparty. Please use a view with that permission or add the permission to this view.", 403, cc=callContext) { - view.canAddCounterparty + view.allowed_actions.exists(_ ==CAN_ADD_COUNTERPARTY) } (counterparty, callContext) <- Connector.connector.vend.checkCounterpartyExists(postJson.name, bankId.value, accountId.value, viewId.value, callContext) @@ -7617,7 +7602,7 @@ trait APIMethods400 extends MdcLoggable { _ <- Helper.booleanToFuture(InvalidBankIdFormat, cc=callContext) {isValidID(bankId.value)} _ <- Helper.booleanToFuture(s"$NoViewPermission can_delete_counterparty. Please use a view with that permission or add the permission to this view.",403, cc=callContext) { - view.canDeleteCounterparty + view.allowed_actions.exists(_ ==CAN_DELETE_COUNTERPARTY) } (counterparty, callContext) <- NewStyle.function.deleteCounterpartyByCounterpartyId(counterpartyId, callContext) @@ -7825,7 +7810,7 @@ trait APIMethods400 extends MdcLoggable { for { (user @Full(u), _, account, view, callContext) <- SS.userBankAccountView _ <- Helper.booleanToFuture(failMsg = s"${NoViewPermission}can_get_counterparty", 403, cc=callContext) { - view.canGetCounterparty == true + view.allowed_actions.exists(_ ==CAN_GET_COUNTERPARTY) } (counterparties, callContext) <- NewStyle.function.getCounterparties(bankId,accountId,viewId, callContext) //Here we need create the metadata for all the explicit counterparties. maybe show them in json response. @@ -7926,7 +7911,7 @@ trait APIMethods400 extends MdcLoggable { for { (user @Full(u), _, account, view, callContext) <- SS.userBankAccountView _ <- Helper.booleanToFuture(failMsg = s"${NoViewPermission}can_get_counterparty", 403, cc=callContext) { - view.canGetCounterparty == true + view.allowed_actions.exists(_ ==CAN_GET_COUNTERPARTY) } (counterparty, callContext) <- NewStyle.function.getCounterpartyByCounterpartyId(counterpartyId, callContext) counterpartyMetadata <- NewStyle.function.getMetadata(bankId, accountId, counterpartyId.value, callContext) diff --git a/obp-api/src/main/scala/code/api/v4_0_0/JSONFactory4.0.0.scala b/obp-api/src/main/scala/code/api/v4_0_0/JSONFactory4.0.0.scala index 24217ff5e..0edb4f2fe 100644 --- a/obp-api/src/main/scala/code/api/v4_0_0/JSONFactory4.0.0.scala +++ b/obp-api/src/main/scala/code/api/v4_0_0/JSONFactory4.0.0.scala @@ -1108,7 +1108,7 @@ object JSONFactory400 { val organisationWebsiteEnergySource = APIUtil.getPropsValue("energy_source.organisation_website", "") val energySource = new EnergySource400(organisationEnergySource, organisationWebsiteEnergySource) - val connector = code.api.Constant.Connector.openOrThrowException(s"$MandatoryPropertyIsNotSet. The missing prop is `connector` ") + val connector = code.api.Constant.CONNECTOR.openOrThrowException(s"$MandatoryPropertyIsNotSet. The missing prop is `connector` ") val resourceDocsRequiresRole = APIUtil.getPropsAsBoolValue("resource_docs_requires_role", false) APIInfoJson400( diff --git a/obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala b/obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala index 50e593848..0427e7ccf 100644 --- a/obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala +++ b/obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala @@ -1,6 +1,7 @@ package code.api.v5_0_0 import code.accountattribute.AccountAttributeX +import code.api.Constant._ import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON._ import code.api.util.APIUtil._ import code.api.util.ApiRole._ @@ -776,7 +777,7 @@ trait APIMethods500 { val accountId = AccountId(viewsFromJwtToken.head.account_id) val viewId = ViewId(viewsFromJwtToken.head.view_id) val helperInfoFromJwtToken = viewsFromJwtToken.head.helper_info - val viewCanGetCounterparty = Views.views.vend.customView(viewId, BankIdAccountId(bankId, accountId)).map(_.canGetCounterparty) + val viewCanGetCounterparty = Views.views.vend.customView(viewId, BankIdAccountId(bankId, accountId)).map(_.allowed_actions.exists( _ == CAN_GET_COUNTERPARTY)) val helperInfo = if(viewCanGetCounterparty==Full(true)) helperInfoFromJwtToken else None (Some(bankId), Some(accountId), Some(viewId), helperInfo) }else{ @@ -1884,9 +1885,9 @@ trait APIMethods500 { for { (Full(u), callContext) <- SS.user permission <- NewStyle.function.permission(bankId, accountId, u, callContext) - anyViewContainsCanSeeAvailableViewsForBankAccountPermission = permission.views.map(_.canSeeAvailableViewsForBankAccount).find(_.==(true)).getOrElse(false) + anyViewContainsCanSeeAvailableViewsForBankAccountPermission = permission.views.map(_.allowed_actions.exists(_ == CAN_SEE_AVAILABLE_VIEWS_FOR_BANK_ACCOUNT)).find(_.==(true)).getOrElse(false) _ <- Helper.booleanToFuture( - s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canSeeAvailableViewsForBankAccount_)).dropRight(1)}` permission on any your views", + s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_SEE_AVAILABLE_VIEWS_FOR_BANK_ACCOUNT)}` permission on any your views", cc = callContext ) { anyViewContainsCanSeeAvailableViewsForBankAccountPermission diff --git a/obp-api/src/main/scala/code/api/v5_0_0/JSONFactory5.0.0.scala b/obp-api/src/main/scala/code/api/v5_0_0/JSONFactory5.0.0.scala index 7be0bf05c..340bb9828 100644 --- a/obp-api/src/main/scala/code/api/v5_0_0/JSONFactory5.0.0.scala +++ b/obp-api/src/main/scala/code/api/v5_0_0/JSONFactory5.0.0.scala @@ -27,6 +27,7 @@ package code.api.v5_0_0 import code.api.Constant +import code.api.Constant._ import code.api.util.APIUtil import code.api.util.APIUtil.{gitCommit, nullToString, stringOptionOrNull, stringOrNull} import code.api.util.ErrorMessages.MandatoryPropertyIsNotSet @@ -559,7 +560,7 @@ object JSONFactory500 { val organisationWebsiteEnergySource = APIUtil.getPropsValue("energy_source.organisation_website", "") val energySource = new EnergySource400(organisationEnergySource, organisationWebsiteEnergySource) - val connector = code.api.Constant.Connector.openOrThrowException(s"$MandatoryPropertyIsNotSet. The missing prop is `connector` ") + val connector = code.api.Constant.CONNECTOR.openOrThrowException(s"$MandatoryPropertyIsNotSet. The missing prop is `connector` ") val resourceDocsRequiresRole = APIUtil.getPropsAsBoolValue("resource_docs_requires_role", false) APIInfoJson400( @@ -827,81 +828,81 @@ object JSONFactory500 { is_firehose = Some(view.isFirehose), alias = alias, hide_metadata_if_alias_used = view.hideOtherAccountMetadataIfAlias, - can_add_comment = view.canAddComment, - can_add_corporate_location = view.canAddCorporateLocation, - can_add_image = view.canAddImage, - can_add_image_url = view.canAddImageURL, - can_add_more_info = view.canAddMoreInfo, - can_add_open_corporates_url = view.canAddOpenCorporatesUrl, - can_add_physical_location = view.canAddPhysicalLocation, - can_add_private_alias = view.canAddPrivateAlias, - can_add_public_alias = view.canAddPublicAlias, - can_add_tag = view.canAddTag, - can_add_url = view.canAddURL, - can_add_where_tag = view.canAddWhereTag, - can_delete_comment = view.canDeleteComment, - can_add_counterparty = view.canAddCounterparty, - can_delete_corporate_location = view.canDeleteCorporateLocation, - can_delete_image = view.canDeleteImage, - can_delete_physical_location = view.canDeletePhysicalLocation, - can_delete_tag = view.canDeleteTag, - can_delete_where_tag = view.canDeleteWhereTag, - can_edit_owner_comment = view.canEditOwnerComment, - can_see_bank_account_balance = view.canSeeBankAccountBalance, - can_query_available_funds = view.canQueryAvailableFunds, - can_see_bank_account_bank_name = view.canSeeBankAccountBankName, - can_see_bank_account_currency = view.canSeeBankAccountCurrency, - can_see_bank_account_iban = view.canSeeBankAccountIban, - can_see_bank_account_label = view.canSeeBankAccountLabel, - can_see_bank_account_national_identifier = view.canSeeBankAccountNationalIdentifier, - can_see_bank_account_number = view.canSeeBankAccountNumber, - can_see_bank_account_owners = view.canSeeBankAccountOwners, - can_see_bank_account_swift_bic = view.canSeeBankAccountSwift_bic, - can_see_bank_account_type = view.canSeeBankAccountType, - can_see_comments = view.canSeeComments, - can_see_corporate_location = view.canSeeCorporateLocation, - can_see_image_url = view.canSeeImageUrl, - can_see_images = view.canSeeImages, - can_see_more_info = view.canSeeMoreInfo, - can_see_open_corporates_url = view.canSeeOpenCorporatesUrl, - can_see_other_account_bank_name = view.canSeeOtherAccountBankName, - can_see_other_account_iban = view.canSeeOtherAccountIBAN, - can_see_other_account_kind = view.canSeeOtherAccountKind, - can_see_other_account_metadata = view.canSeeOtherAccountMetadata, - can_see_other_account_national_identifier = view.canSeeOtherAccountNationalIdentifier, - can_see_other_account_number = view.canSeeOtherAccountNumber, - can_see_other_account_swift_bic = view.canSeeOtherAccountSWIFT_BIC, - can_see_owner_comment = view.canSeeOwnerComment, - can_see_physical_location = view.canSeePhysicalLocation, - can_see_private_alias = view.canSeePrivateAlias, - can_see_public_alias = view.canSeePublicAlias, - can_see_tags = view.canSeeTags, - can_see_transaction_amount = view.canSeeTransactionAmount, - can_see_transaction_balance = view.canSeeTransactionBalance, - can_see_transaction_currency = view.canSeeTransactionCurrency, - can_see_transaction_description = view.canSeeTransactionDescription, - can_see_transaction_finish_date = view.canSeeTransactionFinishDate, - can_see_transaction_metadata = view.canSeeTransactionMetadata, - can_see_transaction_other_bank_account = view.canSeeTransactionOtherBankAccount, - can_see_transaction_start_date = view.canSeeTransactionStartDate, - can_see_transaction_this_bank_account = view.canSeeTransactionThisBankAccount, - can_see_transaction_type = view.canSeeTransactionType, - can_see_url = view.canSeeUrl, - can_see_where_tag = view.canSeeWhereTag, + can_add_comment = view.allowed_actions.exists(_ == CAN_ADD_COMMENT), + can_add_corporate_location = view.allowed_actions.exists(_ == CAN_ADD_CORPORATE_LOCATION), + can_add_image = view.allowed_actions.exists(_ == CAN_ADD_IMAGE), + can_add_image_url = view.allowed_actions.exists(_ == CAN_ADD_IMAGE_URL), + can_add_more_info = view.allowed_actions.exists(_ == CAN_ADD_MORE_INFO), + can_add_open_corporates_url = view.allowed_actions.exists(_ == CAN_ADD_OPEN_CORPORATES_URL), + can_add_physical_location = view.allowed_actions.exists(_ == CAN_ADD_PHYSICAL_LOCATION), + can_add_private_alias = view.allowed_actions.exists(_ == CAN_ADD_PRIVATE_ALIAS), + can_add_public_alias = view.allowed_actions.exists(_ == CAN_ADD_PUBLIC_ALIAS), + can_add_tag = view.allowed_actions.exists(_ == CAN_ADD_TAG), + can_add_url = view.allowed_actions.exists(_ == CAN_ADD_URL), + can_add_where_tag = view.allowed_actions.exists(_ == CAN_ADD_WHERE_TAG), + can_delete_comment = view.allowed_actions.exists(_ == CAN_DELETE_COMMENT), + can_add_counterparty = view.allowed_actions.exists(_ == CAN_ADD_COUNTERPARTY), + can_delete_corporate_location = view.allowed_actions.exists(_ == CAN_DELETE_CORPORATE_LOCATION), + can_delete_image = view.allowed_actions.exists(_ == CAN_DELETE_IMAGE), + can_delete_physical_location = view.allowed_actions.exists(_ == CAN_DELETE_PHYSICAL_LOCATION), + can_delete_tag = view.allowed_actions.exists(_ == CAN_DELETE_TAG), + can_delete_where_tag = view.allowed_actions.exists(_ == CAN_DELETE_WHERE_TAG), + can_edit_owner_comment = view.allowed_actions.exists(_ == CAN_EDIT_OWNER_COMMENT), + can_see_bank_account_balance = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_BALANCE), + can_query_available_funds = view.allowed_actions.exists(_ == CAN_QUERY_AVAILABLE_FUNDS), + can_see_bank_account_bank_name = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_BANK_NAME), + can_see_bank_account_currency = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_CURRENCY), + can_see_bank_account_iban = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_IBAN), + can_see_bank_account_label = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_LABEL), + can_see_bank_account_national_identifier = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_NATIONAL_IDENTIFIER), + can_see_bank_account_number = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_NUMBER), + can_see_bank_account_owners = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_OWNERS), + can_see_bank_account_swift_bic = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_SWIFT_BIC), + can_see_bank_account_type = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_TYPE), + can_see_comments = view.allowed_actions.exists(_ == CAN_SEE_COMMENTS), + can_see_corporate_location = view.allowed_actions.exists(_ == CAN_SEE_CORPORATE_LOCATION), + can_see_image_url = view.allowed_actions.exists(_ == CAN_SEE_IMAGE_URL), + can_see_images = view.allowed_actions.exists(_ == CAN_SEE_IMAGES), + can_see_more_info = view.allowed_actions.exists(_ == CAN_SEE_MORE_INFO), + can_see_open_corporates_url = view.allowed_actions.exists(_ == CAN_SEE_OPEN_CORPORATES_URL), + can_see_other_account_bank_name = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_BANK_NAME), + can_see_other_account_iban = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_IBAN), + can_see_other_account_kind = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_KIND), + can_see_other_account_metadata = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_METADATA), + can_see_other_account_national_identifier = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_NATIONAL_IDENTIFIER), + can_see_other_account_number = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_NUMBER), + can_see_other_account_swift_bic = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_SWIFT_BIC), + can_see_owner_comment = view.allowed_actions.exists(_ == CAN_SEE_OWNER_COMMENT), + can_see_physical_location = view.allowed_actions.exists(_ == CAN_SEE_PHYSICAL_LOCATION), + can_see_private_alias = view.allowed_actions.exists(_ == CAN_SEE_PRIVATE_ALIAS), + can_see_public_alias = view.allowed_actions.exists(_ == CAN_SEE_PUBLIC_ALIAS), + can_see_tags = view.allowed_actions.exists(_ == CAN_SEE_TAGS), + can_see_transaction_amount = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_AMOUNT), + can_see_transaction_balance = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_BALANCE), + can_see_transaction_currency = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_CURRENCY), + can_see_transaction_description = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_DESCRIPTION), + can_see_transaction_finish_date = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_FINISH_DATE), + can_see_transaction_metadata = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_METADATA), + can_see_transaction_other_bank_account = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_OTHER_BANK_ACCOUNT), + can_see_transaction_start_date = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_START_DATE), + can_see_transaction_this_bank_account = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_THIS_BANK_ACCOUNT), + can_see_transaction_type = view.allowed_actions.exists(_ == CAN_SEE_TRANSACTION_TYPE), + can_see_url = view.allowed_actions.exists(_ == CAN_SEE_URL), + can_see_where_tag = view.allowed_actions.exists(_ == CAN_SEE_WHERE_TAG), //V300 new - can_see_bank_routing_scheme = view.canSeeBankRoutingScheme, - can_see_bank_routing_address = view.canSeeBankRoutingAddress, - can_see_bank_account_routing_scheme = view.canSeeBankAccountRoutingScheme, - can_see_bank_account_routing_address = view.canSeeBankAccountRoutingAddress, - can_see_other_bank_routing_scheme = view.canSeeOtherBankRoutingScheme, - can_see_other_bank_routing_address = view.canSeeOtherBankRoutingAddress, - can_see_other_account_routing_scheme = view.canSeeOtherAccountRoutingScheme, - can_see_other_account_routing_address= view.canSeeOtherAccountRoutingAddress, - can_add_transaction_request_to_own_account = view.canAddTransactionRequestToOwnAccount, //added following two for payments - can_add_transaction_request_to_any_account = view.canAddTransactionRequestToAnyAccount, - can_see_bank_account_credit_limit = view.canSeeBankAccountCreditLimit, - can_create_direct_debit = view.canCreateDirectDebit, - can_create_standing_order = view.canCreateStandingOrder, + can_see_bank_routing_scheme = view.allowed_actions.exists(_ == CAN_SEE_BANK_ROUTING_SCHEME), + can_see_bank_routing_address = view.allowed_actions.exists(_ == CAN_SEE_BANK_ROUTING_ADDRESS), + can_see_bank_account_routing_scheme = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_ROUTING_SCHEME), + can_see_bank_account_routing_address = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_ROUTING_ADDRESS), + can_see_other_bank_routing_scheme = view.allowed_actions.exists(_ == CAN_SEE_OTHER_BANK_ROUTING_SCHEME), + can_see_other_bank_routing_address = view.allowed_actions.exists(_ == CAN_SEE_OTHER_BANK_ROUTING_ADDRESS), + can_see_other_account_routing_scheme = view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_ROUTING_SCHEME), + can_see_other_account_routing_address= view.allowed_actions.exists(_ == CAN_SEE_OTHER_ACCOUNT_ROUTING_ADDRESS), + can_add_transaction_request_to_own_account = view.allowed_actions.exists(_ == CAN_ADD_TRANSACTION_REQUEST_TO_OWN_ACCOUNT), //added following two for payments + can_add_transaction_request_to_any_account = view.allowed_actions.exists(_ == CAN_ADD_TRANSACTION_REQUEST_TO_ANY_ACCOUNT), + can_see_bank_account_credit_limit = view.allowed_actions.exists(_ == CAN_SEE_BANK_ACCOUNT_CREDIT_LIMIT), + can_create_direct_debit = view.allowed_actions.exists(_ == CAN_CREATE_DIRECT_DEBIT), + can_create_standing_order = view.allowed_actions.exists(_ == CAN_CREATE_STANDING_ORDER), // Version 5.0.0 can_grant_access_to_views = view.canGrantAccessToViews.getOrElse(Nil), can_revoke_access_to_views = view.canRevokeAccessToViews.getOrElse(Nil), diff --git a/obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala b/obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala index d9ed88566..b9196a235 100644 --- a/obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala +++ b/obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala @@ -2,6 +2,7 @@ package code.api.v5_1_0 import code.api.Constant +import code.api.Constant._ import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON._ import code.api.berlin.group.v1_3.JSONFactory_BERLIN_GROUP_1_3.{ConsentAccessAccountsJson, ConsentAccessJson} import code.api.util.APIUtil._ @@ -3744,9 +3745,9 @@ trait APIMethods510 { (fromAccount, callContext) <- NewStyle.function.checkBankAccountExists(bankId, accountId, callContext) view <- NewStyle.function.checkAccountAccessAndGetView(viewId, BankIdAccountId(bankId, accountId), Full(u), callContext) _ <- Helper.booleanToFuture( - s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canSeeTransactionRequests_)).dropRight(1)}` permission on the View(${viewId.value})", + s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_SEE_TRANSACTION_REQUESTS)}` permission on the View(${viewId.value})", cc=callContext){ - view.canSeeTransactionRequests + view.allowed_actions.exists(_ ==CAN_SEE_TRANSACTION_REQUESTS) } (transactionRequests, callContext) <- Future(Connector.connector.vend.getTransactionRequests210(u, fromAccount, callContext)) map { unboxFullOrFail(_, callContext, GetTransactionRequestsException) @@ -3933,9 +3934,9 @@ trait APIMethods510 { bankIdAccountId = BankIdAccountId(bankId, accountId) view <- NewStyle.function.checkViewAccessAndReturnView(viewId, bankIdAccountId, Full(u), callContext) // Note we do one explicit check here rather than use moderated account because this provides an explicit message - failMsg = ViewDoesNotPermitAccess + s" You need the `${StringHelpers.snakify(nameOf(view.canSeeBankAccountBalance))}` permission on VIEW_ID(${viewId.value})" + failMsg = ViewDoesNotPermitAccess + s" You need the `${StringHelpers.snakify(CAN_SEE_BANK_ACCOUNT_BALANCE)}` permission on VIEW_ID(${viewId.value})" _ <- Helper.booleanToFuture(failMsg, 403, cc = callContext) { - view.canSeeBankAccountBalance + view.allowed_actions.exists(_ ==CAN_SEE_BANK_ACCOUNT_BALANCE) } (accountBalances, callContext) <- BalanceNewStyle.getBankAccountBalances(bankIdAccountId, callContext) } yield { @@ -4432,10 +4433,10 @@ trait APIMethods510 { permissionsFromTarget.toSet.subsetOf(permissionsFromSource) } - failMsg = s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(view.canCreateCustomView))}` permission on VIEW_ID(${viewId.value})" + failMsg = s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_CREATE_CUSTOM_VIEW)}` permission on VIEW_ID(${viewId.value})" _ <- Helper.booleanToFuture(failMsg, cc = callContext) { - view.canCreateCustomView + view.allowed_actions.exists(_ ==CAN_CREATE_CUSTOM_VIEW) } (view, callContext) <- NewStyle.function.createCustomView(BankIdAccountId(bankId, accountId), createCustomViewJson.toCreateViewJson, callContext) } yield { @@ -4489,10 +4490,10 @@ trait APIMethods510 { permissionsFromTarget.toSet.subsetOf(permissionsFromSource) } - failmsg = s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(view.canUpdateCustomView))}` permission on VIEW_ID(${viewId.value})" + failmsg = s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_UPDATE_CUSTOM_VIEW)}` permission on VIEW_ID(${viewId.value})" _ <- Helper.booleanToFuture(failmsg, cc = callContext) { - view.canCreateCustomView + view.allowed_actions.exists(_ ==CAN_CREATE_CUSTOM_VIEW) } (view, callContext) <- NewStyle.function.updateCustomView(BankIdAccountId(bankId, accountId), targetViewId, targetCreateCustomViewJson.toUpdateViewJson, callContext) @@ -4555,9 +4556,9 @@ trait APIMethods510 { _ <- Helper.booleanToFuture(failMsg = InvalidCustomViewFormat + s"Current TARGET_VIEW_ID (${targetViewId.value})", cc = callContext) { isValidCustomViewId(targetViewId.value) } - failmsg = s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(view.canGetCustomView))}`permission on any your views. Current VIEW_ID (${viewId.value})" + failmsg = s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_GET_CUSTOM_VIEW)}`permission on any your views. Current VIEW_ID (${viewId.value})" _ <- Helper.booleanToFuture(failmsg, cc = callContext) { - view.canGetCustomView + view.allowed_actions.exists(_ ==CAN_GET_CUSTOM_VIEW) } targetView <- NewStyle.function.customView(targetViewId, BankIdAccountId(bankId, accountId), callContext) } yield { @@ -4597,9 +4598,9 @@ trait APIMethods510 { _ <- Helper.booleanToFuture(failMsg = InvalidCustomViewFormat + s"Current TARGET_VIEW_ID (${targetViewId.value})", cc = callContext) { isValidCustomViewId(targetViewId.value) } - failMsg = s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(view.canDeleteCustomView))}` permission on any your views.Current VIEW_ID (${viewId.value})" + failMsg = s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_DELETE_CUSTOM_VIEW)}` permission on any your views.Current VIEW_ID (${viewId.value})" _ <- Helper.booleanToFuture(failMsg, cc = callContext) { - view.canDeleteCustomView + view.allowed_actions.exists(_ ==CAN_DELETE_CUSTOM_VIEW) } _ <- NewStyle.function.customView(targetViewId, BankIdAccountId(bankId, accountId), callContext) deleted <- NewStyle.function.removeCustomView(targetViewId, BankIdAccountId(bankId, accountId), callContext) diff --git a/obp-api/src/main/scala/code/api/v5_1_0/JSONFactory5.1.0.scala b/obp-api/src/main/scala/code/api/v5_1_0/JSONFactory5.1.0.scala index e4f45ca05..0463b6cf6 100644 --- a/obp-api/src/main/scala/code/api/v5_1_0/JSONFactory5.1.0.scala +++ b/obp-api/src/main/scala/code/api/v5_1_0/JSONFactory5.1.0.scala @@ -999,7 +999,7 @@ object JSONFactory510 extends CustomJsonFormats { val organisationWebsiteEnergySource = APIUtil.getPropsValue("energy_source.organisation_website", "") val energySource = EnergySource400(organisationEnergySource, organisationWebsiteEnergySource) - val connector = code.api.Constant.Connector.openOrThrowException(s"$MandatoryPropertyIsNotSet. The missing prop is `connector` ") + val connector = code.api.Constant.CONNECTOR.openOrThrowException(s"$MandatoryPropertyIsNotSet. The missing prop is `connector` ") val resourceDocsRequiresRole = APIUtil.getPropsAsBoolValue("resource_docs_requires_role", false) APIInfoJsonV510( diff --git a/obp-api/src/main/scala/code/bankconnectors/Connector.scala b/obp-api/src/main/scala/code/bankconnectors/Connector.scala index 48d082dbd..2d3a8ae3e 100644 --- a/obp-api/src/main/scala/code/bankconnectors/Connector.scala +++ b/obp-api/src/main/scala/code/bankconnectors/Connector.scala @@ -80,7 +80,7 @@ object Connector extends SimpleInjector { val connector = new Inject(buildOne _) {} def buildOne: Connector = { - val connectorProps = code.api.Constant.Connector.openOrThrowException(s"$MandatoryPropertyIsNotSet The missing props is 'connector'") + val connectorProps = code.api.Constant.CONNECTOR.openOrThrowException(s"$MandatoryPropertyIsNotSet The missing props is 'connector'") getConnectorInstance(connectorProps) } diff --git a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala index 2bc99ae3e..f3fa9d7a0 100644 --- a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala +++ b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala @@ -4719,7 +4719,7 @@ object LocalMappedConnector extends Connector with MdcLoggable { for ( permission <- Views.views.vend.permissions(BankIdAccountId(bankId, accountId)) ) yield { - permission.views.exists(_.canAddTransactionRequestToAnyAccount == true) match { + permission.views.exists(_.allowed_actions.exists( _ == CAN_ADD_TRANSACTION_REQUEST_TO_ANY_ACCOUNT)) match { case true => Some(permission.user) case _ => None } diff --git a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnectorInternal.scala b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnectorInternal.scala index a49f32b74..45c002922 100644 --- a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnectorInternal.scala +++ b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnectorInternal.scala @@ -71,7 +71,7 @@ object LocalMappedConnectorInternal extends MdcLoggable { fromBankIdAccountId = BankIdAccountId(fromAccount.bankId, fromAccount.accountId) view <- NewStyle.function.checkAccountAccessAndGetView(viewId, fromBankIdAccountId, Full(user), callContext) _ <- Helper.booleanToFuture(InsufficientAuthorisationToCreateTransactionRequest, cc = callContext) { - view.canAddTransactionRequestToAnyAccount + view.allowed_actions.exists(_ ==CAN_ADD_TRANSACTION_REQUEST_TO_ANY_ACCOUNT) } (paymentLimit, callContext) <- Connector.connector.vend.getPaymentLimit( diff --git a/obp-api/src/main/scala/code/model/ModeratedBankingData.scala b/obp-api/src/main/scala/code/model/ModeratedBankingData.scala index eb92b28d5..7314db295 100644 --- a/obp-api/src/main/scala/code/model/ModeratedBankingData.scala +++ b/obp-api/src/main/scala/code/model/ModeratedBankingData.scala @@ -26,6 +26,7 @@ TESOBE (http://www.tesobe.com/) */ package code.model +import code.api.Constant._ import code.api.util.ErrorMessages._ import code.api.util.{APIUtil, CallContext} import code.model.Moderation.Moderated @@ -123,7 +124,7 @@ class ModeratedTransactionMetadata( u <- Box(user) ?~ { UserNotLoggedIn} tagList <- Box(tags) ?~ { s"$NoViewPermission can_delete_tag. " } tag <- Box(tagList.find(tag => tag.id_ == tagId)) ?~ {"Tag with id " + tagId + "not found for this transaction"} - deleteFunc <- if(tag.postedBy == user||view.canDeleteTag) + deleteFunc <- if(tag.postedBy == user||view.allowed_actions.exists(_ == CAN_DELETE_TAG)) Box(deleteTag) ?~ "Deleting tags not permitted for this view" else Failure("deleting tags not permitted for the current user") @@ -140,7 +141,7 @@ class ModeratedTransactionMetadata( u <- Box(user) ?~ { UserNotLoggedIn} imageList <- Box(images) ?~ { s"$NoViewPermission can_delete_image." } image <- Box(imageList.find(image => image.id_ == imageId)) ?~ {"Image with id " + imageId + "not found for this transaction"} - deleteFunc <- if(image.postedBy == user || view.canDeleteImage) + deleteFunc <- if(image.postedBy == user || view.allowed_actions.exists(_ ==CAN_DELETE_IMAGE)) Box(deleteImage) ?~ "Deleting images not permitted for this view" else Failure("Deleting images not permitted for the current user") @@ -154,7 +155,7 @@ class ModeratedTransactionMetadata( u <- Box(user) ?~ { UserNotLoggedIn} commentList <- Box(comments) ?~ { s"$NoViewPermission can_delete_comment." } comment <- Box(commentList.find(comment => comment.id_ == commentId)) ?~ {"Comment with id "+commentId+" not found for this transaction"} - deleteFunc <- if(comment.postedBy == user || view.canDeleteComment) + deleteFunc <- if(comment.postedBy == user || view.allowed_actions.exists(_ ==CAN_DELETE_COMMENT)) Box(deleteComment) ?~ "Deleting comments not permitted for this view" else Failure("Deleting comments not permitted for the current user") @@ -168,7 +169,7 @@ class ModeratedTransactionMetadata( u <- Box(user) ?~ { UserNotLoggedIn} whereTagOption <- Box(whereTag) ?~ { s"$NoViewPermission can_delete_where_tag. Current ViewId($viewId)" } whereTag <- Box(whereTagOption) ?~ {"there is no tag to delete"} - deleteFunc <- if(whereTag.postedBy == user || view.canDeleteWhereTag) + deleteFunc <- if(whereTag.postedBy == user || view.allowed_actions.exists(_ ==CAN_DELETE_WHERE_TAG)) Box(deleteWhereTag) ?~ "Deleting tag is not permitted for this view" else Failure("Deleting tags not permitted for the current user") diff --git a/obp-api/src/main/scala/code/model/View.scala b/obp-api/src/main/scala/code/model/View.scala index 4d599023a..bd9dcc8fa 100644 --- a/obp-api/src/main/scala/code/model/View.scala +++ b/obp-api/src/main/scala/code/model/View.scala @@ -28,10 +28,10 @@ TESOBE (http://www.tesobe.com/) package code.model +import code.api.Constant._ import code.api.util.ErrorMessages import code.metadata.counterparties.Counterparties -import code.views.system.{ViewDefinition, ViewPermission} -import com.github.dwickern.macros.NameOf.nameOf +import code.views.system.ViewPermission import com.openbankproject.commons.model._ import com.openbankproject.commons.model.enums.AccountRoutingScheme import net.liftweb.common._ @@ -372,7 +372,7 @@ case class ViewExtended(val view: View) { ) } else - Failure(s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canSeeTransactionThisBankAccount_)).dropRight(1)}` permission on the view(${view.viewId.value})") + Failure(s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_SEE_TRANSACTION_THIS_BANK_ACCOUNT)}` permission on the view(${view.viewId.value})") } @@ -424,7 +424,7 @@ case class ViewExtended(val view: View) { ) } else - Failure(s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canSeeTransactionThisBankAccount_)).dropRight(1)}` permission on the view(${view.viewId.value})") + Failure(s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_SEE_TRANSACTION_THIS_BANK_ACCOUNT)}` permission on the view(${view.viewId.value})") } def moderateAccountCore(bankAccount: BankAccount) : Box[ModeratedBankAccountCore] = { @@ -459,7 +459,7 @@ case class ViewExtended(val view: View) { ) } else - Failure(s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canSeeTransactionThisBankAccount_)).dropRight(1)}` permission on the view(${view.viewId.value})") + Failure(s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_SEE_TRANSACTION_THIS_BANK_ACCOUNT)}` permission on the view(${view.viewId.value})") } // Moderate the Counterparty side of the Transaction (i.e. the Other Account involved in the transaction) @@ -584,7 +584,7 @@ case class ViewExtended(val view: View) { ) } else - Failure(s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canSeeTransactionOtherBankAccount_)).dropRight(1)}` permission on the view(${view.viewId.value})") + Failure(s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_SEE_TRANSACTION_OTHER_BANK_ACCOUNT)}` permission on the view(${view.viewId.value})") } def moderateCore(counterpartyCore : CounterpartyCore) : Box[ModeratedOtherBankAccountCore] = { @@ -635,6 +635,6 @@ case class ViewExtended(val view: View) { ) } else - Failure(s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(ViewDefinition.canSeeTransactionOtherBankAccount_)).dropRight(1)}` permission on the view(${view.viewId.value})") + Failure(s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(CAN_SEE_TRANSACTION_OTHER_BANK_ACCOUNT)}` permission on the view(${view.viewId.value})") } } diff --git a/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala b/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala index cb056b0f7..29db243af 100644 --- a/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala +++ b/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala @@ -419,7 +419,7 @@ import net.liftweb.util.Helpers._ /**Marking the locked state to show different error message */ val usernameLockedStateCode = Long.MaxValue - val connector = code.api.Constant.Connector.openOrThrowException(s"$MandatoryPropertyIsNotSet. The missing prop is `connector` ") + val connector = code.api.Constant.CONNECTOR.openOrThrowException(s"$MandatoryPropertyIsNotSet. The missing prop is `connector` ") val starConnectorSupportedTypes = APIUtil.getPropsValue("starConnector_supported_types","") override def dbIndexes: List[BaseIndex[AuthUser]] = UniqueIndex(username, provider) ::super.dbIndexes diff --git a/obp-api/src/main/scala/code/transaction/MappedTransaction.scala b/obp-api/src/main/scala/code/transaction/MappedTransaction.scala index 5ff7ab1bb..1e968ee0c 100644 --- a/obp-api/src/main/scala/code/transaction/MappedTransaction.scala +++ b/obp-api/src/main/scala/code/transaction/MappedTransaction.scala @@ -218,7 +218,7 @@ class MappedTransaction extends LongKeyedMapper[MappedTransaction] with IdPK wit } def toTransaction : Option[Transaction] = { - code.api.Constant.Connector match { + code.api.Constant.CONNECTOR match { case Full("akka_vDec2018") => for { acc <- getBankAccountCommon(theBankId, theAccountId, None).map(_._1) diff --git a/obp-api/src/main/scala/code/views/system/ViewDefinition.scala b/obp-api/src/main/scala/code/views/system/ViewDefinition.scala index 3e254982d..561ebde73 100644 --- a/obp-api/src/main/scala/code/views/system/ViewDefinition.scala +++ b/obp-api/src/main/scala/code/views/system/ViewDefinition.scala @@ -482,6 +482,29 @@ class ViewDefinition extends View with LongKeyedMapper[ViewDefinition] with Many def usePublicAliasIfOneExists: Boolean = usePublicAliasIfOneExists_.get def hideOtherAccountMetadataIfAlias: Boolean = hideOtherAccountMetadataIfAlias_.get + override def allowed_actions : List[String] = ViewPermission.findViewPermissions(this).map(_.permission.get).distinct + +// override def canGrantAccessToViews : Option[List[String]] = { +// ViewPermission.findViewPermission(this, CAN_GRANT_ACCESS_TO_VIEWS).flatMap(vp => +// { +// vp.metaData.get match { +// case value if(value != null && !value.isEmpty) => Some(value.split(",").toList.map(_.trim)) +// case _ => None +// } +// }) +// } +// +// override def canRevokeAccessToViews : Option[List[String]] = { +// ViewPermission.findViewPermission(this, CAN_REVOKE_ACCESS_TO_VIEWS).flatMap(vp => +// { +// vp.metaData.get match { +// case value if(value != null && !value.isEmpty) => Some(value.split(",").toList.map(_.trim)) +// case _ => None +// } +// }) +// } + + //This current view can grant access to other views. override def canGrantAccessToViews : Option[List[String]] = { canGrantAccessToViews_.get == null || canGrantAccessToViews_.get.isEmpty() match { diff --git a/obp-api/src/main/scala/code/views/system/ViewPermission.scala b/obp-api/src/main/scala/code/views/system/ViewPermission.scala index 85db9aa85..17c09f643 100644 --- a/obp-api/src/main/scala/code/views/system/ViewPermission.scala +++ b/obp-api/src/main/scala/code/views/system/ViewPermission.scala @@ -11,7 +11,10 @@ class ViewPermission extends LongKeyedMapper[ViewPermission] with IdPK with Crea object account_id extends MappedString(this, 255) object view_id extends UUIDString(this) object permission extends MappedString(this, 255) - object metaData extends MappedString(this, 1024) //this is for special permissions like "canRevokeAccessToViews" and "canGrantAccessToViews", it need to support list of views. + + //this is for special permissions like "canRevokeAccessToViews" and "canGrantAccessToViews", it will be a list of view ids , + // eg: owner,auditor,accountant,firehose,standard,StageOne,ManageCustomViews,ReadAccountsBasic,ReadAccountsDetail,ReadBalances,ReadTransactionsBasic,ReadTransactionsDebits, + object metaData extends MappedString(this, 1024) } object ViewPermission extends ViewPermission with LongKeyedMetaMapper[ViewPermission] { override def dbIndexes: List[BaseIndex[ViewPermission]] = UniqueIndex(bank_id, account_id, view_id, permission) :: super.dbIndexes diff --git a/obp-api/src/test/scala/code/api/v1_2_1/API1_2_1Test.scala b/obp-api/src/test/scala/code/api/v1_2_1/API1_2_1Test.scala index 4924a3521..ebc971366 100644 --- a/obp-api/src/test/scala/code/api/v1_2_1/API1_2_1Test.scala +++ b/obp-api/src/test/scala/code/api/v1_2_1/API1_2_1Test.scala @@ -26,12 +26,13 @@ TESOBE (http://www.tesobe.com/) */ package code.api.v1_2_1 -import code.api.Constant._ import _root_.net.liftweb.json.Serialization.write +import code.api.Constant._ import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON import code.api.util.APIUtil import code.api.util.APIUtil.OAuth._ import code.api.util.APIUtil.isValidSystemViewId +import code.api.util.ErrorMessages._ import code.bankconnectors.Connector import code.setup.{APIResponse, DefaultUsers, PrivateUser2AccountsAndSetUpWithTestData, ServerSetupWithTestData} import code.views.Views @@ -39,7 +40,6 @@ import com.openbankproject.commons.model._ import net.liftweb.json._ import net.liftweb.util.Helpers._ import org.scalatest.Tag -import code.api.util.ErrorMessages._ import scala.util.Random._ @@ -2017,8 +2017,10 @@ class API1_2_1Test extends ServerSetupWithTestData with DefaultUsers with Privat val viewId = SYSTEM_OWNER_VIEW_ID val userId1 = resourceUser2.idGivenByProvider val userId2 = resourceUser2.idGivenByProvider - grantUserAccessToView(bankId, bankAccount.id, userId1, viewId, user1) - grantUserAccessToView(bankId, bankAccount.id, userId2, viewId, user1) + val replyGrant1 = grantUserAccessToView(bankId, bankAccount.id, userId1, viewId, user1) + replyGrant1.code should equal (201) + val replyGrant2 = grantUserAccessToView(bankId, bankAccount.id, userId2, viewId, user1) + replyGrant2.code should equal (201) val viewsBefore = getUserAccountPermission(bankId, bankAccount.id, userId1, user1).body.extract[ViewsJSONV121].views.length When("the request is sent") val reply = revokeUserAccessToView(bankId, bankAccount.id, userId1, viewId, user1) diff --git a/obp-api/src/test/scala/code/api/v3_1_0/ObpApiLoopbackTest.scala b/obp-api/src/test/scala/code/api/v3_1_0/ObpApiLoopbackTest.scala index 482254d7c..3dd0e9a6f 100644 --- a/obp-api/src/test/scala/code/api/v3_1_0/ObpApiLoopbackTest.scala +++ b/obp-api/src/test/scala/code/api/v3_1_0/ObpApiLoopbackTest.scala @@ -51,7 +51,7 @@ class ObpApiLoopbackTest extends V310ServerSetup { val response310 = makeGetRequest(request310) Then("We should get a 400") response310.code should equal(400) - val connectorVersion = code.api.Constant.Connector.openOrThrowException(s"$MandatoryPropertyIsNotSet The missing props is 'connector'") + val connectorVersion = code.api.Constant.CONNECTOR.openOrThrowException(s"$MandatoryPropertyIsNotSet The missing props is 'connector'") val errorMessage = s"${NotImplemented}" And("error should be " + errorMessage) response310.body.extract[ErrorMessage].message should equal (errorMessage) diff --git a/obp-commons/src/main/scala/com/openbankproject/commons/model/ViewModel.scala b/obp-commons/src/main/scala/com/openbankproject/commons/model/ViewModel.scala index ca8bb81f2..dba7e7bdc 100644 --- a/obp-commons/src/main/scala/com/openbankproject/commons/model/ViewModel.scala +++ b/obp-commons/src/main/scala/com/openbankproject/commons/model/ViewModel.scala @@ -249,7 +249,12 @@ trait View { def usePrivateAliasIfOneExists: Boolean def hideOtherAccountMetadataIfAlias: Boolean - + /** + * These three will get the allowed actions from viewPermission table + */ + def allowed_actions : List[String] + + def canGrantAccessToViews : Option[List[String]] = None def canRevokeAccessToViews : Option[List[String]] = None