add test_mode

This commit is contained in:
2026-01-20 12:34:01 -03:00
parent 49e0c3333b
commit 1aa15aaddc
5 changed files with 72 additions and 2 deletions

View File

@@ -45,6 +45,7 @@ def get_org(org_id: str):
+ SortKey('METADATA#ADDRESS', rename_key='address') + SortKey('METADATA#ADDRESS', rename_key='address')
+ SortKey('METADATA#BILLING', rename_key='billing') + SortKey('METADATA#BILLING', rename_key='billing')
+ SortKey('METADATA#SUBSCRIPTION', rename_key='subscription') + SortKey('METADATA#SUBSCRIPTION', rename_key='subscription')
+ SortKey('METADATA#TEST_MODE', rename_key='test_mode')
+ KeyPair( + KeyPair(
pk='SUBSCRIPTION#FROZEN', pk='SUBSCRIPTION#FROZEN',
sk=SortKey(f'ORG#{org_id}'), sk=SortKey(f'ORG#{org_id}'),

View File

@@ -5,6 +5,7 @@ import {
BadgeCheckIcon, BadgeCheckIcon,
CheckIcon, CheckIcon,
ChevronsUpDownIcon, ChevronsUpDownIcon,
FlaskConicalIcon,
PlusIcon PlusIcon
} from 'lucide-react' } from 'lucide-react'
import { createContext, use } from 'react' import { createContext, use } from 'react'
@@ -54,7 +55,8 @@ export function WorkspaceProvider({
export function WorkspaceSwitcher() { export function WorkspaceSwitcher() {
const location = useLocation() const location = useLocation()
const { isMobile, state } = useSidebar() const { isMobile, state } = useSidebar()
const { activeWorkspace, workspaces, subscription } = useWorksapce() const { activeWorkspace, workspaces, subscription, test_mode } =
useWorksapce()
const [, fragment, _] = location.pathname.slice(1).split('/') const [, fragment, _] = location.pathname.slice(1).split('/')
const onSelect = (workspace: Workspace) => { const onSelect = (workspace: Workspace) => {
@@ -74,10 +76,14 @@ export function WorkspaceSwitcher() {
className="aria-expanded:border flex aspect-square size-8 items-center justify-center rounded-lg relative" className="aria-expanded:border flex aspect-square size-8 items-center justify-center rounded-lg relative"
aria-expanded={state === 'expanded'} aria-expanded={state === 'expanded'}
> >
{subscription ? ( {subscription && !test_mode ? (
<BadgeCheckIcon className="fill-blue-500 stroke-white absolute size-4 dark:size-3.5 -top-1.5 -right-1.5" /> <BadgeCheckIcon className="fill-blue-500 stroke-white absolute size-4 dark:size-3.5 -top-1.5 -right-1.5" />
) : null} ) : null}
{test_mode ? (
<FlaskConicalIcon className="absolute size-3.5 -top-1.5 -right-1.5" />
) : null}
{initials(activeWorkspace.name)} {initials(activeWorkspace.name)}
</div> </div>
<div className="grid flex-1 text-left text-sm leading-tight"> <div className="grid flex-1 text-left text-sm leading-tight">

View File

@@ -22,6 +22,7 @@ export type WorkspaceContextProps = {
workspaces: Workspace[] workspaces: Workspace[]
subscription: Subscription | null subscription: Subscription | null
address: Address | null address: Address | null
test_mode: boolean
} }
export const workspaceContext = createContext< export const workspaceContext = createContext<
@@ -66,6 +67,7 @@ export const workspaceMiddleware = async (
workspaces, workspaces,
subscription: org?.['subscription'] || null, subscription: org?.['subscription'] || null,
address: org?.['address'] || null, address: org?.['address'] || null,
test_mode: 'test_mode' in org,
blocked: 'subscription_frozen' in org blocked: 'subscription_frozen' in org
}) })

View File

@@ -0,0 +1,39 @@
from aws_lambda_powertools import Logger
from aws_lambda_powertools.utilities.data_classes import (
EventBridgeEvent,
event_source,
)
from aws_lambda_powertools.utilities.typing import LambdaContext
from layercake.dynamodb import (
DynamoDBPersistenceLayer,
PartitionKey,
)
from boto3clients import dynamodb_client
from config import ORDER_TABLE
logger = Logger(__name__)
dyn = DynamoDBPersistenceLayer(ORDER_TABLE, dynamodb_client)
@event_source(data_class=EventBridgeEvent)
@logger.inject_lambda_context
def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
keys = event.detail['keys']
order_id = keys['id']
r = dyn.collection.query(PartitionKey(order_id), limit=150)
logger.info('Records found', total_items=len(r['items']), records=r['items'])
with dyn.batch_writer() as batch:
for pair in r['items']:
batch.delete_item(
Key={
'id': {'S': pair['id']},
'sk': {'S': pair['sk']},
}
)
logger.info('Deleted all records')
return True

View File

@@ -96,6 +96,8 @@ Resources:
detail: detail:
new_image: new_image:
sk: ['0'] sk: ['0']
payment_method:
- anything-but: [MANUAL]
EventPaymentsChargeCreditCardFunction: EventPaymentsChargeCreditCardFunction:
Type: AWS::Serverless::Function Type: AWS::Serverless::Function
@@ -245,6 +247,26 @@ Resources:
old_image: old_image:
status: [PENDING] status: [PENDING]
EventRunSelfDestructionFunction:
Type: AWS::Serverless::Function
Properties:
Handler: events.run_self_destruction.lambda_handler
LoggingConfig:
LogGroup: !Ref EventLog
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref OrderTable
Events:
Event:
Type: EventBridgeRule
Properties:
Pattern:
resources: [!Ref OrderTable]
detail-type: [EXPIRE]
detail:
keys:
sk: ['SCHEDULE#SELF_DESTRUCTION']
# DEPRECATED # DEPRECATED
EventAppendOrgIdFunction: EventAppendOrgIdFunction:
Type: AWS::Serverless::Function Type: AWS::Serverless::Function