Skip to content

Commit 2fbbc7a

Browse files
authored
Merge branch 'main' into 108-contents_action_buttons
2 parents a9b0670 + 492471e commit 2fbbc7a

11 files changed

Lines changed: 229 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added Sharing get and update methods @pnicolli

packages/client/src/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ export default class PloneClient {
117117

118118
search = restapi.search;
119119

120+
getSharing = restapi.getSharing;
121+
updateSharing = restapi.updateSharing;
122+
120123
getSite = restapi.getSite;
121124

122125
getSource = restapi.getSource;

packages/client/src/restapi/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ export { deleteRules } from './rules/delete';
9191

9292
export { search } from './search/get';
9393

94+
export { getSharing } from './sharing/get';
95+
export { updateSharing } from './sharing/update';
96+
9497
export { getSite } from './site/get';
9598

9699
export { getSource } from './sources/get';
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import ploneClient from '../../client';
2+
import { setup, teardown } from '../../utils/test';
3+
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
4+
import type { RequestError } from '../types';
5+
6+
const cli = ploneClient.initialize({
7+
apiPath: 'http://localhost:55001/plone',
8+
});
9+
10+
await cli.login({ data: { login: 'admin', password: 'secret' } });
11+
12+
beforeEach(async () => {
13+
await setup();
14+
});
15+
16+
afterEach(async () => {
17+
await teardown();
18+
});
19+
20+
describe('Get Sharing', () => {
21+
test('Successful', async () => {
22+
const path = '/';
23+
24+
const result = await cli.getSharing({ path });
25+
26+
expect(result.data.inherit).toBe(true);
27+
});
28+
29+
test('Successful - page', async () => {
30+
const contentData = {
31+
'@type': 'Document',
32+
title: 'sharingtest',
33+
};
34+
35+
await cli.createContent({ path: '/', data: contentData });
36+
37+
const result = await cli.getSharing({ path: contentData.title });
38+
39+
expect(result.data.inherit).toBe(true);
40+
});
41+
42+
// TODO test sharing with search param
43+
44+
test('Failure', async () => {
45+
const path = 'blah';
46+
47+
try {
48+
await cli.getSharing({ path });
49+
} catch (err) {
50+
expect((err as RequestError).status).toBe(404);
51+
}
52+
});
53+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { z } from 'zod';
2+
import { apiRequest, type ApiRequestParams } from '../../api';
3+
import type { SharingResponse } from '@plone/types';
4+
import type PloneClient from '../../client';
5+
import type { RequestResponse } from '../types';
6+
7+
const getSharingSchema = z.object({
8+
path: z.string(),
9+
search: z.string().optional(),
10+
});
11+
12+
export type SharingArgs = z.infer<typeof getSharingSchema>;
13+
14+
export async function getSharing(
15+
this: PloneClient,
16+
{ path, search }: SharingArgs,
17+
): Promise<RequestResponse<SharingResponse>> {
18+
const validatedArgs = getSharingSchema.parse({
19+
path,
20+
search,
21+
});
22+
23+
const options: ApiRequestParams = {
24+
config: this.config,
25+
params: { search },
26+
};
27+
const sharingPath = `${validatedArgs.path}/@sharing`;
28+
29+
return apiRequest('get', sharingPath, options);
30+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { setup, teardown } from '../../utils/test';
2+
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
3+
import PloneClient from '../../client';
4+
import type { RequestError } from '../types';
5+
6+
const cli = PloneClient.initialize({
7+
apiPath: 'http://localhost:55001/plone',
8+
});
9+
10+
await cli.login({ data: { login: 'admin', password: 'secret' } });
11+
12+
beforeEach(async () => {
13+
await setup();
14+
});
15+
16+
afterEach(async () => {
17+
await teardown();
18+
});
19+
20+
describe('Sharing', () => {
21+
test('Successful', async () => {
22+
const path = '/';
23+
const contentData = {
24+
'@type': 'Document',
25+
title: 'sharingpage',
26+
};
27+
await cli.createContent({ path, data: contentData });
28+
29+
const result = await cli.updateSharing({
30+
path: contentData.title,
31+
data: {
32+
entries: [
33+
{
34+
id: 'AuthenticatedUsers',
35+
roles: {
36+
Contributor: true,
37+
Editor: false,
38+
Reader: false,
39+
Reviewer: false,
40+
},
41+
type: 'group',
42+
},
43+
],
44+
},
45+
});
46+
47+
expect(result.status).toBe(204);
48+
});
49+
50+
test('Failure', async () => {
51+
const path = '/';
52+
const contentData = {
53+
'@type': 'Document',
54+
title: 'sharingpage',
55+
};
56+
await cli.createContent({ path, data: contentData });
57+
58+
try {
59+
await cli.updateSharing({
60+
path: 'blah',
61+
data: {
62+
entries: [
63+
{
64+
id: 'AuthenticatedUsers',
65+
roles: {
66+
Contributor: true,
67+
Editor: false,
68+
Reader: false,
69+
Reviewer: false,
70+
},
71+
type: 'group',
72+
},
73+
],
74+
},
75+
});
76+
} catch (err) {
77+
expect((err as RequestError).status).toBe(404);
78+
}
79+
});
80+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { z } from 'zod';
2+
import { apiRequest, type ApiRequestParams } from '../../api';
3+
import { updateSharingDataSchema } from '../../validation/sharing';
4+
import type PloneClient from '../../client';
5+
import type { RequestResponse } from '../types';
6+
7+
export const updateSharingArgsSchema = z.object({
8+
path: z.string(),
9+
data: updateSharingDataSchema.optional(),
10+
});
11+
12+
export type UpdateSharingArgs = z.infer<typeof updateSharingArgsSchema>;
13+
14+
export async function updateSharing(
15+
this: PloneClient,
16+
{ path, data }: UpdateSharingArgs,
17+
): Promise<RequestResponse<void>> {
18+
const validatedArgs = updateSharingArgsSchema.parse({
19+
path,
20+
data,
21+
});
22+
23+
const options: ApiRequestParams = {
24+
data: validatedArgs.data,
25+
config: this.config,
26+
};
27+
28+
const sharingPath = `${validatedArgs.path}/@sharing`;
29+
30+
return apiRequest('post', sharingPath, options);
31+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { z } from 'zod';
2+
3+
export const updateSharingDataSchema = z.object({
4+
entries: z.array(
5+
z.object({
6+
id: z.string(),
7+
roles: z.record(z.string(), z.boolean()),
8+
type: z.string(),
9+
}),
10+
),
11+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added Sharing service types @pnicolli

packages/types/src/services/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export * from './relations';
2727
export * from './roles';
2828
export * from './rules';
2929
export * from './search';
30+
export * from './sharing';
3031
export * from './site';
3132
export * from './sources';
3233
export * from './system';

0 commit comments

Comments
 (0)