check if subscription if not freeze
This commit is contained in:
@@ -6,7 +6,7 @@ from typing import Any, Literal, TypedDict
|
||||
from uuid import uuid4
|
||||
|
||||
from layercake.dateutils import now, ttl
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
|
||||
from layercake.extra_types import CpfStr, NameStr
|
||||
from layercake.strutils import md5_hash
|
||||
from pydantic import (
|
||||
@@ -18,7 +18,7 @@ from pydantic import (
|
||||
)
|
||||
from typing_extensions import NotRequired
|
||||
|
||||
from config import DEDUP_WINDOW_OFFSET_DAYS
|
||||
from config import DEDUP_WINDOW_OFFSET_DAYS, USER_TABLE
|
||||
|
||||
|
||||
class User(BaseModel):
|
||||
@@ -90,6 +90,16 @@ class DeduplicationConflictError(Exception):
|
||||
super().__init__('Enrollment already exists')
|
||||
|
||||
|
||||
class SubscriptionRequiredError(Exception):
|
||||
def __init__(self, msg: str | dict):
|
||||
super().__init__('Subscription required')
|
||||
|
||||
|
||||
class SubscriptionFrozenError(Exception):
|
||||
def __init__(self, msg: str | dict):
|
||||
super().__init__('Subscription is frozen')
|
||||
|
||||
|
||||
def enroll(
|
||||
enrollment: Enrollment,
|
||||
*,
|
||||
@@ -164,6 +174,7 @@ def enroll(
|
||||
)
|
||||
|
||||
if subscription:
|
||||
org_id = subscription['org_id']
|
||||
transact.put(
|
||||
item={
|
||||
'id': enrollment.id,
|
||||
@@ -172,6 +183,24 @@ def enroll(
|
||||
}
|
||||
| subscription,
|
||||
)
|
||||
transact.condition(
|
||||
key=KeyPair(
|
||||
pk='SUBSCRIPTION',
|
||||
sk=f'ORG#{org_id}',
|
||||
),
|
||||
cond_expr='attribute_exists(sk)',
|
||||
exc_cls=SubscriptionRequiredError,
|
||||
table_name=USER_TABLE,
|
||||
)
|
||||
transact.condition(
|
||||
key=KeyPair(
|
||||
pk='SUBSCRIPTION#FREEZE',
|
||||
sk=f'ORG#{org_id}',
|
||||
),
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
exc_cls=SubscriptionFrozenError,
|
||||
table_name=USER_TABLE,
|
||||
)
|
||||
|
||||
if created_by:
|
||||
transact.put(
|
||||
|
||||
Reference in New Issue
Block a user