Skip to content

Commit 3bacbe2

Browse files
fix: do not change track personal data (#98)
fix #97
1 parent 1581c92 commit 3bacbe2

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ npm add @cap-js/change-tracking
6868
## Annotations
6969

7070
> [!WARNING]
71-
> Please be aware that [**sensitive** or **personal** data](https://cap.cloud.sap/docs/guides/data-privacy/annotations#annotating-personal-data) should not be change tracked, since viewing the log allows users to circumvent [audit-logging](https://cap.cloud.sap/docs/guides/data-privacy/audit-logging#setup).
71+
> Please be aware that [**sensitive** or **personal** data](https://cap.cloud.sap/docs/guides/data-privacy/annotations#annotating-personal-data) (annotated with `@PersonalData`) is not change tracked, since viewing the log allows users to circumvent [audit-logging](https://cap.cloud.sap/docs/guides/data-privacy/audit-logging#setup).
7272
7373
All we need to do is to identify what should be change-tracked by annotating respective entities and elements in our model with the `@changelog` annotation. Following the [best practice of separation of concerns](https://cap.cloud.sap/docs/guides/domain-modeling#separation-of-concerns), we do so in a separate file _srv/change-tracking.cds_:
7474

@@ -544,4 +544,3 @@ We as members, contributors, and leaders pledge to make participation in our com
544544
## Licensing
545545

546546
Copyright 2023 SAP SE or an SAP affiliate company and contributors. Please see our [LICENSE](LICENSE) for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available [via the REUSE tool](https://api.reuse.software/info/github.com/cap-js/change-tracking).
547-

lib/template-processor.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ const _processElement = (processFn, row, key, elements, isRoot, pathSegments, pi
1212
const element = elements[key];
1313
const { plain } = picked;
1414

15-
if (plain) {
15+
// do not change-track personal data
16+
const isPersonalData = element && Object.keys(element).some(key => key.startsWith('@PersonalData'));
17+
if (plain && !isPersonalData) {
1618
/**
1719
* @type import('../../types/api').templateProcessorProcessFnArgs
1820
*/

tests/bookshop/db/schema.cds

+7
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ entity Customers : cuid {
212212
on orderItems.customer = $self;
213213
}
214214

215+
// do not change-track personal data
216+
annotate Customers with {
217+
name @PersonalData.IsPotentiallyPersonal;
218+
name @changelog
219+
};
220+
221+
215222
entity OrderHeader : cuid {
216223
status : String;
217224
}

tests/integration/service-api.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -322,4 +322,17 @@ describe("change log integration test", () => {
322322
expect(changes[0].valueChangedFrom).to.equal("2012-01-01");
323323
expect(changes[0].valueChangedTo).to.equal("");
324324
});
325+
326+
it("Do not change track personal data", async () => {
327+
const allCustomers = await SELECT.from(adminService.entities.Customers);
328+
await UPDATE(adminService.entities.Customers).where({ ID: allCustomers[0].ID }).with({
329+
name: 'John Doe',
330+
});
331+
332+
const changes = await SELECT.from(ChangeView).where({
333+
entity: "sap.capire.bookshop.Customers",
334+
});
335+
336+
expect(changes.length).to.equal(0);
337+
});
325338
});

0 commit comments

Comments
 (0)