Skip to content

fix: fix permissions for workspace creation #17241

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 7 commits into from
Apr 3, 2025
Merged
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
Next Next commit
fix: format
  • Loading branch information
jaaydenh committed Apr 3, 2025
commit 19fcd6f1354dbabcb93a599cfd42c7af4c428ecc
7 changes: 3 additions & 4 deletions site/src/api/queries/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,9 @@ export const workspacePermissionsByOrganization = (
queryKey: ["workspaces", organizationIds.sort(), "permissions"],
queryFn: async () => {
const prefixedChecks = organizationIds.flatMap((orgId) =>
Object.entries(workspacePermissionChecks(orgId, userId)).map(([key, val]) => [
`${orgId}.${key}`,
val,
]),
Object.entries(workspacePermissionChecks(orgId, userId)).map(
([key, val]) => [`${orgId}.${key}`, val],
),
);

const response = await API.checkAuthorization({
Expand Down
5 changes: 4 additions & 1 deletion site/src/modules/permissions/workspaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export const workspacePermissionChecks = (organizationId: string, userId: string) =>
export const workspacePermissionChecks = (
organizationId: string,
userId: string,
) =>
({
createWorkspace: {
object: {
Expand Down
5 changes: 4 additions & 1 deletion site/src/pages/CreateWorkspacePage/CreateWorkspacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ const CreateWorkspacePage: FC = () => {
const permissionsQuery = useQuery(
templateQuery.data
? checkAuthorization({
checks: workspacePermissionChecks(templateQuery.data.organization_id, me.id),
checks: workspacePermissionChecks(
templateQuery.data.organization_id,
me.id,
),
})
: { enabled: false },
);
Expand Down
2 changes: 1 addition & 1 deletion site/src/pages/TemplatePage/TemplateLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { ErrorAlert } from "components/Alert/ErrorAlert";
import { Loader } from "components/Loader/Loader";
import { Margins } from "components/Margins/Margins";
import { TabLink, Tabs, TabsList } from "components/Tabs/Tabs";
import { workspacePermissionChecks } from "modules/permissions/workspaces";
import { useAuthenticated } from "contexts/auth/RequireAuth";
import { workspacePermissionChecks } from "modules/permissions/workspaces";
import {
type FC,
type PropsWithChildren,
Expand Down
21 changes: 10 additions & 11 deletions site/src/pages/TemplatePage/TemplatePageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,16 @@ export const TemplatePageHeader: FC<TemplatePageHeaderProps> = ({
<PageHeader
actions={
<>
{!template.deprecated &&
workspacePermissions.createWorkspace && (
<Button
variant="contained"
startIcon={<AddIcon />}
component={RouterLink}
to={`${templateLink}/workspace`}
>
Create Workspace
</Button>
)}
{!template.deprecated && workspacePermissions.createWorkspace && (
<Button
variant="contained"
startIcon={<AddIcon />}
component={RouterLink}
to={`${templateLink}/workspace`}
>
Create Workspace
</Button>
)}

{permissions.canUpdateTemplate && (
<TemplateMenu
Expand Down
Loading