Skip to content

Commit d8cb59a

Browse files
committed
keep subs data after cancellation, just mark status as 'canceled'
1 parent 885814e commit d8cb59a

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

backend/btrixcloud/orgs.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
OrgCreate,
4141
SubscriptionData,
4242
SubscriptionUpdate,
43-
SubscriptionCancel,
4443
RenameOrg,
4544
UpdateRole,
4645
RemovePendingInvite,
@@ -365,20 +364,6 @@ async def update_subscription_data(
365364
)
366365
return Organization.from_dict(org_data) if org_data else None
367366

368-
async def cancel_subscription_data(
369-
self, cancel: SubscriptionCancel
370-
) -> Optional[Organization]:
371-
"""Find org by subscription by id and delete subscription data, return org"""
372-
org_data = await self.orgs.find_one_and_update(
373-
{"subData.subId": cancel.subId},
374-
{"$set": {"subData": None}},
375-
return_document=ReturnDocument.BEFORE,
376-
)
377-
if not org_data:
378-
return None
379-
380-
return Organization.from_dict(org_data)
381-
382367
async def update_custom_storages(self, org: Organization) -> bool:
383368
"""Update storage on an existing organization"""
384369

backend/btrixcloud/subs.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Subscription API handling
33
"""
44

5-
from typing import Callable, Union
5+
from typing import Callable, Union, Any
66

77
from fastapi import Depends, HTTPException, Request
88

@@ -36,7 +36,7 @@ def __init__(self, mdb, org_ops: OrgOps, user_manager: UserManager):
3636

3737
async def create_new_subscription(
3838
self, create: SubscriptionCreate, user: User, request: Request
39-
):
39+
) -> dict[str, Any]:
4040
"""create org for new subscription"""
4141
sub_data = SubscriptionData(
4242
subId=create.subId, status=create.status, details=create.details
@@ -66,7 +66,7 @@ async def create_new_subscription(
6666

6767
return result
6868

69-
async def update_subscription(self, update: SubscriptionUpdate):
69+
async def update_subscription(self, update: SubscriptionUpdate) -> dict[str, bool]:
7070
"""update subs"""
7171

7272
org = await self.org_ops.update_subscription_data(update)
@@ -76,15 +76,15 @@ async def update_subscription(self, update: SubscriptionUpdate):
7676
status_code=404, detail="org_for_subscription_not_found"
7777
)
7878

79-
print("ORG SUB", org.subData)
80-
8179
await self.add_sub_event(update)
8280
return {"updated": True}
8381

84-
async def cancel_subscription(self, cancel: SubscriptionCancel):
82+
async def cancel_subscription(self, cancel: SubscriptionCancel) -> dict[str, bool]:
8583
"""delete subscription data, and if readOnlyOnCancel is true, the entire org"""
8684

87-
org = await self.org_ops.cancel_subscription_data(cancel)
85+
org = await self.org_ops.update_subscription_data(
86+
SubscriptionUpdate(subId=cancel.subId, status="canceled")
87+
)
8888

8989
if not org:
9090
raise HTTPException(
@@ -125,7 +125,7 @@ def init_subs_api(
125125
org_ops: OrgOps,
126126
user_manager: UserManager,
127127
user_or_shared_secret_dep: Callable,
128-
):
128+
) -> SubOps:
129129
"""init subs API"""
130130
ops = SubOps(mdb, org_ops, user_manager)
131131

0 commit comments

Comments
 (0)