add created by
This commit is contained in:
@@ -14,6 +14,7 @@ from api_gateway import JSONResponse
|
||||
from boto3clients import dynamodb_client
|
||||
from config import INTERNAL_EMAIL_DOMAIN, USER_TABLE
|
||||
from exceptions import ConflictError
|
||||
from middlewares.authentication_middleware import User as Authenticated
|
||||
|
||||
router = Router()
|
||||
dyn = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
|
||||
@@ -53,8 +54,9 @@ def add(
|
||||
org: Annotated[Org, Body(embed=True)],
|
||||
):
|
||||
org.id = org_id
|
||||
created_by: Authenticated = router.context['user']
|
||||
|
||||
if _create_user(user, org):
|
||||
if _create_user(user, org, created_by):
|
||||
return JSONResponse(HTTPStatus.CREATED)
|
||||
|
||||
user_id = _get_user_id(user)
|
||||
@@ -101,7 +103,11 @@ def unlink(org_id: str, user_id: str):
|
||||
return JSONResponse(HTTPStatus.NO_CONTENT)
|
||||
|
||||
|
||||
def _create_user(user: User, org: Org) -> bool:
|
||||
def _create_user(
|
||||
user: User,
|
||||
org: Org,
|
||||
created_by: Authenticated,
|
||||
) -> bool:
|
||||
now_ = now()
|
||||
user_id = uuid4()
|
||||
email_verified = INTERNAL_EMAIL_DOMAIN in user.email
|
||||
@@ -130,6 +136,17 @@ def _create_user(user: User, org: Org) -> bool:
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': user_id,
|
||||
'sk': 'CREATED_BY',
|
||||
'created_by': {
|
||||
'id': created_by.id,
|
||||
'name': created_by.name,
|
||||
},
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': user_id,
|
||||
|
||||
Reference in New Issue
Block a user