add never logged to add user
This commit is contained in:
@@ -15,7 +15,7 @@ from pydantic import BaseModel, EmailStr, Field
|
||||
|
||||
from api_gateway import JSONResponse
|
||||
from boto3clients import dynamodb_client
|
||||
from config import USER_TABLE
|
||||
from config import INTERNAL_EMAIL_DOMAIN, USER_TABLE
|
||||
|
||||
router = Router()
|
||||
dyn = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
|
||||
@@ -33,21 +33,24 @@ class User(BaseModel):
|
||||
email: EmailStr
|
||||
|
||||
|
||||
class CPFConflictError(Exception): ...
|
||||
|
||||
|
||||
class EmailConflictError(Exception): ...
|
||||
|
||||
|
||||
class UserConflictError(ServiceError):
|
||||
class ConflictError(ServiceError):
|
||||
def __init__(self, msg: str | dict):
|
||||
super().__init__(HTTPStatus.CONFLICT, msg)
|
||||
|
||||
|
||||
class UserMissingError(NotFoundError): ...
|
||||
class CPFConflictError(ConflictError): ...
|
||||
|
||||
|
||||
class OrgMissingError(NotFoundError): ...
|
||||
class EmailConflictError(ConflictError): ...
|
||||
|
||||
|
||||
class UserConflictError(ConflictError): ...
|
||||
|
||||
|
||||
class UserNotFoundError(NotFoundError): ...
|
||||
|
||||
|
||||
class OrgNotFoundError(NotFoundError): ...
|
||||
|
||||
|
||||
@router.post('/<org_id>/users')
|
||||
@@ -103,13 +106,13 @@ def unlink(org_id: str, user_id: str):
|
||||
def _create_user(user: User, org: Org) -> bool:
|
||||
now_ = now()
|
||||
user_id = uuid4()
|
||||
email_verified = '@users.noreply.saladeaula.digital' in user.email
|
||||
email_verified = INTERNAL_EMAIL_DOMAIN in user.email
|
||||
|
||||
try:
|
||||
with dyn.transact_writer() as transact:
|
||||
transact.put(
|
||||
item={
|
||||
**user.model_dump(),
|
||||
item=user.model_dump()
|
||||
| {
|
||||
'id': user_id,
|
||||
'sk': '0',
|
||||
'email_verified': email_verified,
|
||||
@@ -119,6 +122,13 @@ def _create_user(user: User, org: Org) -> bool:
|
||||
'created_at': now_,
|
||||
},
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': user_id,
|
||||
'sk': 'NEVER_LOGGED',
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': user_id,
|
||||
@@ -188,7 +198,7 @@ def _create_user(user: User, org: Org) -> bool:
|
||||
transact.condition(
|
||||
key=KeyPair(org.id, '0'), # type: ignore
|
||||
cond_expr='attribute_exists(sk)',
|
||||
exc_cls=OrgMissingError,
|
||||
exc_cls=OrgNotFoundError,
|
||||
)
|
||||
except (CPFConflictError, EmailConflictError):
|
||||
return False
|
||||
@@ -202,14 +212,14 @@ def _add_member(user_id: str, org: Org) -> None:
|
||||
with dyn.transact_writer() as transact:
|
||||
transact.update(
|
||||
key=KeyPair(user_id, '0'),
|
||||
update_expr='ADD tenant_id :org_id',
|
||||
# Post-migration: uncomment the following line
|
||||
# update_expr='ADD tenant_id :org_id',
|
||||
update_expr='ADD tenant_id :org_id',
|
||||
expr_attr_values={
|
||||
':org_id': {org.id},
|
||||
},
|
||||
cond_expr='attribute_exists(sk)',
|
||||
exc_cls=UserMissingError,
|
||||
exc_cls=UserNotFoundError,
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
@@ -234,7 +244,7 @@ def _add_member(user_id: str, org: Org) -> None:
|
||||
transact.condition(
|
||||
key=KeyPair(org.id, '0'), # type: ignore
|
||||
cond_expr='attribute_exists(sk)',
|
||||
exc_cls=OrgMissingError,
|
||||
exc_cls=OrgNotFoundError,
|
||||
)
|
||||
|
||||
|
||||
@@ -254,6 +264,6 @@ def _get_user_id(user: User) -> str:
|
||||
).get('id')
|
||||
|
||||
if not user_id:
|
||||
raise UserMissingError()
|
||||
raise UserNotFoundError('User not found')
|
||||
|
||||
return user_id
|
||||
|
||||
Reference in New Issue
Block a user