-
Notifications
You must be signed in to change notification settings - Fork 928
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
1ad09fa
refactor: update layout so that sidebar always shows
Parkreiner 620bd3a
refactor: consolidate logic more
Parkreiner 7ee3cf0
fix: add redirect for base users
Parkreiner e889621
fix: update routing logic to not block on disabled queries
Parkreiner 36e0376
fix: update type misalignment
Parkreiner 032a75c
chore: format and tidy up
Parkreiner eea8bbd
fix: make sure you can't navigate directly to bare /deployment page
Parkreiner e6d4201
fix: add more granularity to redirect logic
Parkreiner 14fc68e
fix: prevent infinite redirect
Parkreiner a8fd9e6
fix: update redirects for /organizations routes
Parkreiner 0a36cd1
fix: format files
Parkreiner e6d772b
fix: tighten up types for permissions
Parkreiner 3752af5
Merge branch 'main' into mes/deploy-bug
Parkreiner 2068a4c
fix: update route checks to account for subroutes
Parkreiner 2fe3d53
fix: add e2e check to ensure that redirect hasn't happened
Parkreiner 3c41de0
fix: update stories to account for new dashboard logic
Parkreiner 162642e
fix: update out-of-date comment
Parkreiner 64c6f29
fix: update default value logic for storybook setup
Parkreiner e12a4aa
fix: update individual stories
Parkreiner b9b33c0
fix: finish storybook injection changes
Parkreiner f7df5ff
fix: add back separate empty state to satisfy tests
Parkreiner 6925294
fix: add tests and update code to account for missing cases
Parkreiner 9fc0afa
fix: apply formatting
Parkreiner 498e7ba
break out `DeploymentSettingsProvider`
aslilac 234c606
fix: apply changes from previous PR
Parkreiner 4496a75
fix: apply formatting
Parkreiner 9fcf3e7
Merge branch 'main' into mes/deploy-bug
Parkreiner 19fb6e5
Merge branch 'lilac/deployment-settings-provider' into mes/deploy-bug
Parkreiner 804255e
fix: delete invalid tests
Parkreiner d341175
fix: revert changes not caught in merge
Parkreiner f3e6659
fix: update spellcheck
Parkreiner ce67a66
fix: revert nits
Parkreiner 7e946a7
fix: apply feedback
Parkreiner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,6 +175,7 @@ | |
"unauthenticate", | ||
"unconvert", | ||
"untar", | ||
"userauth", | ||
"userspace", | ||
"VMID", | ||
"walkthrough", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
site/src/modules/management/DeploymentSettingsProvider.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
Experiments, | ||
Organization, | ||
} from "api/typesGenerated"; | ||
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 { linkToUsers } from "modules/navigation"; | ||
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: AuthorizationResponse; | ||
permissions: Permissions; | ||
} | ||
|
||
/** | ||
|
@@ -72,7 +68,7 @@ interface DeploymentSettingsNavigationProps { | |
/** Whether a deployment setting page is being viewed. */ | ||
active: boolean; | ||
/** Site-wide permissions. */ | ||
permissions: AuthorizationResponse; | ||
permissions: Permissions; | ||
} | ||
|
||
/** | ||
|
@@ -130,10 +126,11 @@ const DeploymentSettingsNavigation: FC<DeploymentSettingsNavigationProps> = ({ | |
{permissions.viewDeploymentValues && ( | ||
<SidebarNavSubItem href="network">Network</SidebarNavSubItem> | ||
)} | ||
{/* All users can view workspace regions. */} | ||
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 |
||
<SidebarNavSubItem href="workspace-proxies"> | ||
Workspace Proxies | ||
</SidebarNavSubItem> | ||
{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> | ||
)} | ||
<SidebarNavSubItem href="notifications"> | ||
<Stack direction="row" alignItems="center" spacing={1}> | ||
<span>Notifications</span> | ||
<FeatureStageBadge contentType="beta" size="sm" /> | ||
</Stack> | ||
</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: AuthorizationResponse; | ||
permissions: Permissions; | ||
} | ||
|
||
/** | ||
|
@@ -241,8 +240,6 @@ interface OrganizationSettingsNavigationProps { | |
const OrganizationSettingsNavigation: FC< | ||
OrganizationSettingsNavigationProps | ||
> = ({ active, organization }) => { | ||
const { experiments } = useDashboard(); | ||
|
||
return ( | ||
<> | ||
<SidebarNavItem | ||
|
11 changes: 3 additions & 8 deletions
11
site/src/pages/DeploymentSettingsPage/ExternalAuthSettingsPage/ExternalAuthSettingsPage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you delete this unused check then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry – I meant that the
org_id
property specifically didn't seem to be used anywhere