Skip to content

Commit

Permalink
add OrgQuotasIn with all options optional, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ikreymer committed Aug 10, 2024
1 parent bf26bcd commit 0e4ada0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
25 changes: 20 additions & 5 deletions backend/btrixcloud/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,10 +1115,25 @@ 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
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 @@ -1177,7 +1192,7 @@ class SubscriptionUpdate(BaseModel):
planId: str

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


# ============================================================================
Expand Down
5 changes: 3 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 @@ -514,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 @@ -1460,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
20 changes: 10 additions & 10 deletions backend/test/test_org_subs.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,8 @@ def test_subscription_events_log(admin_auth_headers, non_default_org_id):
"storageQuota": 500000,
"extraExecMinutes": None,
"giftedExecMinutes": None,
"maxConcurrentCrawls": 0,
"maxExecMinutesPerMonth": 0,
"maxConcurrentCrawls": None,
"maxExecMinutesPerMonth": None,
},
},
{"subId": "123", "oid": new_subs_oid, "type": "cancel"},
Expand Down Expand Up @@ -549,8 +549,8 @@ def test_subscription_events_log_filter_sub_id(admin_auth_headers):
"storageQuota": 500000,
"extraExecMinutes": None,
"giftedExecMinutes": None,
"maxConcurrentCrawls": 0,
"maxExecMinutesPerMonth": 0,
"maxConcurrentCrawls": None,
"maxExecMinutesPerMonth": None,
},
},
{"subId": "123", "oid": new_subs_oid, "type": "cancel"},
Expand Down Expand Up @@ -610,8 +610,8 @@ def test_subscription_events_log_filter_oid(admin_auth_headers):
"storageQuota": 500000,
"extraExecMinutes": None,
"giftedExecMinutes": None,
"maxConcurrentCrawls": 0,
"maxExecMinutesPerMonth": 0,
"maxConcurrentCrawls": None,
"maxExecMinutesPerMonth": None,
},
},
{"subId": "123", "oid": new_subs_oid, "type": "cancel"},
Expand Down Expand Up @@ -645,8 +645,8 @@ def test_subscription_events_log_filter_plan_id(admin_auth_headers):
"storageQuota": 500000,
"extraExecMinutes": None,
"giftedExecMinutes": None,
"maxConcurrentCrawls": 0,
"maxExecMinutesPerMonth": 0,
"maxConcurrentCrawls": None,
"maxExecMinutesPerMonth": None,
},
}
]
Expand Down Expand Up @@ -696,8 +696,8 @@ def test_subscription_events_log_filter_status(admin_auth_headers):
"storageQuota": 500000,
"extraExecMinutes": None,
"giftedExecMinutes": None,
"maxConcurrentCrawls": 0,
"maxExecMinutesPerMonth": 0,
"maxConcurrentCrawls": None,
"maxExecMinutesPerMonth": None,
},
},
]
Expand Down

0 comments on commit 0e4ada0

Please sign in to comment.