Skip to content

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 33 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 Oct 24, 2024
620bd3a
refactor: consolidate logic more
Parkreiner Oct 24, 2024
7ee3cf0
fix: add redirect for base users
Parkreiner Oct 24, 2024
e889621
fix: update routing logic to not block on disabled queries
Parkreiner Oct 24, 2024
36e0376
fix: update type misalignment
Parkreiner Oct 24, 2024
032a75c
chore: format and tidy up
Parkreiner Oct 24, 2024
eea8bbd
fix: make sure you can't navigate directly to bare /deployment page
Parkreiner Oct 24, 2024
e6d4201
fix: add more granularity to redirect logic
Parkreiner Oct 24, 2024
14fc68e
fix: prevent infinite redirect
Parkreiner Oct 24, 2024
a8fd9e6
fix: update redirects for /organizations routes
Parkreiner Oct 24, 2024
0a36cd1
fix: format files
Parkreiner Oct 24, 2024
e6d772b
fix: tighten up types for permissions
Parkreiner Oct 25, 2024
3752af5
Merge branch 'main' into mes/deploy-bug
Parkreiner Oct 25, 2024
2068a4c
fix: update route checks to account for subroutes
Parkreiner Oct 25, 2024
2fe3d53
fix: add e2e check to ensure that redirect hasn't happened
Parkreiner Oct 25, 2024
3c41de0
fix: update stories to account for new dashboard logic
Parkreiner Oct 25, 2024
162642e
fix: update out-of-date comment
Parkreiner Oct 25, 2024
64c6f29
fix: update default value logic for storybook setup
Parkreiner Oct 25, 2024
e12a4aa
fix: update individual stories
Parkreiner Oct 25, 2024
b9b33c0
fix: finish storybook injection changes
Parkreiner Oct 25, 2024
f7df5ff
fix: add back separate empty state to satisfy tests
Parkreiner Oct 25, 2024
6925294
fix: add tests and update code to account for missing cases
Parkreiner Oct 25, 2024
9fc0afa
fix: apply formatting
Parkreiner Oct 25, 2024
498e7ba
break out `DeploymentSettingsProvider`
aslilac Oct 28, 2024
234c606
fix: apply changes from previous PR
Parkreiner Oct 28, 2024
4496a75
fix: apply formatting
Parkreiner Oct 28, 2024
9fcf3e7
Merge branch 'main' into mes/deploy-bug
Parkreiner Oct 28, 2024
19fb6e5
Merge branch 'lilac/deployment-settings-provider' into mes/deploy-bug
Parkreiner Oct 28, 2024
804255e
fix: delete invalid tests
Parkreiner Oct 28, 2024
d341175
fix: revert changes not caught in merge
Parkreiner Oct 28, 2024
f3e6659
fix: update spellcheck
Parkreiner Oct 28, 2024
ce67a66
fix: revert nits
Parkreiner Oct 28, 2024
7e946a7
fix: apply feedback
Parkreiner Oct 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: update redirects for /organizations routes
  • Loading branch information
Parkreiner committed Oct 24, 2024
commit a8fd9e640d58d910df88ce04c57fc958392b4ee3
45 changes: 25 additions & 20 deletions site/src/modules/management/ManagementSettingsLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useQuery } from "react-query";
import { Outlet, useLocation } from "react-router-dom";
import { Sidebar } from "./Sidebar";
import type { Permissions } from "contexts/auth/permissions";
import { useDashboard } from "modules/dashboard/useDashboard";

type ManagementSettingsValue = Readonly<{
deploymentValues: DeploymentConfig | undefined;
Expand Down Expand Up @@ -47,14 +48,25 @@ export const canEditOrganization = (
};

const isManagementRoutePermitted = (
href: string,
locationPath: string,
permissions: Permissions,
showOrganizations: boolean,
): boolean => {
console.log(href);
if (locationPath.startsWith("/organizations")) {
return showOrganizations;
}

if (!locationPath.startsWith("/deployment")) {
return false;
}

// Switch logic should mirror the conditions used to display the sidebar
// tabs from SidebarView.tsx
// Switch logic for deployment routes should mirror the conditions used to
// display the sidebar tabs from SidebarView.tsx
const href = locationPath.replace(/^\/deployment/, "");
switch (href) {
case "/": {
return true;
}
case "/general": {
return permissions.viewDeploymentValues;
}
Expand Down Expand Up @@ -102,6 +114,7 @@ const isManagementRoutePermitted = (
*/
export const ManagementSettingsLayout: FC = () => {
const location = useLocation();
const { showOrganizations } = useDashboard();
const { permissions } = useAuthenticated();
const deploymentConfigQuery = useQuery({
...deploymentConfig(),
Expand All @@ -115,7 +128,6 @@ export const ManagementSettingsLayout: FC = () => {
return <Loader />;
}

const href = location.pathname.replace(/^\/?deployment/, "");
const canViewAtLeastOneTab =
permissions.viewDeploymentValues ||
permissions.viewAllUsers ||
Expand All @@ -125,23 +137,16 @@ export const ManagementSettingsLayout: FC = () => {
return (
<RequirePermission
permitted={
canViewAtLeastOneTab && isManagementRoutePermitted(href, permissions)
canViewAtLeastOneTab &&
isManagementRoutePermitted(
location.pathname,
permissions,
showOrganizations,
)
}
unpermittedRedirect={
/**
* @todo 2024-10-14 - MES - The router logic is set up so that
* if the user goes to the /deployment page, they get redirected
* to the general page, purely for UX reasons (the /deployment
* page is empty). But it's not guaranteed that the user can see
* that page.
*
* Might be good to remove that router logic, and add a basic
* "landing" page to the /deployment route so that we can safely
* redirect the user there. But that will require coordination
* with the design team.
*/
canViewAtLeastOneTab && href !== "/general"
? "/deployment/general"
canViewAtLeastOneTab && !location.pathname.startsWith("/deployment")
? "/deployment"
: "/workspaces"
}
>
Expand Down
26 changes: 17 additions & 9 deletions site/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -426,16 +426,24 @@ export const router = createBrowserRouter(
</Route>
</Route>

{/**
* @todo 2024-10-24 - MES - The current deployment page is
* almost empty, which isn't great for two reasons:
*
* 1. Even though none of our links lead to the page, the
* user is still able to navigate straight there by
* accident.
* 2. If the user has access to some deployment pages, but
* tries accessing one that they shouldn't be able to
* access, we have to reroute them somewhere. The base
* deployment route is the only safe option, because not
* even the general page is accessible by everyone.
*
* Should update the base /deployment page so that there's
* something there, but that will require coordination with
* the design team.
*/}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really wish I could've added some content here, but it felt really out of scope. At the very least, better a janky experience over a broken one

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something to think together with @chrifro

<Route path="/deployment" element={<ManagementSettingsLayout />}>
{/*
None of the UI elements link directly to the base
/deployment route, but if you navigate there directly,
you would just see a mostly empty screen. Redirect to
the general page for better UX. */}
<Route
path=""
element={<Navigate to="/deployment/general" replace />}
/>
<Route path="general" element={<GeneralSettingsPage />} />
<Route path="licenses" element={<LicensesSettingsPage />} />
<Route path="licenses/add" element={<AddNewLicensePage />} />
Expand Down
Loading