mirror of
https://github.com/clearml/clearml-server
synced 2025-01-31 10:56:48 +00:00
Add user creation time to users.get_current_user
This commit is contained in:
parent
ab495ae586
commit
68a54c34f3
@ -139,11 +139,20 @@ get_current_user {
|
||||
}
|
||||
}
|
||||
}
|
||||
"999.0": ${get_current_user."2.1"} {
|
||||
response.properties.getting_started {
|
||||
type: object
|
||||
description: Getting stated info
|
||||
additionalProperties: true
|
||||
"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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,29 +95,36 @@ 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"):
|
||||
projection = (
|
||||
{"company.name"}
|
||||
.union(User.get_fields())
|
||||
.difference(User.get_exclude_fields())
|
||||
)
|
||||
res = User.get_many_with_join(
|
||||
query=Q(id=call.identity.user),
|
||||
company=company_id,
|
||||
override_projection=projection,
|
||||
)
|
||||
user_id = call.identity.user
|
||||
|
||||
if not res:
|
||||
raise errors.bad_request.InvalidUser("failed loading user")
|
||||
projection = (
|
||||
{"company.name"}
|
||||
.union(User.get_fields())
|
||||
.difference(User.get_exclude_fields())
|
||||
)
|
||||
res = User.get_many_with_join(
|
||||
query=Q(id=user_id),
|
||||
company=company_id,
|
||||
override_projection=projection,
|
||||
)
|
||||
|
||||
user = res[0]
|
||||
user["role"] = call.identity.role
|
||||
if not res:
|
||||
raise errors.bad_request.InvalidUser("failed loading user")
|
||||
|
||||
resp = {
|
||||
"user": user,
|
||||
"getting_started": config.get("apiserver.getting_started_info", None),
|
||||
}
|
||||
call.result.data = resp
|
||||
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),
|
||||
}
|
||||
call.result.data = resp
|
||||
|
||||
|
||||
create_fields = {
|
||||
|
Loading…
Reference in New Issue
Block a user