mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 15:27:01 +00:00
Added getUser endpoint that returns user by email address
This commit is contained in:
parent
17975dabd1
commit
024e14793d
@ -11,6 +11,7 @@ object ApiRole {
|
||||
case object CanSearchMetrics extends ApiRole
|
||||
case object CanCreateCustomer extends ApiRole
|
||||
case object CanCreateAccount extends ApiRole
|
||||
case object CanGetAnyUser extends ApiRole
|
||||
case object IsHackathonDeveloper extends ApiRole
|
||||
|
||||
def valueOf(value: String): ApiRole = value match {
|
||||
@ -21,6 +22,7 @@ object ApiRole {
|
||||
case "CanSearchMetrics" => CanSearchMetrics
|
||||
case "CanCreateCustomer" => CanCreateCustomer
|
||||
case "CanCreateAccount" => CanCreateAccount
|
||||
case "CanGetAnyUser" => CanGetAnyUser
|
||||
case "IsHackathonDeveloper" => IsHackathonDeveloper
|
||||
case _ => throw new IllegalArgumentException()
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ import code.api.v1_2_1.{APIMethods121, AmountOfMoneyJSON => AmountOfMoneyJSON121
|
||||
import code.api.v1_4_0.JSONFactory1_4_0.{ChallengeAnswerJSON, CustomerFaceImageJson, TransactionRequestAccountJSON}
|
||||
import code.entitlement.Entitlement
|
||||
import code.search.{elasticsearchMetrics, elasticsearchWarehouse}
|
||||
import net.liftweb.http.CurrentReq
|
||||
//import code.api.v2_0_0.{CreateCustomerJson}
|
||||
|
||||
import code.model.dataAccess.OBPUser
|
||||
@ -1583,6 +1584,48 @@ trait APIMethods200 {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
resourceDocs += ResourceDoc(
|
||||
getUser,
|
||||
apiVersion,
|
||||
"getUser",
|
||||
"GET",
|
||||
"/users/USER_EMAIL",
|
||||
"Get User by Email Address",
|
||||
"""Get the user by email address
|
||||
|
|
||||
|Login is required.
|
||||
|CanGetAnyUser entitlement is required,
|
||||
|
|
||||
""".stripMargin,
|
||||
emptyObjectJson,
|
||||
emptyObjectJson,
|
||||
emptyObjectJson :: Nil,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
List(apiTagUser))
|
||||
|
||||
|
||||
lazy val getUser: PartialFunction[Req, Box[User] => Box[JsonResponse]] = {
|
||||
case "users" :: userEmail :: Nil JsonGet _ => {
|
||||
user =>
|
||||
for {
|
||||
l <- user ?~ ErrorMessages.UserNotLoggedIn
|
||||
b <- Bank.all.headOption //TODO: This is a temp workaround
|
||||
canGetAnyUser <- booleanToBox(hasEntitlement(b.bankId.value, l.userId, ApiRole.CanGetAnyUser), "CanGetAnyUser entitlement required")
|
||||
// Workaround to get userEmail address directly from URI without needing to URL-encode it
|
||||
u <- OBPUser.getApiUserByEmail(CurrentReq.value.uri.split("/").last)
|
||||
}
|
||||
yield {
|
||||
// Format the data as V2.0.0 json
|
||||
val json = JSONFactory200.createUserJSON(u)
|
||||
successJsonResponse(Extraction.decompose(json))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
resourceDocs += ResourceDoc(
|
||||
createUserCustomerLinks,
|
||||
apiVersion,
|
||||
|
||||
@ -170,6 +170,7 @@ object OBPAPI2_0_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w
|
||||
Implementations2_0_0.getMeeting,
|
||||
Implementations2_0_0.createCustomer,
|
||||
Implementations2_0_0.getCurrentUser,
|
||||
Implementations2_0_0.getUser,
|
||||
Implementations2_0_0.createUserCustomerLinks,
|
||||
Implementations2_0_0.addEntitlement,
|
||||
Implementations2_0_0.getEntitlements,
|
||||
@ -179,13 +180,6 @@ object OBPAPI2_0_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w
|
||||
Implementations2_0_0.elasticSearchMetrics
|
||||
)
|
||||
|
||||
// if (Props.getBool("allow_elasticsearch", false)) {
|
||||
// if (Props.getBool("allow_elasticsearch_warehouse", false))
|
||||
// routes = Implementations2_0_0.elasticSearchWarehouse :: routes
|
||||
// if (Props.getBool("allow_elasticsearch_metrics", false))
|
||||
// routes = Implementations2_0_0.elasticSearchMetrics :: routes
|
||||
// }
|
||||
|
||||
routes.foreach(route => {
|
||||
oauthServe(apiPrefix{route})
|
||||
})
|
||||
|
||||
@ -92,6 +92,10 @@ class OBPUser extends MegaProtoUser[OBPUser] with Logger {
|
||||
.providerId(email)
|
||||
}
|
||||
|
||||
def getApiUserByEmail(userEmail: String) : Box[APIUser] = {
|
||||
APIUser.find(By(APIUser.email, userEmail))
|
||||
}
|
||||
|
||||
override def save(): Boolean = {
|
||||
if(! (user defined_?)){
|
||||
info("user reference is null. We will create an API User")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user