add default org
This commit is contained in:
@@ -16,6 +16,7 @@ from exceptions import (
|
||||
CPFConflictError,
|
||||
EmailConflictError,
|
||||
OrgNotFoundError,
|
||||
SubscriptionFrozenError,
|
||||
UserConflictError,
|
||||
UserNotFoundError,
|
||||
)
|
||||
@@ -107,6 +108,14 @@ def _create_user(
|
||||
|
||||
try:
|
||||
with dyn.transact_writer() as transact:
|
||||
transact.condition(
|
||||
key=KeyPair(
|
||||
pk='SUBSCRIPTION#FROZEN',
|
||||
sk=f'ORG#{org.id}',
|
||||
),
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
exc_cls=SubscriptionFrozenError,
|
||||
)
|
||||
transact.put(
|
||||
item=user.model_dump()
|
||||
| {
|
||||
@@ -223,6 +232,14 @@ def _add_member(user_id: str, org: Org) -> None:
|
||||
now_ = now()
|
||||
|
||||
with dyn.transact_writer() as transact:
|
||||
transact.condition(
|
||||
key=KeyPair(
|
||||
pk='SUBSCRIPTION#FROZEN',
|
||||
sk=f'ORG#{org.id}',
|
||||
),
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
exc_cls=SubscriptionFrozenError,
|
||||
)
|
||||
transact.update(
|
||||
key=KeyPair(user_id, '0'),
|
||||
# Post-migration (users): uncomment the following line
|
||||
|
||||
@@ -17,9 +17,20 @@ def get_orgs(
|
||||
start_key: Annotated[str | None, Query] = None,
|
||||
limit: Annotated[int, Query(ge=25)] = 25,
|
||||
):
|
||||
return dyn.collection.query(
|
||||
# Post-migration (users): rename `orgs#` to `ORG#`
|
||||
r = dyn.collection.query(
|
||||
# Post-migration (users): uncomment the following line
|
||||
# key=KeyPair(user_id, 'ORG#'),
|
||||
key=KeyPair(user_id, 'orgs#'),
|
||||
start_key=start_key,
|
||||
limit=limit,
|
||||
)
|
||||
|
||||
preferred, items = None, []
|
||||
|
||||
for x in r['items']:
|
||||
if 'DEFAULT' in x['sk']:
|
||||
preferred = x.get('org_id')
|
||||
else:
|
||||
items.append(x)
|
||||
|
||||
return r | {'items': items} | ({'preferred_org_id': preferred} if preferred else {})
|
||||
|
||||
@@ -18,3 +18,5 @@ def test_get_orgs(
|
||||
)
|
||||
|
||||
assert r['statusCode'] == HTTPStatus.OK
|
||||
|
||||
print(r['body'])
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
{"id": "213a6682-2c59-4404-9189-12eec0a846d4", "sk": "orgs#DEFAULT", "org_id": "f6000f79-6e5c-49a0-952f-3bda330ef278"}
|
||||
{"id": "213a6682-2c59-4404-9189-12eec0a846d4", "sk": "orgs#f6000f79-6e5c-49a0-952f-3bda330ef278", "name": "Banco do Brasil", "cnpj": "00000000000191"}
|
||||
// Users
|
||||
{"id": "15bacf02-1535-4bee-9022-19d106fd7518", "sk": "0", "name": "Sérgio R Siqueira", "email": "sergio@somosbeta.com.br", "emails": ["osergiosiqueira@gmail.com", "sergio@somosbeta.combr"], "cpf": "07879819908"}
|
||||
|
||||
Reference in New Issue
Block a user