@stamhoofd/backend 2.77.0 → 2.77.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stamhoofd/backend",
3
- "version": "2.77.0",
3
+ "version": "2.77.1",
4
4
  "main": "./dist/index.js",
5
5
  "exports": {
6
6
  ".": {
@@ -37,14 +37,14 @@
37
37
  "@simonbackx/simple-encoding": "2.20.0",
38
38
  "@simonbackx/simple-endpoints": "1.19.1",
39
39
  "@simonbackx/simple-logging": "^1.0.1",
40
- "@stamhoofd/backend-i18n": "2.77.0",
41
- "@stamhoofd/backend-middleware": "2.77.0",
42
- "@stamhoofd/email": "2.77.0",
43
- "@stamhoofd/models": "2.77.0",
44
- "@stamhoofd/queues": "2.77.0",
45
- "@stamhoofd/sql": "2.77.0",
46
- "@stamhoofd/structures": "2.77.0",
47
- "@stamhoofd/utility": "2.77.0",
40
+ "@stamhoofd/backend-i18n": "2.77.1",
41
+ "@stamhoofd/backend-middleware": "2.77.1",
42
+ "@stamhoofd/email": "2.77.1",
43
+ "@stamhoofd/models": "2.77.1",
44
+ "@stamhoofd/queues": "2.77.1",
45
+ "@stamhoofd/sql": "2.77.1",
46
+ "@stamhoofd/structures": "2.77.1",
47
+ "@stamhoofd/utility": "2.77.1",
48
48
  "archiver": "^7.0.1",
49
49
  "aws-sdk": "^2.885.0",
50
50
  "axios": "1.6.8",
@@ -64,5 +64,5 @@
64
64
  "publishConfig": {
65
65
  "access": "public"
66
66
  },
67
- "gitHead": "209036d412e24fefe961eeeeaa5a8618297bfcd7"
67
+ "gitHead": "e6d9dce8ddfdfaf5380e98f3a0ffd113a3826955"
68
68
  }
@@ -42,9 +42,18 @@ export class GetAuditLogsEndpoint extends Endpoint<Params, Query, Body, Response
42
42
  if (!await Context.auth.hasFullAccess(organization.id)) {
43
43
  throw Context.auth.error();
44
44
  }
45
- scopeFilter = {
46
- organizationId: organization.id,
47
- };
45
+ if (!Context.auth.hasPlatformFullAccess()) {
46
+ scopeFilter = {
47
+ organizationId: organization.id,
48
+ };
49
+ } else {
50
+ if (!q.filter || typeof q.filter !== 'object' || !('objectId' in q.filter)) {
51
+ scopeFilter = {
52
+ organizationId: organization.id,
53
+ };
54
+ }
55
+
56
+ }
48
57
  }
