fix user
This commit is contained in:
@@ -32,11 +32,8 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
email=new_image['email'],
|
||||
cpf=new_image.get('cpf', None),
|
||||
)
|
||||
except konviva.EmailAlreadyExists:
|
||||
logger.info(
|
||||
'Email already exists, retrieving existing user',
|
||||
email=new_image['email'],
|
||||
)
|
||||
except konviva.EmailAlreadyExists as exc:
|
||||
logger.exception(exc, email=new_image['email'])
|
||||
|
||||
r = konviva.get_users_by_email(new_image['email'])
|
||||
user_id = glom(r, '0.IDUsuario')
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import random
|
||||
import string
|
||||
from dataclasses import dataclass
|
||||
from urllib.parse import quote_plus, urlparse
|
||||
|
||||
import requests
|
||||
from aws_lambda_powertools.event_handler.exceptions import BadRequestError
|
||||
from glom import glom
|
||||
from layercake.strutils import random_str
|
||||
|
||||
from config import KONVIVA_API_URL, KONVIVA_SECRET_KEY
|
||||
|
||||
@@ -19,16 +18,11 @@ headers = {
|
||||
}
|
||||
|
||||
|
||||
def random_str(maxlen: int = 10) -> str:
|
||||
"""Returns a random string of letters."""
|
||||
return ''.join(random.choice(string.ascii_letters) for _ in range(maxlen))
|
||||
|
||||
|
||||
class KonvivaError(BadRequestError):
|
||||
pass
|
||||
|
||||
|
||||
class EmailAlreadyExists(KonvivaError):
|
||||
class EmailAlreadyExistsError(KonvivaError):
|
||||
pass
|
||||
|
||||
|
||||
@@ -77,7 +71,11 @@ def create_user(
|
||||
# Because Konviva does not return the proper HTTP status code
|
||||
if err := glom(r.json(), 'errors', default=None):
|
||||
err = err[0] if isinstance(err, list) else err
|
||||
raise EmailAlreadyExists(err)
|
||||
|
||||
if err == 'Login já existente':
|
||||
raise EmailAlreadyExistsError(err)
|
||||
else:
|
||||
raise KonvivaError(err)
|
||||
|
||||
return r.json().get('IDUsuario')
|
||||
|
||||
@@ -85,7 +83,7 @@ def create_user(
|
||||
def get_users_by_email(email: str) -> list[dict]:
|
||||
url = urlparse(KONVIVA_API_URL)._replace(
|
||||
path='/action/api/getUsuariosByQuery',
|
||||
query=f'q=Email=={quote_plus(email)}',
|
||||
query=f'q=Email=={quote_plus(email)} or Login=={quote_plus(email)}',
|
||||
)
|
||||
r = requests.get(
|
||||
url=url.geturl(),
|
||||
|
||||
Reference in New Issue
Block a user