Skip to content
Draft
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
36 changes: 32 additions & 4 deletions backend/btrixcloud/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2062,6 +2062,35 @@ class UserOut(UserOutNoId):

# ============================================================================
# ORGS
# ============================================================================

# Org field filters by access type
ORG_ADMIN_EXCLUDE_FIELDS = ["storage"]

ORG_CRAWLER_EXCLUDE_FIELDS = [
*ORG_ADMIN_EXCLUDE_FIELDS,
"users",
"quotaUpdates",
"webhookUrls",
"readOnlyReason",
"subscription",
]

ORG_VIEWER_EXCLUDE_FIELDS = [
*ORG_CRAWLER_EXCLUDE_FIELDS,
"usage",
"crawlExecSeconds",
"qaUsage",
"qaCrawlExecSeconds",
"monthlyExecSeconds",
"extraExecSeconds",
"giftedExecSeconds",
"quotas",
"allowSharedProxies",
"crawlingDefaults",
]


# ============================================================================
class OrgReadOnlyOnCancel(BaseModel):
"""Make org readOnly on subscription cancellation instead of deleting"""
Expand Down Expand Up @@ -2267,14 +2296,13 @@ def _is_auth(self, user, value):
async def serialize_for_user(self, user: User, user_manager) -> OrgOut:
"""Serialize result based on current user access"""

exclude = {"storage"}
exclude = ORG_ADMIN_EXCLUDE_FIELDS

if not self.is_owner(user):
exclude.add("users")
exclude = ORG_CRAWLER_EXCLUDE_FIELDS

if not self.is_crawler(user):
exclude.add("usage")
exclude.add("crawlExecSeconds")
exclude = ORG_VIEWER_EXCLUDE_FIELDS

result = self.to_dict(
exclude_unset=True,
Expand Down
Loading