Add user creation time to users.get_current_user

This commit is contained in:
allegroai 2022-07-08 17:59:45 +03:00
parent ab495ae586
commit 68a54c34f3
2 changed files with 42 additions and 26 deletions

View File

@ -139,12 +139,21 @@ get_current_user {
}
}
}
"999.0": ${get_current_user."2.1"} {
response.properties.getting_started {
"2.20": ${get_current_user."2.1"} {
response {
properties {
getting_started {
type: object
description: Getting stated info
additionalProperties: true
}
created {
type: string
description: User creation time
format: date-time
}
}
}
}
}

View File

@ -12,7 +12,7 @@ from apiserver.bll.project import ProjectBLL
from apiserver.bll.user import UserBLL
from apiserver.config_repo import config
from apiserver.database.errors import translate_errors_context
from apiserver.database.model.auth import Role
from apiserver.database.model.auth import Role, User as AuthUser
from apiserver.database.model.company import Company
from apiserver.database.model.user import User
from apiserver.database.utils import parse_from_call
@ -95,14 +95,15 @@ def get_all(call: APICall, company_id, _):
@endpoint("users.get_current_user")
def get_current_user(call: APICall, company_id, _):
with translate_errors_context("retrieving users"):
user_id = call.identity.user
projection = (
{"company.name"}
.union(User.get_fields())
.difference(User.get_exclude_fields())
)
res = User.get_many_with_join(
query=Q(id=call.identity.user),
query=Q(id=user_id),
company=company_id,
override_projection=projection,
)
@ -113,6 +114,12 @@ def get_current_user(call: APICall, company_id, _):
user = res[0]
user["role"] = call.identity.role
auth_user: AuthUser = AuthUser.objects(id=user_id, company=company_id).first()
if not auth_user:
raise errors.bad_request.InvalidUser("failed loading user")
user["created"] = auth_user.created
resp = {
"user": user,
"getting_started": config.get("apiserver.getting_started_info", None),