@@ -5,12 +5,18 @@ import code.api.util.APIUtil._
55import code .api .util .ApiTag ._
66import code .api .util .ErrorMessages .{$UserNotLoggedIn , InvalidJsonFormat , UnknownError , _ }
77import code .api .util .FutureUtil .EndpointContext
8+ import code .api .util .NewStyle
9+ import code .api .util .NewStyle .HttpCode
810import code .bankconnectors .LocalMappedConnectorInternal
911import code .bankconnectors .LocalMappedConnectorInternal ._
12+ import code .entitlement .Entitlement
13+ import code .views .Views
1014import com .github .dwickern .macros .NameOf .nameOf
1115import com .openbankproject .commons .model ._
1216import com .openbankproject .commons .util .{ApiVersion , ScannedApiVersion }
17+ import net .liftweb .common .Full
1318import net .liftweb .http .rest .RestHelper
19+ import com .openbankproject .commons .ExecutionContext .Implicits .global
1420
1521import scala .collection .immutable .{List , Nil }
1622import scala .collection .mutable .ArrayBuffer
@@ -31,6 +37,46 @@ trait APIMethods600 {
3137 val apiRelations = ArrayBuffer [ApiRelation ]()
3238 val codeContext = CodeContext (staticResourceDocs, apiRelations)
3339
40+
41+ staticResourceDocs += ResourceDoc (
42+ getCurrentUser,
43+ implementedInApiVersion,
44+ nameOf(getCurrentUser), // TODO can we get this string from the val two lines above?
45+ " GET" ,
46+ " /users/current" ,
47+ " Get User (Current)" ,
48+ s """ Get the logged in user
49+ |
50+ | ${userAuthenticationMessage(true )}
51+ """ .stripMargin,
52+ EmptyBody ,
53+ userJsonV300,
54+ List (UserNotLoggedIn , UnknownError ),
55+ List (apiTagUser))
56+
57+ lazy val getCurrentUser : OBPEndpoint = {
58+ case " users" :: " current" :: Nil JsonGet _ => {
59+ cc => {
60+ implicit val ec = EndpointContext (Some (cc))
61+ for {
62+ (Full (u), callContext) <- authenticatedAccess(cc)
63+ entitlements <- NewStyle .function.getEntitlementsByUserId(u.userId, callContext)
64+ } yield {
65+ val permissions : Option [Permission ] = Views .views.vend.getPermissionForUser(u).toOption
66+ val currentUser = UserV600 (u, entitlements, permissions)
67+ val onBehalfOfUser = if (cc.onBehalfOfUser.isDefined) {
68+ val entitlements = Entitlement .entitlement.vend.getEntitlementsByUserId(cc.onBehalfOfUser.get.userId).headOption.toList.flatten
69+ val permissions : Option [Permission ] = Views .views.vend.getPermissionForUser(cc.onBehalfOfUser.get).toOption
70+ Some (UserV600 (cc.onBehalfOfUser.get, entitlements, permissions))
71+ } else {
72+ None
73+ }
74+ (JSONFactory600 .createUserInfoJSON(currentUser, onBehalfOfUser), HttpCode .`200`(callContext))
75+ }
76+ }
77+ }
78+ }
79+
3480 staticResourceDocs += ResourceDoc (
3581 createTransactionRequestCardano,
3682 implementedInApiVersion,
0 commit comments