Skip to content

Commit

Permalink
Merge pull request #2391 from hongwei1/develop
Browse files Browse the repository at this point in the history
feature/added the added Add Subscriptions buttons
  • Loading branch information
simonredfern committed May 30, 2024
2 parents faf8e28 + 415770e commit 5bf3f7f
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 12 deletions.
4 changes: 4 additions & 0 deletions obp-api/src/main/resources/props/sample.props.template
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,10 @@ webui_developer_user_invitation_email_html_text=<!DOCTYPE html>\
</p>\
</body>\
</html>
# the subscription button,default is empty, will not show it on the homepage.
#webui_subscriptions_url=
#webui_subscriptions_button_text=
#webui_subscriptions_invitation_text=

# List of countries where consent is not required for the collection of personal data
personal_data_collection_consent_country_waiver_list = Austria, Belgium, Bulgaria, Croatia, Republic of Cyprus, Czech Republic, Denmark, Estonia, Finland, France, Germany, Greece, Hungary, Ireland, Italy, Latvia, Lithuania, Luxembourg, Malta, Netherlands, Poland, Portugal, Romania, Slovakia, Slovenia, Spain, Sweden, England, Scotland, Wales, Northern Ireland
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package code.api.util.migration
import code.api.Constant.ALL_CONSUMERS
import code.api.util.APIUtil
import code.api.util.migration.Migration.{DbFunction, saveLog}
import code.util.Helper
import code.views.system.AccountAccess
import net.liftweb.common.Full
import net.liftweb.mapper.{DB, Schemifier}
Expand Down Expand Up @@ -30,8 +31,8 @@ object MigrationOfAccountAccessAddedConsumerId {
case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") =>
() =>
s"""
|ALTER TABLE accountaccess ADD COLUMN IF NOT EXISTS "consumer_id" character varchar(255) DEFAULT '$ALL_CONSUMERS';
|DROP INDEX IF EXISTS accountaccess_bank_id_account_id_view_fk_user_fk;
|${Helper.addColumnIfNotExists("accountaccess", "consumer_id", ALL_CONSUMERS)}
|${Helper.dropIndexIfExists("accountaccess", "accountaccess_bank_id_account_id_view_fk_user_fk")}
|""".stripMargin
case _ =>
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import code.api.util.{APIUtil, DBUtil}
import code.api.util.migration.Migration.{DbFunction, saveLog}
import code.context.MappedConsentAuthContext
import net.liftweb.common.Full
import code.util.Helper
import net.liftweb.mapper.{DB, Schemifier}
import net.liftweb.util.DefaultConnectionIdentifier
import scalikejdbc.DB.CPContext
Expand Down Expand Up @@ -46,10 +47,15 @@ object MigrationOfConsentAuthContextDropIndex {

val executedSql =
DbFunction.maybeWrite(true, Schemifier.infoF _) {
APIUtil.getPropsValue("db.driver") match {
APIUtil.getPropsValue("db.driver") match {
case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") =>
() =>
s"""
|${Helper.dropIndexIfExists("MappedConsentAuthContext", "consentauthcontext_consentid_key_c")}
|""".stripMargin
case _ =>
() => "DROP INDEX IF EXISTS consentauthcontext_consentid_key_c;"
}
}
}

val endDate = System.currentTimeMillis()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package code.api.util.migration

import code.api.Constant
import code.api.util.{APIUtil, DBUtil}
import code.api.util.migration.Migration.{DbFunction, saveLog}
import code.loginattempts.MappedBadLoginAttempt
import net.liftweb.mapper.{DB, Schemifier}
import net.liftweb.util.DefaultConnectionIdentifier
import net.liftweb.common.Full
import code.util.Helper
import scalikejdbc.DB.CPContext
import scalikejdbc._
import java.time.format.DateTimeFormatter
Expand Down Expand Up @@ -44,7 +44,12 @@ object MigrationOfMappedBadLoginAttemptDropIndex {

val executedSql =
DbFunction.maybeWrite(true, Schemifier.infoF _) {
APIUtil.getPropsValue("db.driver") match {
APIUtil.getPropsValue("db.driver") match {
case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") =>
() =>
s"""
|${Helper.dropIndexIfExists("mappedbadloginattempt", "mappedbadloginattempt_musername")}
|""".stripMargin
case _ =>
() => "DROP INDEX IF EXISTS mappedbadloginattempt_musername;"
}
Expand Down
24 changes: 24 additions & 0 deletions obp-api/src/main/scala/code/snippet/WebUI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,30 @@ class WebUI extends MdcLoggable{
"#sandbox-introduction-link [href]" #> scala.xml.Unparsed(webUiApiDocumentation)
}

def subscriptionsButton: CssSel = {
val webuiSubscriptionsUrl = getWebUiPropsValue("webui_subscriptions_url", s"")
val webuiSubscriptionsButtonText = getWebUiPropsValue("webui_subscriptions_button_text", s"")

if (webuiSubscriptionsButtonText.isEmpty) {
".subscriptions-button [style]" #> "display:none"&
".btn-default [style]" #> "display:none"
} else {
".subscriptions-button [href]" #> scala.xml.Unparsed(webuiSubscriptionsUrl) &
".subscriptions-button-text *" #> scala.xml.Unparsed(webuiSubscriptionsButtonText)
}
}


def subscriptionsInvitationText: CssSel = {
val webuiSubscriptionsInvitationText = getWebUiPropsValue("webui_subscriptions_invitation_text", s"")

if (webuiSubscriptionsInvitationText.isEmpty) {
".subscriptions_invitation_text [style]" #> "display:none"
} else {
".subscriptions_invitation_text *" #> scala.xml.Unparsed(webuiSubscriptionsInvitationText)
}
}

def technicalFaqsAnchor: CssSel = {
"#technical-faqs-anchor [href]" #> scala.xml.Unparsed(s"${getServerUrl}#technical-faqs")
}
Expand Down
16 changes: 16 additions & 0 deletions obp-api/src/main/scala/code/util/Helper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -523,4 +523,20 @@ object Helper extends Loggable {
enhancer.create().asInstanceOf[S]
}

def addColumnIfNotExists(tableName: String, columName: String, default: String) =
s"""
|IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '$tableName' AND COLUMN_NAME = '$columName')
|BEGIN
| ALTER TABLE $tableName ADD $columName VARCHAR(255) DEFAULT '$default';
|END""".stripMargin


def dropIndexIfExists(tableName: String, index: String) =
s"""
|IF EXISTS (SELECT 1 FROM sys.indexes WHERE name = '$index' AND object_id = OBJECT_ID('$tableName'))
|BEGIN
| DROP INDEX $tableName.$index;
|END""".stripMargin


}
13 changes: 11 additions & 2 deletions obp-api/src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ <h1 id="main-about-text" data-lift="WebUI.aboutText"><lift:loc locid="welcome.to
<!-- <a href="/consumer-registration" class="btn btn-default">Get API key</a>-->
<!-- <a class="sofi-link btn btn-default" data-lift="WebUI.sofiLink" href="">SOFIT</a>-->
<!-- <a id="sandbox-introduction-link" class="btn btn-default" data-lift="WebUI.sandboxIntroductionLink" href="">INTRODUCTION</a>-->

<a class="btn btn-default subscriptions-button" data-lift="WebUI.subscriptionsButton" href="">
<lift:loc locid="subscriptions"><div class ="subscriptions-button-text">Subscriptions</div></lift:loc></a>
</div>
</div>
</div>
Expand All @@ -58,8 +59,11 @@ <h2 id="get-started-part"><lift:loc locid="get_started_title">Get started</lift:
</div>
<div class="col-xs-12 col-md-5 main-get-started-text">
<h3><lift:loc locid="get_started_create_account_title">Create an account</lift:loc></h3>
<p><lift:loc locid="get_started_create_account">First, create a free developer account on this sandbox and request a developer key. You will be asked to submit basic information about your app at this stage.</lift:loc><a href="/user_mgt/sign_up"><lift:loc locid="register_for_an_account">Register for an account</lift:loc>
<p><lift:loc locid="get_started_create_account">First, create a free developer account on this sandbox and request a developer key. You will be asked to submit basic information about your app at this stage. </lift:loc><a href="/user_mgt/sign_up"><lift:loc locid="register_for_an_account">Register for an account</lift:loc>
</a>.</p>
<p data-lift="WebUI.subscriptionsInvitationText" class ="subscriptions_invitation_text"> </lift:loc>
</p>
</a>
</div>
</div>
<div class="row">
Expand Down Expand Up @@ -319,6 +323,11 @@ <h2 name="get-started" data-lift="WebUI.getStartedText"><lift:loc locid="get_sta
<a href="/consumer-registration">
<lift:loc locid="get_api_key">Get API key</lift:loc></a>
</div>
<div data-lift="WebUI.subscriptionsButton" class="btn btn-default pull-left" id ="subscriptions-button-div">
<a class="subscriptions-button" href="">
<lift:loc locid="subscriptions"><div class ="subscriptions-button-text">Subscriptions</div></lift:loc>
</a>
</div>
</div>

<div id="for-banks" name="for-banks" data-lift="WebUI.forBanks" class="col-xs-12 col-sm-6">
Expand Down
5 changes: 5 additions & 0 deletions obp-api/src/main/webapp/templates-hidden/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@
<lift:loc locid="support">Support</lift:loc>
</a>
</li>
<li class="navitem" data-lift="WebUI.subscriptionsButton" >
<a class="navlink subscriptions-button" href="">
<lift:loc locid="subscriptions"><div class ="subscriptions-button-text"></div></lift:loc>
</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<!-- login state -->
Expand Down
32 changes: 29 additions & 3 deletions obp-api/src/test/scala/code/util/HelperTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
package code.util


import code.api.Constant.ALL_CONSUMERS
import code.api.util._
import code.setup.PropsReset
import org.scalatest.{FeatureSpec, GivenWhenThen, Matchers}


class HelperTest extends FeatureSpec with Matchers with GivenWhenThen with PropsReset {

feature("test APIUtil.getStaticPortionOfRedirectURL method") {
feature("test Helper.getStaticPortionOfRedirectURL method") {
// The redirectURl is `http://localhost:8082/oauthcallback`
val testString1 = "http://localhost:8082/oauthcallback?oauth_token=G5AEA2U1WG404EGHTIGBHKRR4YJZAPPHWKOMNEEV&oauth_verifier=53018"
val testString2 = "http://localhost:8082?oauth_token=G5AEA2U1WG404EGHTIGBHKRR4YJZAPPHWKOMNEEV&oauth_verifier=53018"
Expand All @@ -50,7 +50,7 @@ class HelperTest extends FeatureSpec with Matchers with GivenWhenThen with Props
Helper.getStaticPortionOfRedirectURL(testString5).head should be("http://127.0.0.1:8000/oauth/authorize")
}

feature("test APIUtil.getHostOnlyOfRedirectURL method") {
feature("test Helper.getHostOnlyOfRedirectURL method") {
// The redirectURl is `http://localhost:8082/oauthcallback`
val testString1 = "http://localhost:8082/oauthcallback?oauth_token=G5AEA2U1WG404EGHTIGBHKRR4YJZAPPHWKOMNEEV&oauth_verifier=53018"
val testString2 = "http://localhost:8082/oauthcallback"
Expand All @@ -63,4 +63,30 @@ class HelperTest extends FeatureSpec with Matchers with GivenWhenThen with Props
Helper.getHostOnlyOfRedirectURL(testString4).head should be("http://localhost:8082")
}

feature(s"test Helper.getIfNotExistsAddedColumLengthForMsSqlServer method") {

scenario(s"test case 1") {
val expectedValue =
s"""
|IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'accountaccess' AND COLUMN_NAME = 'consumer_id')
|BEGIN
| ALTER TABLE accountaccess ADD consumer_id VARCHAR(255) DEFAULT '$ALL_CONSUMERS';
|END""".stripMargin

Helper.addColumnIfNotExists("accountaccess", "consumer_id", ALL_CONSUMERS) should be(expectedValue)
}

scenario(s"test case 2") {
val expectedValue =
s"""
|IF EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'accountaccess_bank_id_account_id_view_fk_user_fk' AND object_id = OBJECT_ID('accountaccess'))
|BEGIN
| DROP INDEX accountaccess.accountaccess_bank_id_account_id_view_fk_user_fk;
|END""".stripMargin

Helper.dropIndexIfExists("accountaccess", "accountaccess_bank_id_account_id_view_fk_user_fk") should be(expectedValue)
}

}

}

0 comments on commit 5bf3f7f

Please sign in to comment.