add default org

This commit is contained in:
2026-01-20 14:39:57 -03:00
parent d88c84146c
commit b3e60aea65
11 changed files with 65 additions and 17 deletions

View File

@@ -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

View File

@@ -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 {})