mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 20:27:15 +00:00
move some methods into APIUtil
This commit is contained in:
parent
92b17465d3
commit
ce046cb44f
@ -33,9 +33,8 @@
|
||||
package code.api.util
|
||||
|
||||
import java.io.InputStream
|
||||
import java.nio.charset.{Charset, StandardCharsets}
|
||||
import java.nio.charset.Charset
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util
|
||||
import java.util.{Date, UUID}
|
||||
|
||||
import code.api.Constant._
|
||||
@ -2275,5 +2274,13 @@ Versions are groups of endpoints in a file
|
||||
def getPropsAsLongValue(nameOfProperty: String, defaultValue: Long): Long = {
|
||||
getPropsAsLongValue(nameOfProperty) openOr(defaultValue)
|
||||
}
|
||||
|
||||
|
||||
|
||||
val ALLOW_PUBLIC_VIEWS: Boolean = getPropsAsBoolValue("allow_public_views", false)
|
||||
val ALLOW_FIREHOSE_VIEWS: Boolean = getPropsAsBoolValue("allow_firehose_views", false)
|
||||
def canUseFirehose(user: User): Boolean = {
|
||||
ALLOW_FIREHOSE_VIEWS && hasEntitlement("", user.userId, ApiRole.canUseFirehoseAtAnyBank)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -423,7 +423,7 @@ trait APIMethods300 {
|
||||
(user, callContext) <- extractCallContext(UserNotLoggedIn, cc)
|
||||
u <- unboxFullAndWrapIntoFuture{ user }
|
||||
_ <- Helper.booleanToFuture(failMsg = FirehoseViewsNotAllowedOnThisInstance +" or " + UserHasMissingRoles + CanUseFirehoseAtAnyBank ) {
|
||||
MapperViews.canUseFirehose(u)
|
||||
canUseFirehose(u)
|
||||
}
|
||||
bankBox <- Future { Bank(bankId) } map {x => fullBoxOrException(x ?~! BankNotFound)}
|
||||
bank<- unboxFullAndWrapIntoFuture(bankBox)
|
||||
@ -475,7 +475,7 @@ trait APIMethods300 {
|
||||
(user, callContext) <- extractCallContext(UserNotLoggedIn, cc)
|
||||
u <- unboxFullAndWrapIntoFuture{ user }
|
||||
_ <- Helper.booleanToFuture(failMsg = FirehoseViewsNotAllowedOnThisInstance +" or " + UserHasMissingRoles + CanUseFirehoseAtAnyBank ) {
|
||||
MapperViews.canUseFirehose(u)
|
||||
canUseFirehose(u)
|
||||
}
|
||||
bankAccount <- Future { BankAccount(bankId, accountId, callContext) } map {
|
||||
x => fullBoxOrException(x ?~! BankAccountNotFound)
|
||||
|
||||
@ -398,7 +398,7 @@ trait BankAccount extends MdcLoggable {
|
||||
true
|
||||
else
|
||||
user match {
|
||||
case Some(u) if view.isFirehose && MapperViews.canUseFirehose(u) =>
|
||||
case Some(u) if view.isFirehose && APIUtil.canUseFirehose(u) =>
|
||||
true
|
||||
case Some(u) =>
|
||||
u.permittedView(view)
|
||||
|
||||
@ -32,16 +32,16 @@ Berlin 13359, Germany
|
||||
|
||||
package code.model
|
||||
|
||||
import code.util.Helper
|
||||
import net.liftweb.json.JsonDSL._
|
||||
import net.liftweb.json.JsonAST.JObject
|
||||
import net.liftweb.common.{Box, Failure, Full}
|
||||
import code.api.UserNotFound
|
||||
import code.views.Views
|
||||
import code.entitlement.Entitlement
|
||||
import code.model.dataAccess.{ResourceUser, ViewImpl, ViewPrivileges}
|
||||
import code.users.Users
|
||||
import code.util.Helper
|
||||
import code.util.Helper.MdcLoggable
|
||||
import code.views.Views
|
||||
import net.liftweb.common.{Box, Failure, Full}
|
||||
import net.liftweb.json.JsonAST.JObject
|
||||
import net.liftweb.json.JsonDSL._
|
||||
import net.liftweb.mapper.By
|
||||
|
||||
case class UserId(val value : Long) {
|
||||
|
||||
@ -1,25 +1,22 @@
|
||||
package code.views
|
||||
|
||||
import bootstrap.liftweb.ToSchemify
|
||||
import code.accountholder.{AccountHolders, MapperAccountHolders}
|
||||
import code.accountholder.MapperAccountHolders
|
||||
import code.api.APIFailure
|
||||
import code.api.util.{APIUtil, ApiRole}
|
||||
import code.api.util.APIUtil._
|
||||
import code.api.util.ApiRole
|
||||
import code.api.util.ErrorMessages._
|
||||
import code.model.dataAccess.ViewImpl.create
|
||||
import code.model.dataAccess.{ResourceUser, ViewImpl, ViewPrivileges}
|
||||
import code.model.dataAccess.{ViewImpl, ViewPrivileges}
|
||||
import code.model.{CreateViewJson, Permission, UpdateViewJSON, User, _}
|
||||
import code.util.Helper.MdcLoggable
|
||||
import net.liftweb.common._
|
||||
import net.liftweb.mapper.{By, Schemifier}
|
||||
import net.liftweb.util.Helpers._
|
||||
import code.api.util.ErrorMessages._
|
||||
|
||||
import scala.collection.immutable.List
|
||||
import code.util.Helper.MdcLoggable
|
||||
import net.liftweb.util.Props
|
||||
import code.api.util.ErrorMessages._
|
||||
import code.views.MapperViews.canUseFirehose
|
||||
|
||||
import scala.concurrent.Future
|
||||
import scala.concurrent.ExecutionContext.Implicits.global
|
||||
import scala.concurrent.Future
|
||||
|
||||
//TODO: Replace BankAccountUIDs with bankPermalink + accountPermalink
|
||||
|
||||
@ -27,9 +24,6 @@ import scala.concurrent.ExecutionContext.Implicits.global
|
||||
object MapperViews extends Views with MdcLoggable {
|
||||
|
||||
Schemifier.schemify(true, Schemifier.infoF _, ToSchemify.modelsRemotedata: _*)
|
||||
|
||||
val ALLOW_PUBLIC_VIEWS: Boolean = APIUtil.getPropsAsBoolValue("allow_public_views", false)
|
||||
val ALLOW_FIREHOSE_VIEWS: Boolean = APIUtil.getPropsAsBoolValue("allow_firehose_views", false)
|
||||
|
||||
def permissions(account : BankIdAccountId) : List[Permission] = {
|
||||
|
||||
@ -406,9 +400,7 @@ object MapperViews extends Views with MdcLoggable {
|
||||
Nil
|
||||
}
|
||||
}
|
||||
def canUseFirehose(user: User): Boolean = {
|
||||
ALLOW_FIREHOSE_VIEWS && user.assignedEntitlements.map(_.roleName).contains(ApiRole.canUseFirehoseAtAnyBank.toString())
|
||||
}
|
||||
|
||||
/**
|
||||
* @param user
|
||||
* @return the bank accounts the @user can see (public + private if @user is Full, public if @user is Empty)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user