Skip to content

Commit e8d3a6b

Browse files
committed
Fix permissions checks
1 parent 2cd2a31 commit e8d3a6b

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

packages/authorization-token/src/db/authorization-token.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const applyTokenPermissions = (
1313
): AuthorizationToken => {
1414
let result = token;
1515

16+
// @todo: fix this on SQL level
1617
if (token.relation !== "viewers") {
1718
result = {
1819
...result,
@@ -21,20 +22,30 @@ const applyTokenPermissions = (
2122
};
2223
}
2324

25+
// @todo: fix this on SQL level
2426
if (token.relation === "viewers") {
2527
result = {
2628
...result,
2729
canPublish: false,
2830
};
2931
}
3032

33+
// @todo: fix this on SQL level
3134
if (token.relation === "builders") {
3235
result = {
3336
...result,
3437
canPublish: false,
3538
};
3639
}
3740

41+
// @todo: fix this on SQL level
42+
if (token.relation === "administrators") {
43+
result = {
44+
...result,
45+
canPublish: true,
46+
};
47+
}
48+
3849
return result;
3950
};
4051

packages/project-build/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@webstudio-is/postrest": "workspace:*",
2525
"@webstudio-is/sdk": "workspace:*",
2626
"@webstudio-is/trpc-interface": "workspace:*",
27+
"@webstudio-is/authorization-token": "workspace:*",
2728
"nanoid": "^5.0.8",
2829
"zod": "^3.22.4"
2930
},

packages/project-build/src/db/build.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
authorizeProject,
88
type AppContext,
99
} from "@webstudio-is/trpc-interface/index.server";
10+
import { db as authDb } from "@webstudio-is/authorization-token/index.server";
1011
import {
1112
type Deployment,
1213
type Resource,
@@ -299,14 +300,31 @@ export const createProductionBuild = async (
299300
context: AppContext
300301
) => {
301302
const canBuild = await authorizeProject.hasProjectPermit(
302-
{ projectId: props.projectId, permit: "build" },
303+
{ projectId: props.projectId, permit: "edit" },
303304
context
304305
);
305306

306307
if (canBuild === false) {
307308
throw new AuthorizationError("You don't have access to build this project");
308309
}
309310

311+
// Get token permissions
312+
if (context.authorization.type === "token") {
313+
const permissions = await authDb.getTokenPermissions(
314+
{
315+
projectId: props.projectId,
316+
token: context.authorization.authToken,
317+
},
318+
context
319+
);
320+
321+
if (!permissions.canPublish) {
322+
throw new AuthorizationError(
323+
"The token does not have permission to build this project."
324+
);
325+
}
326+
}
327+
310328
const build = await context.postgrest.client.rpc("create_production_build", {
311329
project_id: props.projectId,
312330
deployment: JSON.stringify(props.deployment),

pnpm-lock.yaml

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)