mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 19:16:53 +00:00
Added isSystem in view trait, modify the create and update views endpoints
This commit is contained in:
parent
d14893af74
commit
86e6f3fd5a
@ -44,7 +44,7 @@ object SwaggerDefinitionsJSON {
|
||||
)
|
||||
|
||||
val createViewJson = CreateViewJson(
|
||||
name = "test",
|
||||
name = "_test",
|
||||
description = "good",
|
||||
is_public = true,
|
||||
which_alias_to_use = "good",
|
||||
|
||||
@ -156,6 +156,8 @@ import code.api.util.APIUtil._
|
||||
|
||||
val InvalidInternalRedirectUrl = "OBP-20018: Login failed, invalid internal redirectUrl."
|
||||
val UserNoOwnerView = "OBP-20019: User does not have access to owner view. "
|
||||
val InvalidCustomViewFormat = "OBP-20020: View name must start with `_`. eg: _work, _life "
|
||||
val SystemViewsCanNotBeModified = "OBP-20021: System Views can not be modified. Only the created views can be modified."
|
||||
|
||||
|
||||
|
||||
|
||||
@ -30,6 +30,7 @@ import net.liftweb.json.Extraction._
|
||||
import scalacache.{memoization}
|
||||
import scalacache.memoization.memoizeSync
|
||||
import code.api.util.APIUtil._
|
||||
import code.util.Helper.booleanToBox
|
||||
|
||||
trait APIMethods121 {
|
||||
//needs to be a RestHelper to get access to JsonGet, JsonPost, etc.
|
||||
@ -539,6 +540,8 @@ trait APIMethods121 {
|
||||
for {
|
||||
u <- user ?~ UserNotLoggedIn
|
||||
json <- tryo{json.extract[CreateViewJson]} ?~ InvalidJsonFormat
|
||||
//customer views are started ith `_`,eg _lift, _work, and System views startWith letter, eg: owner
|
||||
_<- booleanToBox(json.name.startsWith("_"), InvalidCustomViewFormat)
|
||||
account <- BankAccount(bankId, accountId) ?~! BankAccountNotFound
|
||||
view <- account createView (u, json)
|
||||
} yield {
|
||||
@ -583,6 +586,10 @@ trait APIMethods121 {
|
||||
updateJson <- tryo{ json.extract[UpdateViewJSON] } ?~ InvalidJsonFormat
|
||||
account <- BankAccount(bankId, accountId) ?~! BankAccountNotFound
|
||||
u <- user ?~ UserNotLoggedIn
|
||||
//customer views are started ith `_`,eg _lift, _work, and System views startWith letter, eg: owner
|
||||
_ <- booleanToBox(viewId.value.startsWith("_"), InvalidCustomViewFormat)
|
||||
view <- View.fromUrl(viewId, accountId, bankId)?~! ViewNotFound
|
||||
_ <- booleanToBox(!view.isSystem, SystemViewsCanNotBeModified)
|
||||
updatedView <- account.updateView(u, viewId, updateJson)
|
||||
} yield {
|
||||
val viewJSON = JSONFactory.createViewJSON(updatedView)
|
||||
|
||||
@ -180,6 +180,8 @@ trait APIMethods220 {
|
||||
user =>
|
||||
for {
|
||||
json <- tryo{json.extract[CreateViewJson]} ?~!InvalidJsonFormat
|
||||
//customer views are started ith `_`,eg _lift, _work, and System views startWith letter, eg: owner
|
||||
_<- booleanToBox(json.name.startsWith("_"), InvalidCustomViewFormat)
|
||||
u <- user ?~!UserNotLoggedIn
|
||||
account <- BankAccount(bankId, accountId) ?~! BankAccountNotFound
|
||||
view <- account createView (u, json)
|
||||
@ -222,6 +224,10 @@ trait APIMethods220 {
|
||||
user =>
|
||||
for {
|
||||
updateJson <- tryo{json.extract[UpdateViewJSON]} ?~!InvalidJsonFormat
|
||||
//customer views are started ith `_`,eg _lift, _work, and System views startWith letter, eg: owner
|
||||
_ <- booleanToBox(viewId.value.startsWith("_"), InvalidCustomViewFormat)
|
||||
view <- View.fromUrl(viewId, accountId, bankId)?~! ViewNotFound
|
||||
_ <- booleanToBox(!view.isSystem, SystemViewsCanNotBeModified)
|
||||
u <- user ?~!UserNotLoggedIn
|
||||
account <- BankAccount(bankId, accountId) ?~!BankAccountNotFound
|
||||
updatedView <- account.updateView(u, viewId, updateJson)
|
||||
|
||||
@ -182,6 +182,8 @@ trait APIMethods300 {
|
||||
user =>
|
||||
for {
|
||||
json <- tryo{json.extract[CreateViewJson]} ?~!InvalidJsonFormat
|
||||
//customer views are started ith `_`,eg _lift, _work, and System views startWith letter, eg: owner
|
||||
_<- booleanToBox(json.name.startsWith("_"), InvalidCustomViewFormat)
|
||||
u <- user ?~!UserNotLoggedIn
|
||||
account <- BankAccount(bankId, accountId) ?~! BankAccountNotFound
|
||||
view <- account createView (u, json)
|
||||
@ -224,6 +226,10 @@ trait APIMethods300 {
|
||||
user =>
|
||||
for {
|
||||
updateJson <- tryo{json.extract[UpdateViewJSON]} ?~!InvalidJsonFormat
|
||||
//customer views are started ith `_`,eg _lift, _work, and System views startWith letter, eg: owner
|
||||
_ <- booleanToBox(viewId.value.startsWith("_"), InvalidCustomViewFormat)
|
||||
view <- View.fromUrl(viewId, accountId, bankId)?~! ViewNotFound
|
||||
_ <- booleanToBox(!view.isSystem, SystemViewsCanNotBeModified)
|
||||
u <- user ?~!UserNotLoggedIn
|
||||
account <- BankAccount(bankId, accountId) ?~!BankAccountNotFound
|
||||
updatedView <- account.updateView(u, viewId, updateJson)
|
||||
|
||||
@ -195,6 +195,12 @@ trait View {
|
||||
val viewLogger = Logger(classOf[View])
|
||||
//e.g. "Public", "Authorities", "Our Network", etc.
|
||||
|
||||
//This is used for distinguishing all the views
|
||||
//For now, we need have some system views and user created views.
|
||||
// System Views: eg: owner, accountant ... They are the fixed views, account owner can not modify it.
|
||||
// User Created Views: Start with _, eg _son, _wife ... The owner can update the fields for these views.
|
||||
def isSystem : Boolean
|
||||
|
||||
//these ids are used together to uniquely identify a view
|
||||
def viewId : ViewId
|
||||
def accountId : AccountId
|
||||
|
||||
@ -163,6 +163,10 @@ class ViewImpl extends View with LongKeyedMapper[ViewImpl] with ManyToMany with
|
||||
canAddTransactionRequestToAnyAccount_(actions.exists(_ == "can_add_transaction_request_to_any_account"))
|
||||
}
|
||||
|
||||
object isSystem_ extends MappedBoolean(this){
|
||||
override def defaultValue = false
|
||||
override def dbIndexed_? = true
|
||||
}
|
||||
|
||||
object isPublic_ extends MappedBoolean(this){
|
||||
override def defaultValue = false
|
||||
@ -396,6 +400,7 @@ class ViewImpl extends View with LongKeyedMapper[ViewImpl] with ManyToMany with
|
||||
}
|
||||
|
||||
def id: Long = id_.get
|
||||
def isSystem: Boolean = isSystem_.get
|
||||
|
||||
def viewId : ViewId = ViewId(permalink_.get)
|
||||
def accountId : AccountId = AccountId(accountPermalink.get)
|
||||
|
||||
@ -239,7 +239,7 @@ object MapperViews extends Views with MdcLoggable {
|
||||
if(view.name.contentEquals("")) {
|
||||
return Failure("You cannot create a View with an empty Name")
|
||||
}
|
||||
|
||||
//view-permalink is view.name without spaces. (view.name = my life) <---> (view-permalink = mylife)
|
||||
val newViewPermalink = {
|
||||
view.name.replaceAllLiterally(" ", "").toLowerCase
|
||||
}
|
||||
@ -517,6 +517,7 @@ object MapperViews extends Views with MdcLoggable {
|
||||
|
||||
def createRandomView(bankId: BankId, accountId: AccountId) : Box[View] = {
|
||||
Full(ViewImpl.create.
|
||||
isSystem_(false).
|
||||
name_(randomString(5)).
|
||||
description_(randomString(3)).
|
||||
permalink_(randomString(3)).
|
||||
@ -722,6 +723,7 @@ object MapperViews extends Views with MdcLoggable {
|
||||
|
||||
def unsavedOwnerView(bankId : BankId, accountId: AccountId, description: String) : ViewImpl = {
|
||||
create
|
||||
.isSystem_(true)
|
||||
.bankPermalink(bankId.value)
|
||||
.accountPermalink(accountId.value)
|
||||
.name_("Owner")
|
||||
@ -812,6 +814,7 @@ object MapperViews extends Views with MdcLoggable {
|
||||
|
||||
def unsavedDefaultPublicView(bankId : BankId, accountId: AccountId, description: String) : ViewImpl = {
|
||||
create.
|
||||
isSystem_(true).
|
||||
name_("Public").
|
||||
description_(description).
|
||||
permalink_("public").
|
||||
@ -907,6 +910,7 @@ object MapperViews extends Views with MdcLoggable {
|
||||
|
||||
def unsavedDefaultAccountantsView(bankId : BankId, accountId: AccountId, description: String) : ViewImpl = {
|
||||
create.
|
||||
isSystem_(true).
|
||||
name_("Accountant"). // Use the singular form
|
||||
description_(description).
|
||||
permalink_("accountant"). // Use the singular form
|
||||
@ -1001,6 +1005,7 @@ Auditors
|
||||
|
||||
def unsavedDefaultAuditorsView(bankId : BankId, accountId: AccountId, description: String) : ViewImpl = {
|
||||
create.
|
||||
isSystem_(true).
|
||||
name_("Auditor"). // Use the singular form
|
||||
description_(description).
|
||||
permalink_("auditor"). // Use the singular form
|
||||
|
||||
@ -237,7 +237,7 @@ class API1_2_1Test extends User1AllPrivileges with DefaultUsers with PrivateUser
|
||||
|
||||
def randomView(isPublic: Boolean, alias: String) : CreateViewJson = {
|
||||
CreateViewJson(
|
||||
name = randomString(3),
|
||||
name = "_"+randomString(3),//Now, all created views should start with `_`.
|
||||
description = randomString(3),
|
||||
is_public = isPublic,
|
||||
which_alias_to_use=alias,
|
||||
@ -1537,7 +1537,7 @@ class API1_2_1Test extends User1AllPrivileges with DefaultUsers with PrivateUser
|
||||
val bankAccount : AccountJSON = randomPrivateAccount(bankId)
|
||||
|
||||
Given("a view does not exist")
|
||||
val nonExistantViewId = "asdfasdfasdfasdfasdf"
|
||||
val nonExistantViewId = "_asdfasdfasdfasdfasdf"
|
||||
val getReply = getAccountViews(bankId, bankAccount.id, user1)
|
||||
getReply.code should equal (200)
|
||||
val views : ViewsJSONV121 = getReply.body.extract[ViewsJSONV121]
|
||||
@ -1545,8 +1545,8 @@ class API1_2_1Test extends User1AllPrivileges with DefaultUsers with PrivateUser
|
||||
|
||||
When("we try to update that view")
|
||||
val reply = putView(bankId, bankAccount.id, nonExistantViewId, someViewUpdateJson(), user1)
|
||||
Then("We should get a 404")
|
||||
reply.code should equal(404)
|
||||
Then("We should get a 400")
|
||||
reply.code should equal(400)
|
||||
}
|
||||
|
||||
scenario("We will not update a view on a bank account due to missing token", API1_2, PutView) {
|
||||
|
||||
@ -343,8 +343,8 @@ class API2_2_0Test extends User1AllPrivileges with V220ServerSetup with DefaultU
|
||||
|
||||
When("we try to update that view")
|
||||
val reply = putView(bankId, bankAccountId, nonExistantViewId, someViewUpdateJson(), user1)
|
||||
Then("We should get a 404")
|
||||
reply.code should equal(404)
|
||||
Then("We should get a 400")
|
||||
reply.code should equal(400)
|
||||
}
|
||||
|
||||
scenario("We will not update a view on a bank account due to missing token", API2_2, PutView) {
|
||||
|
||||
@ -250,8 +250,8 @@ class ViewsTests extends V300ServerSetup {
|
||||
|
||||
When("we try to update that view")
|
||||
val reply = putView(bankId, bankAccountId, nonExistantViewId, someViewUpdateJson(), user1)
|
||||
Then("We should get a 404")
|
||||
reply.code should equal(404)
|
||||
Then("We should get a 400")
|
||||
reply.code should equal(400)
|
||||
}
|
||||
|
||||
scenario("We will not update a view on a bank account due to missing token") {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user