- Notifications
You must be signed in to change notification settings - Fork1.1k
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 fromall commits
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
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -175,6 +175,7 @@ | ||
| "unauthenticate", | ||
| "unconvert", | ||
| "untar", | ||
| "userauth", | ||
| "userspace", | ||
| "VMID", | ||
| "walkthrough", | ||
| 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 |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import type { DeploymentConfig } from "api/api"; | ||
| import { deploymentConfig } from "api/queries/deployment"; | ||
| import { ErrorAlert } from "components/Alert/ErrorAlert"; | ||
| import { Loader } from "components/Loader/Loader"; | ||
| import { useAuthenticated } from "contexts/auth/RequireAuth"; | ||
| import { RequirePermission } from "contexts/auth/RequirePermission"; | ||
| import { type FC, createContext, useContext } from "react"; | ||
| import { useQuery } from "react-query"; | ||
| import { Outlet } from "react-router-dom"; | ||
| export const DeploymentSettingsContext = createContext< | ||
| DeploymentSettingsValue | undefined | ||
| >(undefined); | ||
| type DeploymentSettingsValue = Readonly<{ | ||
| deploymentConfig: DeploymentConfig; | ||
| }>; | ||
| export const useDeploymentSettings = (): DeploymentSettingsValue => { | ||
| const context = useContext(DeploymentSettingsContext); | ||
| if (!context) { | ||
| throw new Error( | ||
| `${useDeploymentSettings.name} should be used inside of ${DeploymentSettingsProvider.name}`, | ||
| ); | ||
| } | ||
| return context; | ||
| }; | ||
| const DeploymentSettingsProvider: FC = () => { | ||
| const { permissions } = useAuthenticated(); | ||
| const deploymentConfigQuery = useQuery(deploymentConfig()); | ||
| // The deployment settings page also contains users, audit logs, groups and | ||
| // organizations, so this page must be visible if you can see any of these. | ||
| const canViewDeploymentSettingsPage = | ||
| permissions.viewDeploymentValues || | ||
| permissions.viewAllUsers || | ||
| permissions.editAnyOrganization || | ||
| permissions.viewAnyAuditLog; | ||
| // Not a huge problem to unload the content in the event of an error, | ||
| // because the sidebar rendering isn't tied to this. Even if the user hits | ||
| // a 403 error, they'll still have navigation options | ||
| if (deploymentConfigQuery.error) { | ||
| return <ErrorAlert error={deploymentConfigQuery.error} />; | ||
| } | ||
| if (!deploymentConfigQuery.data) { | ||
| return <Loader />; | ||
| } | ||
| return ( | ||
| <RequirePermission isFeatureVisible={canViewDeploymentSettingsPage}> | ||
| <DeploymentSettingsContext.Provider | ||
| value={{ deploymentConfig: deploymentConfigQuery.data }} | ||
| > | ||
| <Outlet /> | ||
| </DeploymentSettingsContext.Provider> | ||
| </RequirePermission> | ||
| ); | ||
| }; | ||
| export default DeploymentSettingsProvider; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2,19 +2,15 @@ import { cx } from "@emotion/css"; | ||
| import type { Interpolation, Theme } from "@emotion/react"; | ||
| import AddIcon from "@mui/icons-material/Add"; | ||
| import SettingsIcon from "@mui/icons-material/Settings"; | ||
| import type { AuthorizationResponse, Organization } from "api/typesGenerated"; | ||
| import { FeatureStageBadge } from "components/FeatureStageBadge/FeatureStageBadge"; | ||
| 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 +26,7 @@ interface SidebarProps { | ||
| /** Organizations and their permissions or undefined if still fetching. */ | ||
| organizations: OrganizationWithPermissions[] | undefined; | ||
| /** Site-wide permissions. */ | ||
| permissions:Permissions; | ||
| } | ||
| /** | ||
| @@ -72,7 +68,7 @@ interface DeploymentSettingsNavigationProps { | ||
| /** Whether a deployment setting page is being viewed. */ | ||
| active: boolean; | ||
| /** Site-wide permissions. */ | ||
| permissions:Permissions; | ||
| } | ||
| /** | ||
| @@ -130,10 +126,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 +142,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 +166,7 @@ interface OrganizationsSettingsNavigationProps { | ||
| /** Organizations and their permissions or undefined if still fetching. */ | ||
| organizations: OrganizationWithPermissions[] | undefined; | ||
| /** Site-wide permissions. */ | ||
| permissions:Permissions; | ||
| } | ||
| /** | ||
| @@ -241,8 +240,6 @@ interface OrganizationSettingsNavigationProps { | ||
| const OrganizationSettingsNavigation: FC< | ||
| OrganizationSettingsNavigationProps | ||
| > = ({ active, organization }) => { | ||
| return ( | ||
| <> | ||
| <SidebarNavItem | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.