Skip to content

Commit 4b5b915

Browse files
committed
Merge branch 'additional-minutes-addon-purchase' into temp-feature-all-1.22
2 parents d60688e + 261f9b8 commit 4b5b915

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2009
-654
lines changed

.github/workflows/k3d-ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ jobs:
119119
version: 3.10.2
120120

121121
- name: Create secret
122-
run: kubectl create secret generic btrix-subs-app-secret --from-literal=BTRIX_SUBS_APP_URL=${{ env.ECHO_SERVER_HOST_URL }}/portalUrl
122+
run: kubectl create secret generic btrix-subs-app-secret --from-literal=BTRIX_SUBS_APP_URL=${{ env.ECHO_SERVER_HOST_URL }}
123123

124124
- name: Start Cluster with Helm
125125
run: |

.github/workflows/k3d-nightly-ci.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ jobs:
9999
with:
100100
version: 3.10.2
101101

102+
- name: Create Secret
103+
run: >
104+
kubectl create secret generic btrix-subs-app-secret
105+
--from-literal=BTRIX_SUBS_APP_URL=${{ env.ECHO_SERVER_HOST_URL }}
106+
--from-literal=BTRIX_SUBS_APP_API_KEY=TEST_PRESHARED_SECRET_PASSWORD
107+
102108
- name: Start Cluster with Helm
103109
run: |
104110
helm upgrade --install -f ./chart/values.yaml -f ./chart/test/test.yaml -f ./chart/test/test-nightly-addons.yaml btrix ./chart/

.github/workflows/microk8s-ci.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ jobs:
1717
btrix-microk8s-test:
1818
runs-on: ubuntu-latest
1919
steps:
20+
- name: Initial Disk Cleanup
21+
uses: mathio/gha-cleanup@v1
22+
with:
23+
remove-browsers: true
24+
verbose: true
25+
2026
- uses: balchua/[email protected]
2127
with:
2228
channel: "1.25/stable"
@@ -60,7 +66,7 @@ jobs:
6066
cache-to: type=gha,scope=frontend,mode=max
6167

6268
- name: Create Secret
63-
run: sudo microk8s kubectl create secret generic btrix-subs-app-secret --from-literal=BTRIX_SUBS_APP_URL=${{ env.ECHO_SERVER_HOST_URL }}/portalUrl
69+
run: sudo microk8s kubectl create secret generic btrix-subs-app-secret --from-literal=BTRIX_SUBS_APP_URL=${{ env.ECHO_SERVER_HOST_URL }}
6470

6571
- name: Start Cluster with Helm
6672
run: |

backend/btrixcloud/auth.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ class OA2BearerOrQuery(OAuth2PasswordBearer):
6666
"""Override bearer check to also test query"""
6767

6868
async def __call__(
69-
self, request: Request = None, websocket: WebSocket = None # type: ignore
69+
self,
70+
request: Request = None, # type: ignore
71+
websocket: WebSocket = None, # type: ignore
7072
) -> str:
7173
param = None
7274
exc = None
@@ -163,7 +165,7 @@ async def get_current_user(
163165
headers={"WWW-Authenticate": "Bearer"},
164166
)
165167