49
58
  else {
50
59
  if (!Context.auth.hasPlatformFullAccess()) {
@@ -2,8 +2,8 @@ import { OneToManyRelation } from '@simonbackx/simple-database';
2
2
  import { ConvertArrayToPatchableArray, Decoder, PatchableArrayAutoEncoder, PatchableArrayDecoder, StringDecoder } from '@simonbackx/simple-encoding';
3
3
  import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
4
4
  import { SimpleError } from '@simonbackx/simple-errors';
5
- import { BalanceItem, Document, Group, Member, MemberFactory, MemberPlatformMembership, MemberResponsibilityRecord, MemberWithRegistrations, mergeTwoMembers, Organization, Platform, RateLimiter, Registration, RegistrationPeriod, User } from '@stamhoofd/models';
6
- import { GroupType, MembersBlob, MemberWithRegistrationsBlob, PermissionLevel } from '@stamhoofd/structures';
5
+ import { AuditLog, BalanceItem, Document, Group, Member, MemberFactory, MemberPlatformMembership, MemberResponsibilityRecord, MemberWithRegistrations, mergeTwoMembers, Organization, Platform, RateLimiter, Registration, RegistrationPeriod, User } from '@stamhoofd/models';
6
+ import { AuditLogReplacement, AuditLogReplacementType, AuditLogSource, AuditLogType, GroupType, MembersBlob, MemberWithRegistrationsBlob, PermissionLevel } from '@stamhoofd/structures';
7
7
  import { Formatter } from '@stamhoofd/utility';
8
8
 
9
9
  import { Email } from '@stamhoofd/email';
@@ -17,6 +17,7 @@ import { SetupStepUpdater } from '../../../helpers/SetupStepUpdater';
17
17
  import { PlatformMembershipService } from '../../../services/PlatformMembershipService';
18
18
  import { RegistrationService } from '../../../services/RegistrationService';
19
19
  import { shouldCheckIfMemberIsDuplicateForPatch, shouldCheckIfMemberIsDuplicateForPut } from './shouldCheckIfMemberIsDuplicate';
20
+ import { AuditLogService } from '../../../services/AuditLogService';
20
21
 
21
22
  type Params = Record<string, never>;
22
23
  type Query = undefined;
@@ -794,6 +795,29 @@ export class PatchOrganizationMembersEndpoint extends Endpoint<Params, Query, Bo
794
795
 
795
796
  // Grant temporary access to this member without needing to enter the security code again
796
797
  await Context.auth.temporarilyGrantMemberAccess(member, PermissionLevel.Write);
798
+
799
+ const log = new AuditLog();
800
+
801
+ // a member has multiple organizations, so this is difficult to determine - for now it is only visible in the admin panel
802
+ log.organizationId = member.organizationId;
803
+
804
+ log.type = AuditLogType.MemberSecurityCodeUsed;
805
+ log.source = AuditLogSource.Anonymous;
806
+
807
+ if (Context.user) {
808
+ log.userId = Context.user.id;
809
+ log.source = AuditLogSource.User;
810
+ }
811
+
812
+ log.objectId = member.id;
813
+ log.replacements = new Map([
814
+ ['m', AuditLogReplacement.create({
815
+ value: member.details.name,
816
+ type: AuditLogReplacementType.Member,
817
+ id: member.id,
818
+ })],
819
+ ]);
820
+ await log.save();
797
821
  }
798
822
  else {
799
823
  throw new SimpleError({
@@ -87,6 +87,7 @@ describe('Endpoint.PatchUserMembersEndpoint', () => {
87
87
  expect(member.details.lastName).toBe(lastName);
88
88
  expect(member.details.birthDay).toEqual(existingMember.details.birthDay);
89
89
  expect(member.details.email).toBe('anewemail@example.com'); // this has been merged
90
+ expect(member.details.alternativeEmails).toHaveLength(0);
90
91
  });
91
92
 
92
93
  test('A duplicate member with existing registrations returns those registrations after a merge', async () => {
@@ -96,6 +97,7 @@ describe('Endpoint.PatchUserMembersEndpoint', () => {
96
97
  firstName,
97
98
  lastName,
98
99
  securityCode: 'ABC-123',
100
+ email: 'original@example.com',
99
101
  parents: [
100
102
  Parent.create({
101
103
  firstName: 'Jane',
@@ -146,7 +148,8 @@ describe('Endpoint.PatchUserMembersEndpoint', () => {
146
148
  expect(member.details.firstName).toBe(firstName);
147
149
  expect(member.details.lastName).toBe(lastName);
148
150
  expect(member.details.birthDay).toEqual(existingMember.details.birthDay);
149
- expect(member.details.email).toBe('anewemail@example.com'); // this has been merged
151
+ expect(member.details.email).toBe('original@example.com'); // this has been merged
152
+ expect(member.details.alternativeEmails).toEqual(['anewemail@example.com']); // this has been merged
150
153
 
151
154
  // Check the registration is still there
152
155
  expect(member.registrations.length).toBe(1);