Skip to content

chore: fixup permission story with multi-org on the UI #14049

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

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
toggle menu items
  • Loading branch information
Emyrk committed Jul 30, 2024
commit d1cacae97cf0f36a2a8db8d3527682c1390f6ccd
25 changes: 16 additions & 9 deletions site/src/contexts/auth/permissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { AuthorizationCheck } from "api/typesGenerated";
//
// Any check not using this language should be updated to use it.
export const checks = {
readAllUsers: "readAllUsers",
viewAllUsers: "viewAllUsers",
updateUsers: "updateUsers",
createUser: "createUser",
createAnyTemplate: "createAnyTemplate",
Expand All @@ -18,17 +18,24 @@ export const checks = {
viewAnyAuditLog: "viewAnyAuditLog",
viewDeploymentValues: "viewDeploymentValues",
createAnyGroup: "createAnyGroup",
viewUpdateCheck: "viewUpdateCheck",
viewExternalAuthConfig: "viewExternalAuthConfig",
updateDeploymentConfig: "updateDeploymentConfig",
viewDeploymentStats: "viewDeploymentStats",
editWorkspaceProxies: "editWorkspaceProxies",
viewAllLicenses: "viewAllLicenses",
} as const;

export const permissionsToCheck: Record<
keyof typeof checks,
AuthorizationCheck
> = {
[checks.readAllUsers]: {
[checks.viewAllLicenses]: {
object: {
resource_type: "license",
},
action: "read",
},
[checks.viewAllUsers]: {
object: {
resource_type: "user",
},
Expand Down Expand Up @@ -78,19 +85,19 @@ export const permissionsToCheck: Record<
},
action: "read",
},
[checks.updateDeploymentConfig]: {
object: {
resource_type: "deployment_config",
},
action: "update",
},
[checks.createAnyGroup]: {
object: {
resource_type: "group",
any_org: true,
},
action: "create",
},
[checks.viewUpdateCheck]: {
object: {
resource_type: "deployment_config",
},
action: "read",
},
[checks.viewExternalAuthConfig]: {
object: {
resource_type: "deployment_config",
Expand Down
2 changes: 1 addition & 1 deletion site/src/modules/dashboard/DashboardLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useUpdateCheck } from "./useUpdateCheck";

export const DashboardLayout: FC = () => {
const { permissions } = useAuthenticated();
const updateCheck = useUpdateCheck(permissions.viewUpdateCheck);
const updateCheck = useUpdateCheck(permissions.viewDeploymentValues);
const canViewDeployment = Boolean(permissions.viewDeploymentValues);

return (
Expand Down
2 changes: 1 addition & 1 deletion site/src/modules/dashboard/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const Navbar: FC = () => {
const canViewOrganizations =
featureVisibility.multiple_organizations &&
experiments.includes("multi-organization");
const canViewAllUsers = Boolean(permissions.readAllUsers);
const canViewAllUsers = Boolean(permissions.viewAllUsers);
const proxyContextValue = useProxy();
const canViewHealth = canViewDeployment;

Expand Down
65 changes: 44 additions & 21 deletions site/src/pages/ManagementSettingsPage/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import { useFeatureVisibility } from "modules/dashboard/useFeatureVisibility";
import { AUDIT_LINK, USERS_LINK, withFilter } from "modules/navigation";
import { useOrganizationSettings } from "./ManagementSettingsLayout";
import { useAuthenticated } from "contexts/auth/RequireAuth";

Check failure on line 15 in site/src/pages/ManagementSettingsPage/Sidebar.tsx

View workflow job for this annotation

GitHub Actions / lint

`contexts/auth/RequireAuth` import should occur before import of `hooks/useClassName`

Check failure on line 15 in site/src/pages/ManagementSettingsPage/Sidebar.tsx

View workflow job for this annotation

GitHub Actions / lint

`contexts/auth/RequireAuth` import should occur before import of `hooks/useClassName`

export const Sidebar: FC = () => {
const { organizations } = useOrganizationSettings();
Expand Down Expand Up @@ -62,6 +63,7 @@
}) => {
const location = useLocation();
const active = location.pathname.startsWith("/deployment");
const { permissions } = useAuthenticated();

return (
<div css={{ paddingBottom: 12 }}>
Expand All @@ -76,36 +78,57 @@
</SidebarNavItem>
{active && (
<Stack spacing={0.5} css={{ marginBottom: 8, marginTop: 8 }}>
<SidebarNavSubItem href="general">General</SidebarNavSubItem>
<SidebarNavSubItem href="licenses">Licenses</SidebarNavSubItem>
<SidebarNavSubItem href="appearance">Appearance</SidebarNavSubItem>
<SidebarNavSubItem href="userauth">
User Authentication
</SidebarNavSubItem>
<SidebarNavSubItem href="external-auth">
External Authentication
</SidebarNavSubItem>
{permissions.viewDeploymentValues && (
<SidebarNavSubItem href="general">General</SidebarNavSubItem>
)}
{permissions.viewAllLicenses && (
<SidebarNavSubItem href="licenses">Licenses</SidebarNavSubItem>
)}
{permissions.updateDeploymentConfig && (
<SidebarNavSubItem href="appearance">Appearance</SidebarNavSubItem>
)}
{permissions.viewDeploymentValues && (
<SidebarNavSubItem href="userauth">
User Authentication
</SidebarNavSubItem>
)}
{permissions.viewDeploymentValues && (
<SidebarNavSubItem href="external-auth">
External Authentication
</SidebarNavSubItem>
)}
{/* Not exposing this yet since token exchange is not finished yet.
<SidebarNavSubItem href="oauth2-provider/ap>
OAuth2 Applications
</SidebarNavSubItem>*/}
<SidebarNavSubItem href="network">Network</SidebarNavSubItem>
{permissions.viewDeploymentValues && (
<SidebarNavSubItem href="network">Network</SidebarNavSubItem>
)}
{/* All users can view workspace regions. */}
<SidebarNavSubItem href="workspace-proxies">
Workspace Proxies
</SidebarNavSubItem>
<SidebarNavSubItem href="security">Security</SidebarNavSubItem>
<SidebarNavSubItem href="observability">
Observability
</SidebarNavSubItem>
<SidebarNavSubItem href={USERS_LINK.slice(1)}>
Users
</SidebarNavSubItem>
{!organizationsEnabled && (
{permissions.viewDeploymentValues && (
<SidebarNavSubItem href="security">Security</SidebarNavSubItem>
)}
{permissions.viewDeploymentValues && (
<SidebarNavSubItem href="observability">
Observability
</SidebarNavSubItem>
)}
{permissions.viewAllUsers && (
<SidebarNavSubItem href={USERS_LINK.slice(1)}>
Users
</SidebarNavSubItem>
)}
{!organizationsEnabled && permissions.createAnyGroup && (
<SidebarNavSubItem href="groups">Groups</SidebarNavSubItem>
)}
<SidebarNavSubItem href={AUDIT_LINK.slice(1)}>
Auditing
</SidebarNavSubItem>
{permissions.viewAnyAuditLog && (
<SidebarNavSubItem href={AUDIT_LINK.slice(1)}>
Auditing
</SidebarNavSubItem>
)}
</Stack>
)}
</div>
Expand Down
5 changes: 3 additions & 2 deletions site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2477,14 +2477,15 @@ export const MockPermissions: Permissions = {
createUser: true,
deleteAllTemplates: true,
updateAllTemplates: true,
readAllUsers: true,
viewAllUsers: true,
updateUsers: true,
viewAnyAuditLog: true,
viewDeploymentValues: true,
viewUpdateCheck: true,
viewDeploymentStats: true,
viewExternalAuthConfig: true,
editWorkspaceProxies: true,
updateDeploymentConfig: true,
viewAllLicenses: true,
};

export const MockDeploymentConfig: DeploymentConfig = {
Expand Down
Loading