Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Subscription Update doesn't update the gifted quotas #2012

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions backend/btrixcloud/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,12 +1115,28 @@ class S3Storage(BaseModel):
class OrgQuotas(BaseModel):
"""Organization quotas (settable by superadmin)"""

maxConcurrentCrawls: Optional[int] = 0
maxPagesPerCrawl: Optional[int] = 0
storageQuota: Optional[int] = 0
maxExecMinutesPerMonth: Optional[int] = 0
extraExecMinutes: Optional[int] = 0
giftedExecMinutes: Optional[int] = 0
storageQuota: int = 0
maxExecMinutesPerMonth: int = 0

maxConcurrentCrawls: int = 0
maxPagesPerCrawl: int = 0

extraExecMinutes: int = 0
giftedExecMinutes: int = 0


# ============================================================================
class OrgQuotasIn(BaseModel):
"""Update for existing OrgQuotas"""

storageQuota: Optional[int] = None
maxExecMinutesPerMonth: Optional[int] = None

maxConcurrentCrawls: Optional[int] = None
maxPagesPerCrawl: Optional[int] = None

extraExecMinutes: Optional[int] = None
giftedExecMinutes: Optional[int] = None


# ============================================================================
Expand Down Expand Up @@ -1176,7 +1192,7 @@ class SubscriptionUpdate(BaseModel):
planId: str

futureCancelDate: Optional[datetime] = None
quotas: Optional[OrgQuotas] = None
quotas: Optional[OrgQuotasIn] = None


# ============================================================================
Expand Down
7 changes: 5 additions & 2 deletions backend/btrixcloud/orgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
Organization,
StorageRef,
OrgQuotas,
OrgQuotasIn,
OrgQuotaUpdate,
OrgReadOnlyUpdate,
OrgReadOnlyOnCancel,
Expand Down Expand Up @@ -489,6 +490,8 @@ async def update_subscription_data(

org = Organization.from_dict(org_data)
if update.quotas:
# don't change gifted minutes here
update.quotas.giftedExecMinutes = None
await self.update_quotas(org, update.quotas)

return org
Expand All @@ -512,7 +515,7 @@ async def update_custom_storages(self, org: Organization) -> bool:
res = await self.orgs.find_one_and_update({"_id": org.id}, {"$set": set_dict})
return res is not None

async def update_quotas(self, org: Organization, quotas: OrgQuotas) -> None:
async def update_quotas(self, org: Organization, quotas: OrgQuotasIn) -> None:
"""update organization quotas"""

previous_extra_mins = (
Expand Down Expand Up @@ -1458,7 +1461,7 @@ async def rename_org(

@router.post("/quotas", tags=["organizations"], response_model=UpdatedResponse)
async def update_quotas(
quotas: OrgQuotas,
quotas: OrgQuotasIn,
org: Organization = Depends(org_owner_dep),
user: User = Depends(user_dep),
):
Expand Down
40 changes: 20 additions & 20 deletions backend/test/test_org_subs.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,10 @@ def test_subscription_events_log(admin_auth_headers, non_default_org_id):
"quotas": {
"maxPagesPerCrawl": 50,
"storageQuota": 500000,
"extraExecMinutes": 0,
"giftedExecMinutes": 0,
"maxConcurrentCrawls": 0,
"maxExecMinutesPerMonth": 0,
"extraExecMinutes": None,
"giftedExecMinutes": None,
"maxConcurrentCrawls": None,
"maxExecMinutesPerMonth": None,
},
},
{"subId": "123", "oid": new_subs_oid, "type": "cancel"},
Expand Down Expand Up @@ -547,10 +547,10 @@ def test_subscription_events_log_filter_sub_id(admin_auth_headers):
"quotas": {
"maxPagesPerCrawl": 50,
"storageQuota": 500000,
"extraExecMinutes": 0,
"giftedExecMinutes": 0,
"maxConcurrentCrawls": 0,
"maxExecMinutesPerMonth": 0,
"extraExecMinutes": None,
"giftedExecMinutes": None,
"maxConcurrentCrawls": None,
"maxExecMinutesPerMonth": None,
},
},
{"subId": "123", "oid": new_subs_oid, "type": "cancel"},
Expand Down Expand Up @@ -608,10 +608,10 @@ def test_subscription_events_log_filter_oid(admin_auth_headers):
"quotas": {
"maxPagesPerCrawl": 50,
"storageQuota": 500000,
"extraExecMinutes": 0,
"giftedExecMinutes": 0,
"maxConcurrentCrawls": 0,
"maxExecMinutesPerMonth": 0,
"extraExecMinutes": None,
"giftedExecMinutes": None,
"maxConcurrentCrawls": None,
"maxExecMinutesPerMonth": None,
},
},
{"subId": "123", "oid": new_subs_oid, "type": "cancel"},
Expand Down Expand Up @@ -643,10 +643,10 @@ def test_subscription_events_log_filter_plan_id(admin_auth_headers):
"quotas": {
"maxPagesPerCrawl": 50,
"storageQuota": 500000,
"extraExecMinutes": 0,
"giftedExecMinutes": 0,
"maxConcurrentCrawls": 0,
"maxExecMinutesPerMonth": 0,
"extraExecMinutes": None,
"giftedExecMinutes": None,
"maxConcurrentCrawls": None,
"maxExecMinutesPerMonth": None,
},
}
]
Expand Down Expand Up @@ -694,10 +694,10 @@ def test_subscription_events_log_filter_status(admin_auth_headers):
"quotas": {
"maxPagesPerCrawl": 50,
"storageQuota": 500000,
"extraExecMinutes": 0,
"giftedExecMinutes": 0,
"maxConcurrentCrawls": 0,
"maxExecMinutesPerMonth": 0,
"extraExecMinutes": None,
"giftedExecMinutes": None,
"maxConcurrentCrawls": None,
"maxExecMinutesPerMonth": None,
},
},
]
Expand Down
Loading