Skip to content

Commit e0361fa

Browse files
ikreymertw4l
authored andcommitted
org user roles filtering pass:
- remove fields from org based on user role
1 parent 5de23f9 commit e0361fa

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

backend/btrixcloud/models.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,6 +2134,35 @@ class UserOut(UserOutNoId):
21342134

21352135
# ============================================================================
21362136
# ORGS
2137+
# ============================================================================
2138+
2139+
# Org field filters by access type
2140+
ORG_ADMIN_EXCLUDE_FIELDS = ["storage"]
2141+
2142+
ORG_CRAWLER_EXCLUDE_FIELDS = [
2143+
*ORG_ADMIN_EXCLUDE_FIELDS,
2144+
"users",
2145+
"quotaUpdates",
2146+
"webhookUrls",
2147+
"readOnlyReason",
2148+
"subscription",
2149+
]
2150+
2151+
ORG_VIEWER_EXCLUDE_FIELDS = [
2152+
*ORG_CRAWLER_EXCLUDE_FIELDS,
2153+
"usage",
2154+
"crawlExecSeconds",
2155+
"qaUsage",
2156+
"qaCrawlExecSeconds",
2157+
"monthlyExecSeconds",
2158+
"extraExecSeconds",
2159+
"giftedExecSeconds",
2160+
"quotas",
2161+
"allowSharedProxies",
2162+
"crawlingDefaults",
2163+
]
2164+
2165+
21372166
# ============================================================================
21382167
class OrgReadOnlyOnCancel(BaseModel):
21392168
"""Make org readOnly on subscription cancellation instead of deleting"""
@@ -2348,14 +2377,13 @@ def _is_auth(self, user, value):
23482377
async def serialize_for_user(self, user: User, user_manager) -> OrgOut:
23492378
"""Serialize result based on current user access"""
23502379

2351-
exclude = {"storage"}
2380+
exclude = ORG_ADMIN_EXCLUDE_FIELDS
23522381

23532382
if not self.is_owner(user):
2354-
exclude.add("users")
2383+
exclude = ORG_CRAWLER_EXCLUDE_FIELDS
23552384

23562385
if not self.is_crawler(user):
2357-
exclude.add("usage")
2358-
exclude.add("crawlExecSeconds")
2386+
exclude = ORG_VIEWER_EXCLUDE_FIELDS
23592387

23602388
result = self.to_dict(
23612389
exclude_unset=True,

0 commit comments

Comments
 (0)