From dc240ebe350120b7cbccf706f86775031744040b Mon Sep 17 00:00:00 2001 From: Lin Wang Date: Fri, 27 Oct 2023 18:25:28 +0800 Subject: [PATCH] fix: permissions missed after workspace update (#245) * fix: permissions missed after workspace update Signed-off-by: Lin Wang * remove not used imports Signed-off-by: Lin Wang --------- Signed-off-by: Lin Wang --- .../workspace/public/workspace_client.ts | 6 +-- .../server/integration_tests/routes.test.ts | 39 ++++++++++++++++--- src/plugins/workspace/server/routes/index.ts | 2 +- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/plugins/workspace/public/workspace_client.ts b/src/plugins/workspace/public/workspace_client.ts index 7d7e42d4af35..811d26cbf48d 100644 --- a/src/plugins/workspace/public/workspace_client.ts +++ b/src/plugins/workspace/public/workspace_client.ts @@ -30,7 +30,7 @@ type IResponse = error?: string; }; -type WorkspaceRoutePermissionItem = { +type WorkspacePermissionItem = { modes: Array< | WorkspacePermissionMode.LibraryRead | WorkspacePermissionMode.LibraryWrite @@ -177,7 +177,7 @@ export class WorkspaceClient { */ public async create( attributes: Omit, - permissions?: WorkspaceRoutePermissionItem[] + permissions?: WorkspacePermissionItem[] ): Promise> { const path = this.getPath(); @@ -265,7 +265,7 @@ export class WorkspaceClient { public async update( id: string, attributes: Partial, - permissions?: WorkspaceRoutePermissionItem[] + permissions?: WorkspacePermissionItem[] ): Promise> { const path = this.getPath(id); const body = { diff --git a/src/plugins/workspace/server/integration_tests/routes.test.ts b/src/plugins/workspace/server/integration_tests/routes.test.ts index 4d2b50e02f06..576beb259314 100644 --- a/src/plugins/workspace/server/integration_tests/routes.test.ts +++ b/src/plugins/workspace/server/integration_tests/routes.test.ts @@ -6,13 +6,9 @@ import { WorkspaceAttribute } from 'src/core/types'; import { omit } from 'lodash'; import * as osdTestServer from '../../../../core/test_helpers/osd_server'; -import { WorkspaceRoutePermissionItem } from '../types'; -import { WorkspacePermissionMode } from '../../../../core/server'; import { WORKSPACE_TYPE } from '../../../../core/server'; -const testWorkspace: WorkspaceAttribute & { - permissions: WorkspaceRoutePermissionItem; -} = { +const testWorkspace: WorkspaceAttribute = { id: 'fake_id', name: 'test_workspace', description: 'test_workspace_description', @@ -120,6 +116,39 @@ describe('workspace service', () => { expect(getResult.body.success).toEqual(true); expect(getResult.body.result.name).toEqual('updated'); }); + it('update with permission', async () => { + const permission = { + userId: 'foo', + type: 'user', + modes: ['read', 'library_read'], + }; + const result: any = await osdTestServer.request + .post(root, `/api/workspaces`) + .send({ + attributes: omit(testWorkspace, 'id'), + }) + .expect(200); + + await osdTestServer.request + .put(root, `/api/workspaces/${result.body.result.id}`) + .send({ + attributes: { + ...omit(testWorkspace, 'id'), + name: 'updated', + }, + permissions: permission, + }) + .expect(200); + + const getResult = await osdTestServer.request.get( + root, + `/api/workspaces/${result.body.result.id}` + ); + + expect(getResult.body.success).toEqual(true); + expect(getResult.body.result.name).toEqual('updated'); + expect(getResult.body.result.permissions[0]).toEqual(permission); + }); it('delete', async () => { const result: any = await osdTestServer.request .post(root, `/api/workspaces`) diff --git a/src/plugins/workspace/server/routes/index.ts b/src/plugins/workspace/server/routes/index.ts index c4d6d65a4a5c..0556200a6f5c 100644 --- a/src/plugins/workspace/server/routes/index.ts +++ b/src/plugins/workspace/server/routes/index.ts @@ -189,7 +189,7 @@ export function registerRoutes({ id, { ...attributes, - ...(finalPermissions.length ? { finalPermissions } : {}), + ...(finalPermissions.length ? { permissions: finalPermissions } : {}), } ); return res.ok({ body: result });