- Notifications
You must be signed in to change notification settings - Fork1.2k
fix: ensure user admins can always see users table#15226
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
1ad09fa620bd3a7ee3cf0e88962136e0376032a75ceea8bbde6d420114fc68ea8fd9e60a36cd1e6d772b3752af52068a4c2fe3d533c41de0162642e64c6f29e12a4aab9b33c0f7df5ff69252949fc0afa498e7ba234c6064496a759fcf3e719fb6e5804255ed341175f3e6659ce67a667e946a7File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| import type { AuthorizationCheck } from "api/typesGenerated"; | ||
| export const checks = { | ||
| viewAllUsers: "viewAllUsers", | ||
| updateUsers: "updateUsers", | ||
| @@ -11,13 +13,20 @@ export const checks = { | ||
| viewUpdateCheck: "viewUpdateCheck", | ||
| viewExternalAuthConfig: "viewExternalAuthConfig", | ||
| viewDeploymentStats: "viewDeploymentStats", | ||
| readWorkspaceProxies: "readWorkspaceProxies", | ||
| editWorkspaceProxies: "editWorkspaceProxies", | ||
| createOrganization: "createOrganization", | ||
| editAnyOrganization: "editAnyOrganization", | ||
| viewAnyGroup: "viewAnyGroup", | ||
| createGroup: "createGroup", | ||
| viewAllLicenses: "viewAllLicenses", | ||
| viewNotificationTemplate: "viewNotificationTemplate", | ||
| } as const satisfies Record<string, string>; | ||
| // Type expression seems a little redundant (`keyof typeof checks` has the same | ||
| // result), just because each key-value pair is currently symmetrical; this may | ||
| // change down the line | ||
| type PermissionValue = (typeof checks)[keyof typeof checks]; | ||
| export const permissionsToCheck = { | ||
| [checks.viewAllUsers]: { | ||
| @@ -94,6 +103,12 @@ export const permissionsToCheck = { | ||
| }, | ||
| action: "read", | ||
| }, | ||
| [checks.readWorkspaceProxies]: { | ||
| object: { | ||
| resource_type: "workspace_proxy", | ||
| }, | ||
| action: "read", | ||
| }, | ||
| [checks.editWorkspaceProxies]: { | ||
| object: { | ||
| resource_type: "workspace_proxy", | ||
| @@ -116,7 +131,6 @@ export const permissionsToCheck = { | ||
| [checks.viewAnyGroup]: { | ||
| object: { | ||
| resource_type: "group", | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Ended up deleting this because the property wasn't compatible. It also didn't seem to be used anywhere @Emyrk Not sure if we should update the types so that this can be added back Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Can you delete this unused check then? ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Oh, sorry – I meant that the | ||
| }, | ||
| action: "read", | ||
| }, | ||
| @@ -132,6 +146,12 @@ export const permissionsToCheck = { | ||
| }, | ||
| action: "read", | ||
| }, | ||
| [checks.viewNotificationTemplate]: { | ||
| object: { | ||
| resource_type: "notification_template", | ||
| }, | ||
| action: "read", | ||
| }, | ||
| } as const satisfies Record<PermissionValue, AuthorizationCheck>; | ||
| export type Permissions = Record<PermissionValue, boolean>; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,9 +12,9 @@ import { Loader } from "components/Loader/Loader"; | ||
| import { Sidebar as BaseSidebar } from "components/Sidebar/Sidebar"; | ||
| import { Stack } from "components/Stack/Stack"; | ||
| import { UserAvatar } from "components/UserAvatar/UserAvatar"; | ||
| import type { Permissions } from "contexts/auth/permissions"; | ||
| import { type ClassName, useClassName } from "hooks/useClassName"; | ||
| import { useDashboard } from "modules/dashboard/useDashboard"; | ||
| import type { FC, ReactNode } from "react"; | ||
| import { Link, NavLink } from "react-router-dom"; | ||
| @@ -30,7 +30,7 @@ interface SidebarProps { | ||
| /** Organizations and their permissions or undefined if still fetching. */ | ||
| organizations: OrganizationWithPermissions[] | undefined; | ||
| /** Site-wide permissions. */ | ||
| permissions:Permissions; | ||
| } | ||
| /** | ||
| @@ -72,7 +72,7 @@ interface DeploymentSettingsNavigationProps { | ||
| /** Whether a deployment setting page is being viewed. */ | ||
| active: boolean; | ||
| /** Site-wide permissions. */ | ||
| permissions:Permissions; | ||
| } | ||
| /** | ||
| @@ -130,10 +130,11 @@ const DeploymentSettingsNavigation: FC<DeploymentSettingsNavigationProps> = ({ | ||
| {permissions.viewDeploymentValues && ( | ||
| <SidebarNavSubItem href="network">Network</SidebarNavSubItem> | ||
| )} | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This actually wasn't true, so Steven and I had to put this behind a condition | ||
| {permissions.readWorkspaceProxies && ( | ||
| <SidebarNavSubItem href="workspace-proxies"> | ||
| Workspace Proxies | ||
| </SidebarNavSubItem> | ||
| )} | ||
| {permissions.viewDeploymentValues && ( | ||
| <SidebarNavSubItem href="security">Security</SidebarNavSubItem> | ||
| )} | ||
| @@ -145,12 +146,14 @@ const DeploymentSettingsNavigation: FC<DeploymentSettingsNavigationProps> = ({ | ||
| {permissions.viewAllUsers && ( | ||
| <SidebarNavSubItem href="users">Users</SidebarNavSubItem> | ||
| )} | ||
| {permissions.viewNotificationTemplate && ( | ||
| <SidebarNavSubItem href="notifications"> | ||
| <Stack direction="row" alignItems="center" spacing={1}> | ||
| <span>Notifications</span> | ||
| <FeatureStageBadge contentType="beta" size="sm" /> | ||
| </Stack> | ||
| </SidebarNavSubItem> | ||
| )} | ||
| </Stack> | ||
| )} | ||
| </div> | ||
| @@ -167,7 +170,7 @@ interface OrganizationsSettingsNavigationProps { | ||
| /** Organizations and their permissions or undefined if still fetching. */ | ||
| organizations: OrganizationWithPermissions[] | undefined; | ||
| /** Site-wide permissions. */ | ||
| permissions:Permissions; | ||
| } | ||
| /** | ||
| @@ -241,8 +244,6 @@ interface OrganizationSettingsNavigationProps { | ||
| const OrganizationSettingsNavigation: FC< | ||
| OrganizationSettingsNavigationProps | ||
| > = ({ active, organization }) => { | ||
| return ( | ||
| <> | ||
| <SidebarNavItem | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -11,15 +11,14 @@ import { Section } from "pages/UserSettingsPage/Section"; | ||
| import type { FC } from "react"; | ||
| import { Helmet } from "react-helmet-async"; | ||
| import { useQueries } from "react-query"; | ||
| import { deploymentGroupHasParent } from "utils/deployOptions"; | ||
| import { pageTitle } from "utils/page"; | ||
| import OptionsTable from "../OptionsTable"; | ||
| import { NotificationEvents } from "./NotificationEvents"; | ||
| import { useDeploymentSettings } from "modules/management/DeploymentSettingsProvider"; | ||
| import { useSearchParamsKey } from "hooks/useSearchParamsKey"; | ||
| export const NotificationsPage: FC = () => { | ||
| const { deploymentConfig } = useDeploymentSettings(); | ||
| const [templatesByGroup, dispatchMethods] = useQueries({ | ||
| queries: [ | ||
| @@ -30,10 +29,12 @@ export const NotificationsPage: FC = () => { | ||
| notificationDispatchMethods(), | ||
| ], | ||
| }); | ||
| const tabState = useSearchParamsKey({ | ||
| key: "tab", | ||
| defaultValue: "events", | ||
| }); | ||
| const ready = !!(templatesByGroup.data && dispatchMethods.data); | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. nit: prefer ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. So do I, but for some reason, when I tried to change things, it wasn't doing anything with type narrowing | ||
| return ( | ||
| <> | ||
| <Helmet> | ||
| @@ -45,7 +46,7 @@ export const NotificationsPage: FC = () => { | ||
| layout="fluid" | ||
| featureStage={"beta"} | ||
| > | ||
| <Tabs active={tabState.value}> | ||
| <TabsList> | ||
| <TabLink to="?tab=events" value="events"> | ||
| Events | ||
| @@ -58,7 +59,7 @@ export const NotificationsPage: FC = () => { | ||
| <div css={styles.content}> | ||
| {ready ? ( | ||
| tabState.value === "events" ? ( | ||
| <NotificationEvents | ||
| templatesByGroup={templatesByGroup.data} | ||
| deploymentConfig={deploymentConfig.config} | ||
| @@ -71,7 +72,7 @@ export const NotificationsPage: FC = () => { | ||
| /> | ||
| ) : ( | ||
| <OptionsTable | ||
| options={deploymentConfig.options.filter((o) => | ||
| deploymentGroupHasParent(o.group, "Notifications"), | ||
| )} | ||
| /> | ||
Uh oh!
There was an error while loading.Please reload this page.