Skip to content
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

fix: permissions missed after workspace update #245

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions src/plugins/workspace/public/workspace_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type IResponse<T> =
error?: string;
};

type WorkspaceRoutePermissionItem = {
type WorkspacePermissionItem = {
modes: Array<
| WorkspacePermissionMode.LibraryRead
| WorkspacePermissionMode.LibraryWrite
Expand Down Expand Up @@ -177,7 +177,7 @@ export class WorkspaceClient {
*/
public async create(
attributes: Omit<WorkspaceAttribute, 'id'>,
permissions?: WorkspaceRoutePermissionItem[]
permissions?: WorkspacePermissionItem[]
): Promise<IResponse<WorkspaceAttribute>> {
const path = this.getPath();

Expand Down Expand Up @@ -265,7 +265,7 @@ export class WorkspaceClient {
public async update(
id: string,
attributes: Partial<WorkspaceAttribute>,
permissions?: WorkspaceRoutePermissionItem[]
permissions?: WorkspacePermissionItem[]
): Promise<IResponse<boolean>> {
const path = this.getPath(id);
const body = {
Expand Down
39 changes: 34 additions & 5 deletions src/plugins/workspace/server/integration_tests/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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`)
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/workspace/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export function registerRoutes({
id,
{
...attributes,
...(finalPermissions.length ? { finalPermissions } : {}),
...(finalPermissions.length ? { permissions: finalPermissions } : {}),
}
);
return res.ok({ body: result });
Expand Down
Loading