166-
async def shared_secret_or_active_user(
168+
async def shared_secret_or_superuser(
167169
token: str = Depends(oauth2_scheme),
168170
) -> User:
169171
# allow superadmin access if token matches the known shared secret
@@ -257,4 +259,4 @@ async def refresh_jwt(user=Depends(current_active_user)):
257259
user_info = await user_manager.get_user_info_with_orgs(user)
258260
return get_bearer_response(user, user_info)
259261

260-
return auth_jwt_router, current_active_user, shared_secret_or_active_user
262+
return auth_jwt_router, current_active_user, shared_secret_or_superuser

backend/btrixcloud/main.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ def main() -> None:
172172

173173
user_manager = init_user_manager(mdb, email, invites)
174174

175-
current_active_user, shared_secret_or_active_user = init_users_api(
176-
app, user_manager
177-
)
175+
current_active_user, shared_secret_or_superuser = init_users_api(app, user_manager)
178176

179177
org_ops = init_orgs_api(
180178
app,
@@ -185,7 +183,7 @@ def main() -> None:
185183
current_active_user,
186184
)
187185

188-
init_subs_api(app, mdb, org_ops, user_manager, shared_secret_or_active_user)
186+
init_subs_api(app, mdb, org_ops, user_manager, shared_secret_or_superuser)
189187

190188
event_webhook_ops = init_event_webhooks_api(mdb, org_ops, app_root)
191189

backend/btrixcloud/models.py

Lines changed: 81 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,8 @@ class S3Storage(BaseModel):
18841884
REASON_PAUSED = "subscriptionPaused"
18851885
REASON_CANCELED = "subscriptionCanceled"
18861886

1887+
SubscriptionEventType = Literal["create", "import", "update", "cancel", "add-minutes"]
1888+
18871889

18881890
# ============================================================================
18891891
class OrgQuotas(BaseModel):
@@ -1936,6 +1938,7 @@ class SubscriptionEventOut(BaseModel):
19361938

19371939
oid: UUID
19381940
timestamp: datetime
1941+
type: SubscriptionEventType
19391942

19401943

19411944
# ============================================================================
@@ -2001,18 +2004,54 @@ class SubscriptionCancel(BaseModel):
20012004

20022005

20032006
# ============================================================================
2004-
class SubscriptionTrialEndReminder(BaseModel):
2005-
"""Email reminder that subscription will end soon"""
2007+
class SubscriptionCancelOut(SubscriptionCancel, SubscriptionEventOut):
2008+
"""Output model for subscription cancellation event"""
20062009

2007-
subId: str
2008-
behavior_on_trial_end: Literal["cancel", "continue", "read-only"]
2010+
type: Literal["cancel"] = "cancel"
20092011

20102012

20112013
# ============================================================================
2012-
class SubscriptionCancelOut(SubscriptionCancel, SubscriptionEventOut):
2013-
"""Output model for subscription cancellation event"""
2014+
class SubscriptionAddMinutes(BaseModel):
2015+
"""Represents a purchase of additional minutes"""
2016+
2017+
oid: UUID
2018+
minutes: int
2019+
totalPrice: float
2020+
currency: str
2021+
paymentId: str
20142022

2015-
type: Literal["cancel"] = "cancel"
2023+
2024+
# ============================================================================
2025+
class SubscriptionAddMinutesOut(SubscriptionAddMinutes, SubscriptionEventOut):
2026+
"""SubscriptionAddMinutes output model"""
2027+
2028+
type: Literal["add-minutes"] = "add-minutes"
2029+
2030+
2031+
# ============================================================================
2032+
SubscriptionEventAny = Union[
2033+
SubscriptionCreate,
2034+
SubscriptionUpdate,
2035+
SubscriptionCancel,
2036+
SubscriptionImport,
2037+
SubscriptionAddMinutes,
2038+
]
2039+
2040+
SubscriptionEventAnyOut = Union[
2041+
SubscriptionCreateOut,
2042+
SubscriptionUpdateOut,
2043+
SubscriptionCancelOut,
2044+
SubscriptionImportOut,
2045+
SubscriptionAddMinutesOut,
2046+
]
2047+
2048+
2049+
# ============================================================================
2050+
class SubscriptionTrialEndReminder(BaseModel):
2051+
"""Email reminder that subscription will end soon"""
2052+
2053+
subId: str
2054+
behavior_on_trial_end: Literal["cancel", "continue", "read-only"]
20162055

20172056

20182057
# ============================================================================
@@ -2035,6 +2074,30 @@ class SubscriptionPortalUrlResponse(BaseModel):
20352074
portalUrl: str = ""
20362075

20372076

2077+
# ============================================================================
2078+
class AddonMinutesPricing(BaseModel):
2079+
"""Addon minutes pricing"""
2080+
2081+
value: float
2082+
currency: str
2083+
2084+
2085+
# ============================================================================
2086+
class CheckoutAddonMinutesRequest(BaseModel):
2087+
"""Request for additional minutes checkout session"""
2088+
2089+
orgId: str
2090+
subId: str
2091+
minutes: int | None = None
2092+
return_url: str
2093+
2094+
2095+
class CheckoutAddonMinutesResponse(BaseModel):
2096+
"""Response for additional minutes checkout session"""
2097+
2098+
checkoutUrl: str
2099+
2100+
20382101
# ============================================================================
20392102
class Subscription(BaseModel):
20402103
"""subscription data"""
@@ -2113,6 +2176,15 @@ class OrgQuotaUpdate(BaseModel):
21132176

21142177
modified: datetime
21152178
update: OrgQuotas
2179+
subEventId: str | None = None
2180+
2181+
2182+
# ============================================================================
2183+
class OrgQuotaUpdateOut(BaseModel):
2184+
"""Organization quota update output for admins"""
2185+
2186+
modified: datetime
2187+
update: OrgQuotas
21162188

21172189

21182190
# ============================================================================
@@ -2189,7 +2261,7 @@ class OrgOut(BaseMongoModel):
21892261
giftedExecSecondsAvailable: int = 0
21902262

21912263
quotas: OrgQuotas = OrgQuotas()
2192-
quotaUpdates: Optional[List[OrgQuotaUpdate]] = []
2264+
quotaUpdates: Optional[List[OrgQuotaUpdateOut]] = []
21932265

21942266
webhookUrls: Optional[OrgWebhookUrls] = OrgWebhookUrls()
21952267

@@ -3154,14 +3226,7 @@ class PaginatedProfileResponse(PaginatedResponse):
31543226
class PaginatedSubscriptionEventResponse(PaginatedResponse):
31553227
"""Response model for paginated subscription events"""
31563228

3157-
items: List[
3158-
Union[
3159-
SubscriptionCreateOut,
3160-
SubscriptionUpdateOut,
3161-
SubscriptionCancelOut,
3162-
SubscriptionImportOut,
3163-
]
3164-
]
3229+
items: List[SubscriptionEventAnyOut]
31653230

31663231

31673232
# ============================================================================

0 commit comments

Comments
 (0)