Skip to content

Commit

Permalink
fix: make permissions as optional params
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Oct 8, 2023
1 parent 86fcb49 commit d2d18a7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
27 changes: 18 additions & 9 deletions src/plugins/workspace/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ export function registerRoutes({
...result.result,
workspaces: result.result.workspaces.map((workspace) => ({
...workspace,
permissions: convertFromACL(workspace.permissions),
...(workspace.permissions
? { permissions: convertFromACL(workspace.permissions) }
: {}),
})),
},
},
Expand Down Expand Up @@ -163,7 +165,9 @@ export function registerRoutes({
...result,
result: {
...result.result,
permissions: convertFromACL(result.result.permissions),
...(result.result.permissions
? { permissions: convertFromACL(result.result.permissions) }
: {}),
},
},
});
Expand All @@ -182,9 +186,13 @@ export function registerRoutes({
const { attributes } = req.body;
const rawRequest = ensureRawRequest(req);
const authInfo = rawRequest?.auth?.credentials?.authInfo as { user_name?: string } | null;
const permissions = Array.isArray(attributes.permissions)
? attributes.permissions
: [attributes.permissions];
const { permissions: permissionsInAttributes, ...others } = attributes;
let permissions: WorkspaceRoutePermissionItem[] = [];
if (permissionsInAttributes) {
permissions = Array.isArray(permissionsInAttributes)
? permissionsInAttributes
: [permissionsInAttributes];
}

if (!!authInfo?.user_name) {
permissions.push({
Expand All @@ -206,8 +214,8 @@ export function registerRoutes({
logger,
},
{
...attributes,
permissions: convertToACL(permissions),
...others,
...(permissionsInAttributes ? { permissions: convertToACL(permissions) } : {}),
}
);
return res.ok({ body: result });
Expand All @@ -228,6 +236,7 @@ export function registerRoutes({
router.handleLegacyErrors(async (context, req, res) => {
const { id } = req.params;
const { attributes } = req.body;
const { permissions, ...others } = attributes;

const result = await client.update(
{
Expand All @@ -237,8 +246,8 @@ export function registerRoutes({
},
id,
{
...attributes,
permissions: convertToACL(attributes.permissions),
...others,
...(permissions ? { permissions: convertToACL(permissions) } : {}),
}
);
return res.ok({ body: result });
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/workspace/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '../../../core/server';

export interface WorkspaceAttributeWithPermission extends WorkspaceAttribute {
permissions: Permissions;
permissions?: Permissions;
}

export interface WorkspaceFindOptions {
Expand Down

0 comments on commit d2d18a7

Please sign in to comment.