Skip to content

Commit 04cefeb

Browse files
authored
add permissions.canUpdateOrganization to show/hide items in org navbar (calcom#24142)
1 parent dbd927c commit 04cefeb

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

apps/web/app/(use-page-wrapper)/settings/(settings-layout)/SettingsLayoutAppDirClient.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ const organizationAdminKeys = ["privacy", "OAuth Clients", "SSO", "directory_syn
175175
export interface SettingsPermissions {
176176
canViewRoles?: boolean;
177177
canViewOrganizationBilling?: boolean;
178+
canUpdateOrganization?: boolean;
178179
}
179180

180181
const useTabs = ({
@@ -203,10 +204,13 @@ const useTabs = ({
203204
};
204205
} else if (tab.href === "/settings/organizations") {
205206
const newArray = (tab?.children ?? []).filter(
206-
(child) => isOrgAdminOrOwner || !organizationAdminKeys.includes(child.name)
207+
(child) =>
208+
permissions?.canUpdateOrganization ||
209+
isOrgAdminOrOwner ||
210+
!organizationAdminKeys.includes(child.name)
207211
);
208212

209-
if (isOrgAdminOrOwner) {
213+
if (permissions?.canUpdateOrganization || isOrgAdminOrOwner) {
210214
newArray.splice(4, 0, {
211215
name: "attributes",
212216
href: "/settings/organizations/attributes",
@@ -238,7 +242,7 @@ const useTabs = ({
238242
});
239243
}
240244
} else {
241-
if (isOrgAdminOrOwner) {
245+
if (permissions?.canUpdateOrganization || isOrgAdminOrOwner) {
242246
newArray.push({
243247
name: "billing",
244248
href: "/settings/organizations/billing",
@@ -264,7 +268,8 @@ const useTabs = ({
264268
return { ...tab, children: filtered };
265269
} else if (tab.href === "/settings/developer") {
266270
const filtered = tab?.children?.filter(
267-
(childTab) => isOrgAdminOrOwner || childTab.name !== "admin_api"
271+
(childTab) =>
272+
permissions?.canUpdateOrganization || isOrgAdminOrOwner || childTab.name !== "admin_api"
268273
);
269274
return { ...tab, children: filtered };
270275
}
@@ -274,12 +279,21 @@ const useTabs = ({
274279
// check if name is in adminRequiredKeys
275280
return processedTabs.filter((tab) => {
276281
if (organizationRequiredKeys.includes(tab.name)) return !!orgBranding;
277-
if (tab.name === "other_teams" && !isOrgAdminOrOwner) return false;
282+
if (tab.name === "other_teams" && !(permissions?.canUpdateOrganization || isOrgAdminOrOwner))
283+
return false;
278284

279285
if (isAdmin) return true;
280286
return !adminRequiredKeys.includes(tab.name);
281287
});
282-
}, [isAdmin, orgBranding, isOrgAdminOrOwner, user, isDelegationCredentialEnabled, isPbacEnabled, permissions]);
288+
}, [
289+
isAdmin,
290+
orgBranding,
291+
isOrgAdminOrOwner,
292+
user,
293+
isDelegationCredentialEnabled,
294+
isPbacEnabled,
295+
permissions,
296+
]);
283297

284298
return processTabsMemod;
285299
};
@@ -643,7 +657,7 @@ const SettingsSidebarContainer = ({
643657
</div>
644658
</Link>
645659
<TeamListCollapsible teamFeatures={teamFeatures} />
646-
{(!orgBranding?.id || isOrgAdminOrOwner) && (
660+
{(!orgBranding?.id || permissions?.canUpdateOrganization || isOrgAdminOrOwner) && (
647661
<VerticalTabItem
648662
name={t("add_a_team")}
649663
href={`${WEBAPP_URL}/settings/teams/new`}

apps/web/app/(use-page-wrapper)/settings/(settings-layout)/layout.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export default async function SettingsLayoutAppDir(props: SettingsLayoutProps) {
4747
let teamFeatures: Record<number, TeamFeatures> | null = null;
4848
let canViewRoles = false;
4949
let canViewOrganizationBilling = false;
50+
let canUpdateOrganization = false;
5051
const orgId = session?.user?.profile?.organizationId ?? session?.user.org?.id;
5152

5253
// For now we only grab organization features but it would be nice to fetch these on the server side for specific team feature flags
@@ -68,6 +69,7 @@ export default async function SettingsLayoutAppDir(props: SettingsLayoutProps) {
6869
canViewRoles = roleActions[CrudAction.Read] ?? false;
6970
const orgActions = PermissionMapper.toActionMap(organizationPermissions, Resource.Organization);
7071
canViewOrganizationBilling = orgActions[CustomAction.ManageBilling] ?? isOrgAdminOrOwner;
72+
canUpdateOrganization = orgActions[CrudAction.Update] ?? isOrgAdminOrOwner;
7173
}
7274
}
7375

@@ -76,7 +78,7 @@ export default async function SettingsLayoutAppDir(props: SettingsLayoutProps) {
7678
<SettingsLayoutAppDirClient
7779
{...props}
7880
teamFeatures={teamFeatures ?? {}}
79-
permissions={{ canViewRoles, canViewOrganizationBilling }}
81+
permissions={{ canViewRoles, canViewOrganizationBilling, canUpdateOrganization }}
8082
/>
8183
</>
8284
);

0 commit comments

Comments
 (0)