@stamhoofd/backend 2.99.1 → 2.100.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +10 -10
- package/src/endpoints/admin/organizations/PatchOrganizationsEndpoint.ts +1 -1
- package/src/endpoints/global/events/PatchEventNotificationsEndpoint.test.ts +7 -1
- package/src/endpoints/global/events/PatchEventNotificationsEndpoint.ts +2 -2
- package/src/endpoints/global/events/PatchEventsEndpoint.test.ts +267 -0
- package/src/endpoints/global/events/PatchEventsEndpoint.ts +4 -4
- package/src/endpoints/global/members/GetMembersEndpoint.ts +1 -1
- package/src/endpoints/global/members/PatchOrganizationMembersEndpoint.ts +1 -1
- package/src/endpoints/global/organizations/SearchOrganizationEndpoint.test.ts +5 -2
- package/src/endpoints/global/platform/PatchPlatformEnpoint.test.ts +63 -0
- package/src/endpoints/global/platform/PatchPlatformEnpoint.ts +1 -1
- package/src/endpoints/global/registration/GetRegistrationsEndpoint.ts +1 -1
- package/src/endpoints/global/registration/RegisterMembersEndpoint.test.ts +4 -3
- package/src/endpoints/global/registration-periods/GetRegistrationPeriodsEndpoint.ts +2 -2
- package/src/endpoints/global/registration-periods/PatchRegistrationPeriodsEndpoint.ts +10 -3
- package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.test.ts +67 -2
- package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.ts +41 -29
- package/src/endpoints/organization/dashboard/registration-periods/GetOrganizationRegistrationPeriodsEndpoint.test.ts +32 -8
- package/src/endpoints/organization/dashboard/registration-periods/PatchOrganizationRegistrationPeriodsEndpoint.test.ts +206 -0
- package/src/endpoints/organization/dashboard/registration-periods/PatchOrganizationRegistrationPeriodsEndpoint.ts +35 -1
- package/src/helpers/AuthenticatedStructures.ts +1 -1
- package/src/helpers/FlagMomentCleanup.ts +105 -52
- package/src/helpers/PeriodHelper.ts +85 -2
- package/src/sql-filters/registration-periods.ts +1 -1
- package/tests/jest.setup.ts +2 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Request } from '@simonbackx/simple-endpoints';
|
|
2
|
-
import { GroupFactory, Organization, OrganizationFactory, Token, User, UserFactory, Webshop, WebshopFactory } from '@stamhoofd/models';
|
|
3
|
-
import { AccessRight, MemberResponsibility, OrganizationPrivateMetaData, Organization as OrganizationStruct, PermissionLevel, PermissionRoleDetailed, PermissionRoleForResponsibility, Permissions, PermissionsResourceType, ResourcePermissions, Version } from '@stamhoofd/structures';
|
|
2
|
+
import { GroupFactory, Organization, OrganizationFactory, OrganizationRegistrationPeriod, RegistrationPeriodFactory, Token, User, UserFactory, Webshop, WebshopFactory } from '@stamhoofd/models';
|
|
3
|
+
import { AccessRight, MemberResponsibility, OrganizationPrivateMetaData, OrganizationRegistrationPeriod as OrganizationRegistrationPeriodStruct, Organization as OrganizationStruct, PermissionLevel, PermissionRoleDetailed, PermissionRoleForResponsibility, Permissions, PermissionsResourceType, ResourcePermissions, Version } from '@stamhoofd/structures';
|
|
4
4
|
|
|
5
5
|
import { AutoEncoderPatchType, PatchableArray, PatchableArrayAutoEncoder, PatchMap } from '@simonbackx/simple-encoding';
|
|
6
|
+
import { STExpect, TestUtils } from '@stamhoofd/test-utils';
|
|
6
7
|
import { testServer } from '../../../../../tests/helpers/TestServer';
|
|
7
8
|
import { PatchOrganizationEndpoint } from './PatchOrganizationEndpoint';
|
|
8
9
|
|
|
@@ -10,6 +11,10 @@ describe('Endpoint.PatchOrganization', () => {
|
|
|
10
11
|
// Test endpoint
|
|
11
12
|
const endpoint = new PatchOrganizationEndpoint();
|
|
12
13
|
|
|
14
|
+
beforeEach(async () => {
|
|
15
|
+
TestUtils.setEnvironment('userMode', 'platform');
|
|
16
|
+
});
|
|
17
|
+
|
|
13
18
|
const patchOrganization = async ({ patch, organization, token }: { patch: AutoEncoderPatchType<OrganizationStruct> | OrganizationStruct; organization: Organization; token: Token }) => {
|
|
14
19
|
const request = Request.buildJson('PATCH', `/v${Version}/organization`, organization.getApiHost(), patch);
|
|
15
20
|
request.headers.authorization = 'Bearer ' + token.accessToken;
|
|
@@ -1274,4 +1279,64 @@ describe('Endpoint.PatchOrganization', () => {
|
|
|
1274
1279
|
});
|
|
1275
1280
|
});
|
|
1276
1281
|
});
|
|
1282
|
+
|
|
1283
|
+
describe('userMode organization', () => {
|
|
1284
|
+
beforeEach(async () => {
|
|
1285
|
+
TestUtils.setEnvironment('userMode', 'organization');
|
|
1286
|
+
});
|
|
1287
|
+
|
|
1288
|
+
test("Can't set period that belongs to no organization", async () => {
|
|
1289
|
+
const initialPeriod = await new RegistrationPeriodFactory({}).create();
|
|
1290
|
+
const organization = await new OrganizationFactory({ }).create();
|
|
1291
|
+
|
|
1292
|
+
organization.periodId = initialPeriod.id;
|
|
1293
|
+
await organization.save();
|
|
1294
|
+
|
|
1295
|
+
const user = await new UserFactory({ organization, permissions: Permissions.create({ level: PermissionLevel.Full }) }).create();
|
|
1296
|
+
const token = await Token.createToken(user);
|
|
1297
|
+
|
|
1298
|
+
const newPeriod = await new RegistrationPeriodFactory({}).create();
|
|
1299
|
+
|
|
1300
|
+
const newOrganizationPeriod = new OrganizationRegistrationPeriod();
|
|
1301
|
+
newOrganizationPeriod.organizationId = organization.id;
|
|
1302
|
+
newOrganizationPeriod.periodId = newPeriod.id;
|
|
1303
|
+
await newOrganizationPeriod.save();
|
|
1304
|
+
|
|
1305
|
+
const patch = OrganizationStruct.patch({
|
|
1306
|
+
id: organization.id,
|
|
1307
|
+
period: OrganizationRegistrationPeriodStruct.patch({ id: newOrganizationPeriod.id }),
|
|
1308
|
+
});
|
|
1309
|
+
|
|
1310
|
+
await expect(patchOrganization({ patch, organization, token })).rejects.toThrow(
|
|
1311
|
+
STExpect.simpleError({ code: 'invalid_field', field: 'period' }),
|
|
1312
|
+
);
|
|
1313
|
+
});
|
|
1314
|
+
|
|
1315
|
+
test("Can't set period that belongs to other organization", async () => {
|
|
1316
|
+
const initialPeriod = await new RegistrationPeriodFactory({}).create();
|
|
1317
|
+
const organization = await new OrganizationFactory({ }).create();
|
|
1318
|
+
|
|
1319
|
+
organization.periodId = initialPeriod.id;
|
|
1320
|
+
await organization.save();
|
|
1321
|
+
|
|
1322
|
+
const user = await new UserFactory({ organization, permissions: Permissions.create({ level: PermissionLevel.Full }) }).create();
|
|
1323
|
+
const token = await Token.createToken(user);
|
|
1324
|
+
|
|
1325
|
+
const otherOrganization = await new OrganizationFactory({ }).create();
|
|
1326
|
+
const newPeriod = await new RegistrationPeriodFactory({ organization: otherOrganization }).create();
|
|
1327
|
+
const newOrganizationPeriod = new OrganizationRegistrationPeriod();
|
|
1328
|
+
newOrganizationPeriod.organizationId = otherOrganization.id;
|
|
1329
|
+
newOrganizationPeriod.periodId = newPeriod.id;
|
|
1330
|
+
await newOrganizationPeriod.save();
|
|
1331
|
+
|
|
1332
|
+
const patch = OrganizationStruct.patch({
|
|
1333
|
+
id: organization.id,
|
|
1334
|
+
period: OrganizationRegistrationPeriodStruct.patch({ id: newOrganizationPeriod.id }),
|
|
1335
|
+
});
|
|
1336
|
+
|
|
1337
|
+
await expect(patchOrganization({ patch, organization, token })).rejects.toThrow(
|
|
1338
|
+
STExpect.simpleError({ code: 'invalid_field', field: 'period' }),
|
|
1339
|
+
);
|
|
1340
|
+
});
|
|
1341
|
+
});
|
|
1277
1342
|
});
|
|
@@ -355,7 +355,7 @@ export class PatchOrganizationEndpoint extends Endpoint<Params, Query, Body, Res
|
|
|
355
355
|
organization.uri = request.body.uri;
|
|
356
356
|
}
|
|
357
357
|
|
|
358
|
-
if (request.body.period
|
|
358
|
+
if (request.body.period) {
|
|
359
359
|
const organizationPeriod = await OrganizationRegistrationPeriod.getByID(request.body.period.id);
|
|
360
360
|
if (!organizationPeriod || organizationPeriod.organizationId !== organization.id) {
|
|
361
361
|
throw new SimpleError({
|
|
@@ -366,37 +366,49 @@ export class PatchOrganizationEndpoint extends Endpoint<Params, Query, Body, Res
|
|
|
366
366
|
});
|
|
367
367
|
}
|
|
368
368
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
369
|
+
if (organizationPeriod.periodId !== organization.periodId) {
|
|
370
|
+
const period = await RegistrationPeriod.getByID(organizationPeriod.periodId);
|
|
371
|
+
if (!period || (period.organizationId && period.organizationId !== organization.id)) {
|
|
372
|
+
throw new SimpleError({
|
|
373
|
+
code: 'invalid_field',
|
|
374
|
+
message: 'The period you want to set does not exist (anymore)',
|
|
375
|
+
human: $t('a3795bf6-ed50-4aa6-9caf-33820292c159'),
|
|
376
|
+
field: 'period',
|
|
377
|
+
});
|
|
378
|
+
}
|
|
378
379
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
380
|
+
if (STAMHOOFD.userMode === 'organization' && period.organizationId === null) {
|
|
381
|
+
// period should always have organization id if userMode is organization
|
|
382
|
+
throw new SimpleError({
|
|
383
|
+
code: 'invalid_field',
|
|
384
|
+
message: 'The period has no organization id',
|
|
385
|
+
human: $t('d004e93c-e67f-48ab-bf3d-7b4ad86c7a38'),
|
|
386
|
+
field: 'period',
|
|
387
|
+
});
|
|
388
|
+
}
|
|
387
389
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
}
|
|
396
|
-
|
|
390
|
+
if (period.locked) {
|
|
391
|
+
throw new SimpleError({
|
|
392
|
+
code: 'invalid_field',
|
|
393
|
+
message: 'The period you want to set is already closed',
|
|
394
|
+
human: $t('b6bc2fef-71ac-43a1-b430-50945427a9e3'),
|
|
395
|
+
field: 'period',
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const maximumStart = 1000 * 60 * 60 * 24 * 31 * 2; // 2 months in advance
|
|
400
|
+
if (period.startDate > new Date(Date.now() + maximumStart) && STAMHOOFD.environment !== 'development') {
|
|
401
|
+
throw new SimpleError({
|
|
402
|
+
code: 'invalid_field',
|
|
403
|
+
message: 'The period you want to set has not started yet',
|
|
404
|
+
human: $t('e0fff936-3f3c-46b8-adcf-c723c33907a2'),
|
|
405
|
+
field: 'period',
|
|
406
|
+
});
|
|
407
|
+
}
|
|
397
408
|
|
|
398
|
-
|
|
399
|
-
|
|
409
|
+
organization.periodId = period.id;
|
|
410
|
+
shouldUpdateSetupSteps = true;
|
|
411
|
+
}
|
|
400
412
|
}
|
|
401
413
|
|
|
402
414
|
// Save the organization
|
|
@@ -114,10 +114,26 @@ describe('Endpoint.GetOrganizationRegistrationPeriods', () => {
|
|
|
114
114
|
|
|
115
115
|
test('Should not contain groups of other organizations or periods', async () => {
|
|
116
116
|
// arrange
|
|
117
|
-
const
|
|
117
|
+
const period2 = await new RegistrationPeriodFactory({
|
|
118
|
+
startDate: new Date(2022, 0, 1),
|
|
119
|
+
endDate: new Date(2022, 11, 31),
|
|
120
|
+
}).create();
|
|
121
|
+
|
|
122
|
+
const period = await new RegistrationPeriodFactory({
|
|
123
|
+
startDate: new Date(2023, 0, 1),
|
|
124
|
+
endDate: new Date(2023, 11, 31),
|
|
125
|
+
previousPeriodId: period2.id,
|
|
126
|
+
}).create();
|
|
127
|
+
|
|
128
|
+
const organization = await initOrganization(period);
|
|
129
|
+
period.organizationId = organization.id;
|
|
130
|
+
await period.save();
|
|
131
|
+
period2.organizationId = organization.id;
|
|
132
|
+
await period2.save();
|
|
133
|
+
|
|
118
134
|
const organizationPeriod = await new OrganizationRegistrationPeriodFactory({
|
|
119
135
|
organization,
|
|
120
|
-
period
|
|
136
|
+
period,
|
|
121
137
|
}).create();
|
|
122
138
|
|
|
123
139
|
const user = await new UserFactory({
|
|
@@ -132,12 +148,12 @@ describe('Endpoint.GetOrganizationRegistrationPeriods', () => {
|
|
|
132
148
|
|
|
133
149
|
const group1 = await new GroupFactory({
|
|
134
150
|
organization,
|
|
135
|
-
period
|
|
151
|
+
period,
|
|
136
152
|
}).create();
|
|
137
153
|
|
|
138
154
|
const group2 = await new GroupFactory({
|
|
139
155
|
organization,
|
|
140
|
-
period
|
|
156
|
+
period,
|
|
141
157
|
}).create();
|
|
142
158
|
|
|
143
159
|
// Make sure the groups are in a category of the organization period
|
|
@@ -147,15 +163,23 @@ describe('Endpoint.GetOrganizationRegistrationPeriods', () => {
|
|
|
147
163
|
await organizationPeriod.save();
|
|
148
164
|
|
|
149
165
|
// group list of other organization
|
|
150
|
-
const
|
|
166
|
+
const otherPeriod = await new RegistrationPeriodFactory({
|
|
167
|
+
startDate: new Date(2023, 0, 1),
|
|
168
|
+
endDate: new Date(2023, 11, 31),
|
|
169
|
+
}).create();
|
|
170
|
+
|
|
171
|
+
const otherOrganization = await initOrganization(otherPeriod);
|
|
172
|
+
otherPeriod.organizationId = otherOrganization.id;
|
|
173
|
+
await otherPeriod.save();
|
|
174
|
+
|
|
151
175
|
const otherOrganizationPeriod = await new OrganizationRegistrationPeriodFactory({
|
|
152
176
|
organization: otherOrganization,
|
|
153
|
-
period:
|
|
177
|
+
period: otherPeriod,
|
|
154
178
|
}).create();
|
|
155
179
|
|
|
156
180
|
const otherGroup1 = await new GroupFactory({
|
|
157
181
|
organization: otherOrganization,
|
|
158
|
-
period:
|
|
182
|
+
period: otherPeriod,
|
|
159
183
|
}).create();
|
|
160
184
|
|
|
161
185
|
// Add the group to the other organization's period
|
|
@@ -165,7 +189,7 @@ describe('Endpoint.GetOrganizationRegistrationPeriods', () => {
|
|
|
165
189
|
// group of other period
|
|
166
190
|
await new GroupFactory({
|
|
167
191
|
organization,
|
|
168
|
-
period:
|
|
192
|
+
period: period2,
|
|
169
193
|
}).create();
|
|
170
194
|
|
|
171
195
|
// act
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { Request } from '@simonbackx/simple-endpoints';
|
|
2
|
+
import { GroupFactory, Organization, OrganizationFactory, OrganizationRegistrationPeriod, OrganizationRegistrationPeriodFactory, RegistrationPeriodFactory, Token, UserFactory } from '@stamhoofd/models';
|
|
3
|
+
import { GroupSettings, Group as GroupStruct, OrganizationRegistrationPeriod as OrganizationRegistrationPeriodStruct, PermissionLevel, Permissions, Version } from '@stamhoofd/structures';
|
|
4
|
+
|
|
5
|
+
import { PatchableArray, PatchableArrayAutoEncoder } from '@simonbackx/simple-encoding';
|
|
6
|
+
import { STExpect, TestUtils } from '@stamhoofd/test-utils';
|
|
7
|
+
import { testServer } from '../../../../../tests/helpers/TestServer';
|
|
8
|
+
import { PatchOrganizationRegistrationPeriodsEndpoint } from './PatchOrganizationRegistrationPeriodsEndpoint';
|
|
9
|
+
|
|
10
|
+
describe('Endpoint.PatchOrganizationRegistrationPeriods', () => {
|
|
11
|
+
// Test endpoint
|
|
12
|
+
const endpoint = new PatchOrganizationRegistrationPeriodsEndpoint();
|
|
13
|
+
|
|
14
|
+
beforeEach(async () => {
|
|
15
|
+
TestUtils.setEnvironment('userMode', 'platform');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const patchOrganizationRegistrationPeriods = async ({ patch, organization, token }: { patch: PatchableArrayAutoEncoder<OrganizationRegistrationPeriodStruct>; organization: Organization; token: Token }) => {
|
|
19
|
+
const request = Request.buildJson('PATCH', `/v${Version}/organization/registration-periods`, organization.getApiHost(), patch);
|
|
20
|
+
request.headers.authorization = 'Bearer ' + token.accessToken;
|
|
21
|
+
return await testServer.test(endpoint, request);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
describe('userMode organization', () => {
|
|
25
|
+
beforeEach(async () => {
|
|
26
|
+
TestUtils.setEnvironment('userMode', 'organization');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('should not be able to patch registration periods with global period', async () => {
|
|
30
|
+
const organization = await new OrganizationFactory({ }).create();
|
|
31
|
+
|
|
32
|
+
// create global period
|
|
33
|
+
const newPeriod = await new RegistrationPeriodFactory({}).create();
|
|
34
|
+
|
|
35
|
+
// create organization registration period linked to global period
|
|
36
|
+
const newOrganizationPeriod = new OrganizationRegistrationPeriod();
|
|
37
|
+
newOrganizationPeriod.organizationId = organization.id;
|
|
38
|
+
newOrganizationPeriod.periodId = newPeriod.id;
|
|
39
|
+
await newOrganizationPeriod.save();
|
|
40
|
+
|
|
41
|
+
const user = await new UserFactory({
|
|
42
|
+
organization,
|
|
43
|
+
permissions: Permissions.create({ level: PermissionLevel.Full }),
|
|
44
|
+
}).create();
|
|
45
|
+
|
|
46
|
+
const token = await Token.createToken(user);
|
|
47
|
+
|
|
48
|
+
const patch: PatchableArrayAutoEncoder<OrganizationRegistrationPeriodStruct> = new PatchableArray();
|
|
49
|
+
|
|
50
|
+
patch.addPatch(OrganizationRegistrationPeriodStruct.patch({
|
|
51
|
+
id: newOrganizationPeriod.id,
|
|
52
|
+
groups: new PatchableArray(),
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
// patch organization registration period should fail
|
|
56
|
+
await expect(patchOrganizationRegistrationPeriods({ patch, organization, token })).rejects.toThrow(
|
|
57
|
+
STExpect.simpleError({ code: 'not_found' }),
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('should be able to patch registration periods', async () => {
|
|
62
|
+
const organization = await new OrganizationFactory({ }).create();
|
|
63
|
+
|
|
64
|
+
// create period
|
|
65
|
+
const newPeriod = await new RegistrationPeriodFactory({ organization }).create();
|
|
66
|
+
|
|
67
|
+
// create organization registration period
|
|
68
|
+
const newOrganizationPeriod = new OrganizationRegistrationPeriod();
|
|
69
|
+
newOrganizationPeriod.organizationId = organization.id;
|
|
70
|
+
newOrganizationPeriod.periodId = newPeriod.id;
|
|
71
|
+
await newOrganizationPeriod.save();
|
|
72
|
+
|
|
73
|
+
const user = await new UserFactory({
|
|
74
|
+
organization,
|
|
75
|
+
permissions: Permissions.create({ level: PermissionLevel.Full }),
|
|
76
|
+
}).create();
|
|
77
|
+
|
|
78
|
+
const token = await Token.createToken(user);
|
|
79
|
+
|
|
80
|
+
const patch: PatchableArrayAutoEncoder<OrganizationRegistrationPeriodStruct> = new PatchableArray();
|
|
81
|
+
|
|
82
|
+
patch.addPatch(OrganizationRegistrationPeriodStruct.patch({
|
|
83
|
+
id: newOrganizationPeriod.id,
|
|
84
|
+
groups: new PatchableArray(),
|
|
85
|
+
}));
|
|
86
|
+
|
|
87
|
+
// patch organization registration period should not fail
|
|
88
|
+
const response = await patchOrganizationRegistrationPeriods({ patch, organization, token });
|
|
89
|
+
expect(response.body).toBeDefined();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('should not be able to create registration periods with global period', async () => {
|
|
93
|
+
const organization = await new OrganizationFactory({ }).create();
|
|
94
|
+
|
|
95
|
+
// create global period
|
|
96
|
+
const newPeriod = await new RegistrationPeriodFactory({}).create();
|
|
97
|
+
|
|
98
|
+
// create organization registration period linked to global period
|
|
99
|
+
const newOrganizationPeriod = OrganizationRegistrationPeriodStruct.create({
|
|
100
|
+
period: newPeriod.getStructure(),
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const user = await new UserFactory({
|
|
104
|
+
organization,
|
|
105
|
+
permissions: Permissions.create({ level: PermissionLevel.Full }),
|
|
106
|
+
}).create();
|
|
107
|
+
|
|
108
|
+
const token = await Token.createToken(user);
|
|
109
|
+
|
|
110
|
+
const patch: PatchableArrayAutoEncoder<OrganizationRegistrationPeriodStruct> = new PatchableArray();
|
|
111
|
+
|
|
112
|
+
patch.addPut(newOrganizationPeriod);
|
|
113
|
+
|
|
114
|
+
// patch organization registration period should fail
|
|
115
|
+
await expect(patchOrganizationRegistrationPeriods({ patch, organization, token })).rejects.toThrow(
|
|
116
|
+
STExpect.simpleError({ code: 'invalid_period' }),
|
|
117
|
+
);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test('should be able to create registration periods', async () => {
|
|
121
|
+
const organization = await new OrganizationFactory({ }).create();
|
|
122
|
+
|
|
123
|
+
// create period
|
|
124
|
+
const startDate = new Date(Date.now() + 5 * 24 * 60 * 60 * 1000);
|
|
125
|
+
const endDate = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000);
|
|
126
|
+
|
|
127
|
+
const newPeriod = await new RegistrationPeriodFactory({
|
|
128
|
+
organization,
|
|
129
|
+
startDate,
|
|
130
|
+
endDate,
|
|
131
|
+
}).create();
|
|
132
|
+
|
|
133
|
+
// create organization registration period
|
|
134
|
+
const newOrganizationPeriod = OrganizationRegistrationPeriodStruct.create({
|
|
135
|
+
period: newPeriod.getStructure(),
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const user = await new UserFactory({
|
|
139
|
+
organization,
|
|
140
|
+
permissions: Permissions.create({ level: PermissionLevel.Full }),
|
|
141
|
+
}).create();
|
|
142
|
+
|
|
143
|
+
const token = await Token.createToken(user);
|
|
144
|
+
|
|
145
|
+
const patch: PatchableArrayAutoEncoder<OrganizationRegistrationPeriodStruct> = new PatchableArray();
|
|
146
|
+
|
|
147
|
+
patch.addPut(newOrganizationPeriod);
|
|
148
|
+
|
|
149
|
+
// patch organization registration period should not fail
|
|
150
|
+
const response = await patchOrganizationRegistrationPeriods({ patch, organization, token });
|
|
151
|
+
expect(response.body).toBeDefined();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test('should not be able to patch groups of other organization', async () => {
|
|
155
|
+
const organization = await new OrganizationFactory({ }).create();
|
|
156
|
+
const otherOrganization = await new OrganizationFactory({ }).create();
|
|
157
|
+
|
|
158
|
+
// create period
|
|
159
|
+
const startDate = new Date(Date.now() + 5 * 24 * 60 * 60 * 1000);
|
|
160
|
+
const endDate = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000);
|
|
161
|
+
|
|
162
|
+
const newPeriod = await new RegistrationPeriodFactory({
|
|
163
|
+
organization,
|
|
164
|
+
startDate,
|
|
165
|
+
endDate,
|
|
166
|
+
}).create();
|
|
167
|
+
|
|
168
|
+
// create organization registration period
|
|
169
|
+
const newOrganizationPeriod = await new OrganizationRegistrationPeriodFactory({
|
|
170
|
+
organization,
|
|
171
|
+
period: newPeriod,
|
|
172
|
+
}).create();
|
|
173
|
+
|
|
174
|
+
const user = await new UserFactory({
|
|
175
|
+
organization,
|
|
176
|
+
permissions: Permissions.create({ level: PermissionLevel.Full }),
|
|
177
|
+
}).create();
|
|
178
|
+
|
|
179
|
+
const token = await Token.createToken(user);
|
|
180
|
+
|
|
181
|
+
// create group
|
|
182
|
+
const group = await new GroupFactory({ organization: otherOrganization }).create();
|
|
183
|
+
|
|
184
|
+
const patch: PatchableArrayAutoEncoder<OrganizationRegistrationPeriodStruct> = new PatchableArray();
|
|
185
|
+
const groupsPatch: PatchableArrayAutoEncoder<GroupStruct> = new PatchableArray();
|
|
186
|
+
|
|
187
|
+
// patch group
|
|
188
|
+
groupsPatch.addPatch(GroupStruct.patch({
|
|
189
|
+
id: group.id,
|
|
190
|
+
settings: GroupSettings.patch({
|
|
191
|
+
name: 'new name',
|
|
192
|
+
}),
|
|
193
|
+
}));
|
|
194
|
+
|
|
195
|
+
patch.addPatch(OrganizationRegistrationPeriodStruct.patch({
|
|
196
|
+
id: newOrganizationPeriod.id,
|
|
197
|
+
groups: groupsPatch,
|
|
198
|
+
}));
|
|
199
|
+
|
|
200
|
+
// patch organization registration period should fail because of group of other organization
|
|
201
|
+
await expect(patchOrganizationRegistrationPeriods({ patch, organization, token })).rejects.toThrow(
|
|
202
|
+
STExpect.simpleError({ code: 'permission_denied' }),
|
|
203
|
+
);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
});
|
|
@@ -54,6 +54,7 @@ export class PatchOrganizationRegistrationPeriodsEndpoint extends Endpoint<Param
|
|
|
54
54
|
|
|
55
55
|
for (const patch of request.body.getPatches()) {
|
|
56
56
|
const organizationPeriod = await OrganizationRegistrationPeriod.getByID(patch.id);
|
|
57
|
+
|
|
57
58
|
if (!organizationPeriod || organizationPeriod.organizationId !== organization.id) {
|
|
58
59
|
throw new SimpleError({
|
|
59
60
|
code: 'not_found',
|
|
@@ -65,7 +66,7 @@ export class PatchOrganizationRegistrationPeriodsEndpoint extends Endpoint<Param
|
|
|
65
66
|
|
|
66
67
|
const period = await RegistrationPeriod.getByID(organizationPeriod.periodId);
|
|
67
68
|
|
|
68
|
-
if (!period) {
|
|
69
|
+
if (!period || (STAMHOOFD.userMode === 'organization' && period.organizationId !== organization.id)) {
|
|
69
70
|
throw new SimpleError({
|
|
70
71
|
code: 'not_found',
|
|
71
72
|
message: 'Period not found',
|
|
@@ -287,6 +288,14 @@ export class PatchOrganizationRegistrationPeriodsEndpoint extends Endpoint<Param
|
|
|
287
288
|
});
|
|
288
289
|
}
|
|
289
290
|
|
|
291
|
+
if (STAMHOOFD.userMode === 'organization' && period.organizationId !== organization.id) {
|
|
292
|
+
throw new SimpleError({
|
|
293
|
+
code: 'invalid_period',
|
|
294
|
+
message: 'Period has different organization id',
|
|
295
|
+
statusCode: 400,
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
290
299
|
if (period?.locked) {
|
|
291
300
|
throw new SimpleError({
|
|
292
301
|
code: 'locked_period',
|
|
@@ -403,6 +412,14 @@ export class PatchOrganizationRegistrationPeriodsEndpoint extends Endpoint<Param
|
|
|
403
412
|
}
|
|
404
413
|
|
|
405
414
|
if (period) {
|
|
415
|
+
if (STAMHOOFD.userMode === 'organization' && period.organizationId !== model.organizationId) {
|
|
416
|
+
throw new SimpleError({
|
|
417
|
+
code: 'invalid_period',
|
|
418
|
+
message: 'Period has different organization id',
|
|
419
|
+
statusCode: 400,
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
|
|
406
423
|
model.periodId = period.id;
|
|
407
424
|
model.settings.period = period.getBaseStructure();
|
|
408
425
|
|
|
@@ -479,6 +496,15 @@ export class PatchOrganizationRegistrationPeriodsEndpoint extends Endpoint<Param
|
|
|
479
496
|
if (!requiredPeriod) {
|
|
480
497
|
throw new Error('Unexpected missing period when creating waiting list');
|
|
481
498
|
}
|
|
499
|
+
|
|
500
|
+
if (STAMHOOFD.userMode === 'organization' && requiredPeriod.organizationId !== model.organizationId) {
|
|
501
|
+
throw new SimpleError({
|
|
502
|
+
code: 'invalid_period',
|
|
503
|
+
message: 'Period has different organization id',
|
|
504
|
+
statusCode: 400,
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
|
|
482
508
|
const group = await PatchOrganizationRegistrationPeriodsEndpoint.createGroup(
|
|
483
509
|
patch.waitingList,
|
|
484
510
|
model.organizationId,
|
|
@@ -524,6 +550,14 @@ export class PatchOrganizationRegistrationPeriodsEndpoint extends Endpoint<Param
|
|
|
524
550
|
});
|
|
525
551
|
}
|
|
526
552
|
|
|
553
|
+
if (STAMHOOFD.userMode === 'organization' && (period.organizationId !== organizationId)) {
|
|
554
|
+
throw new SimpleError({
|
|
555
|
+
code: 'invalid_period',
|
|
556
|
+
message: 'Period has different organization id',
|
|
557
|
+
statusCode: 400,
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
|
|
527
561
|
const user = Context.auth.user;
|
|
528
562
|
|
|
529
563
|
const model = new Group();
|
|
@@ -5,8 +5,8 @@ import { Sorter } from '@stamhoofd/utility';
|
|
|
5
5
|
|
|
6
6
|
import { SQL } from '@stamhoofd/sql';
|
|
7
7
|
import { Formatter } from '@stamhoofd/utility';
|
|
8
|
-
import { Context } from './Context';
|
|
9
8
|
import { BalanceItemService } from '../services/BalanceItemService';
|
|
9
|
+
import { Context } from './Context';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Builds authenticated structures for the current user
|