Skip to content

Commit dc240eb

Browse files
authored
fix: permissions missed after workspace update (opensearch-project#245)
* fix: permissions missed after workspace update Signed-off-by: Lin Wang <[email protected]> * remove not used imports Signed-off-by: Lin Wang <[email protected]> --------- Signed-off-by: Lin Wang <[email protected]>
1 parent d1fe469 commit dc240eb

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

src/plugins/workspace/public/workspace_client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type IResponse<T> =
3030
error?: string;
3131
};
3232

33-
type WorkspaceRoutePermissionItem = {
33+
type WorkspacePermissionItem = {
3434
modes: Array<
3535
| WorkspacePermissionMode.LibraryRead
3636
| WorkspacePermissionMode.LibraryWrite
@@ -177,7 +177,7 @@ export class WorkspaceClient {
177177
*/
178178
public async create(
179179
attributes: Omit<WorkspaceAttribute, 'id'>,
180-
permissions?: WorkspaceRoutePermissionItem[]
180+
permissions?: WorkspacePermissionItem[]
181181
): Promise<IResponse<WorkspaceAttribute>> {
182182
const path = this.getPath();
183183

@@ -265,7 +265,7 @@ export class WorkspaceClient {
265265
public async update(
266266
id: string,
267267
attributes: Partial<WorkspaceAttribute>,
268-
permissions?: WorkspaceRoutePermissionItem[]
268+
permissions?: WorkspacePermissionItem[]
269269
): Promise<IResponse<boolean>> {
270270
const path = this.getPath(id);
271271
const body = {

src/plugins/workspace/server/integration_tests/routes.test.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@
66
import { WorkspaceAttribute } from 'src/core/types';
77
import { omit } from 'lodash';
88
import * as osdTestServer from '../../../../core/test_helpers/osd_server';
9-
import { WorkspaceRoutePermissionItem } from '../types';
10-
import { WorkspacePermissionMode } from '../../../../core/server';
119
import { WORKSPACE_TYPE } from '../../../../core/server';
1210

13-
const testWorkspace: WorkspaceAttribute & {
14-
permissions: WorkspaceRoutePermissionItem;
15-
} = {
11+
const testWorkspace: WorkspaceAttribute = {
1612
id: 'fake_id',
1713
name: 'test_workspace',
1814
description: 'test_workspace_description',
@@ -120,6 +116,39 @@ describe('workspace service', () => {
120116
expect(getResult.body.success).toEqual(true);
121117
expect(getResult.body.result.name).toEqual('updated');
122118
});
119+
it('update with permission', async () => {
120+
const permission = {
121+
userId: 'foo',
122+
type: 'user',
123+
modes: ['read', 'library_read'],
124+
};
125+
const result: any = await osdTestServer.request
126+
.post(root, `/api/workspaces`)
127+
.send({
128+
attributes: omit(testWorkspace, 'id'),
129+
})
130+
.expect(200);
131+
132+
await osdTestServer.request
133+
.put(root, `/api/workspaces/${result.body.result.id}`)
134+
.send({
135+
attributes: {
136+
...omit(testWorkspace, 'id'),
137+
name: 'updated',
138+
},
139+
permissions: permission,
140+
})
141+
.expect(200);
142+
143+
const getResult = await osdTestServer.request.get(
144+
root,
145+
`/api/workspaces/${result.body.result.id}`
146+
);
147+
148+
expect(getResult.body.success).toEqual(true);
149+
expect(getResult.body.result.name).toEqual('updated');
150+
expect(getResult.body.result.permissions[0]).toEqual(permission);
151+
});
123152
it('delete', async () => {
124153
const result: any = await osdTestServer.request
125154
.post(root, `/api/workspaces`)

src/plugins/workspace/server/routes/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export function registerRoutes({
189189
id,
190190
{
191191
...attributes,
192-
...(finalPermissions.length ? { finalPermissions } : {}),
192+
...(finalPermissions.length ? { permissions: finalPermissions } : {}),
193193
}
194194
);
195195
return res.ok({ body: result });

0 commit comments

Comments
 (0)