From 4b7a9ecad62cef2cd473292b25c936f7e4767a05 Mon Sep 17 00:00:00 2001 From: D050513 Date: Tue, 21 May 2024 09:07:03 +0200 Subject: [PATCH 1/2] stash --- CHANGELOG.md | 9 +++++- cds-plugin.js | 33 ++++++++++++-------- package.json | 5 ++- test/personal-data/deep.test.js | 10 ++++++ test/personal-data/srv/deep-service.cds | 41 +++++++++++++++++++++++++ 5 files changed, 83 insertions(+), 15 deletions(-) create mode 100644 test/personal-data/deep.test.js create mode 100644 test/personal-data/srv/deep-service.cds diff --git a/CHANGELOG.md b/CHANGELOG.md index f027ada..0923c73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,14 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). The format is based on [Keep a Changelog](http://keepachangelog.com/). -## Version 0.7.0 - tbd +## Version 0.8.0 - TBD + +### Added + +- Default kind `audit-log-to-restv2` for profile `hybrid` +- Support for @sap/cds^8 + +## Version 0.7.0 - 2024-05-15 ### Added diff --git a/cds-plugin.js b/cds-plugin.js index 84ffcdb..04cf1e1 100644 --- a/cds-plugin.js +++ b/cds-plugin.js @@ -6,6 +6,18 @@ const { hasPersonalData } = require('./lib/utils') const WRITE = ['CREATE', 'UPDATE', 'DELETE'] +const _get_ancestry_of = (entity, service, ancestors = []) => { + for (const each of service.entities) { + for (const k in each.compositions) { + if (each.compositions[k].target === entity.name && k !== 'SiblingEntity') { + ancestors.push(each) + _get_ancestry_of(each, service, ancestors) + } + } + } + return ancestors +} + /* * Add generic audit logging handlers */ @@ -15,24 +27,19 @@ cds.on('served', services => { for (const service of services) { if (!(service instanceof cds.ApplicationService)) continue - const relevantEntities = [] - for (const entity of service.entities) if (hasPersonalData(entity)) relevantEntities.push(entity) - if (!relevantEntities.length) continue - // automatically promote entities that are associated with data subjects - for (const entity of relevantEntities) { + for (const entity of service.entities) { if (entity['@PersonalData.EntitySemantics'] !== 'DataSubject') continue - for (const e of service.entities) { - for (const k in e.associations) { - if (e.associations[k].target === entity.name && k !== 'SiblingEntity') { - e['@PersonalData.EntitySemantics'] ??= 'Other' - e.associations[k]['@PersonalData.FieldSemantics'] ??= 'DataSubjectID' - if (!relevantEntities.includes(e)) relevantEntities.push(e) - } - } + const ancestors = _get_ancestry_of(entity, service) + for (const each of ancestors) { + each['@PersonalData.EntitySemantics'] ??= 'Other' } } + const relevantEntities = [] + for (const entity of service.entities) if (hasPersonalData(entity)) relevantEntities.push(entity) + if (!relevantEntities.length) continue + for (const entity of relevantEntities) { /* * data access diff --git a/package.json b/package.json index 5860363..2f849e2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cap-js/audit-logging", - "version": "0.7.0", + "version": "0.8.0", "description": "CDS plugin providing integration to the SAP Audit Log service as well as out-of-the-box personal data-related audit logging based on annotations.", "repository": "cap-js/audit-logging", "author": "SAP SE (https://www.sap.com)", @@ -44,6 +44,9 @@ "[development]": { "kind": "audit-log-to-console" }, + "[hybrid]": { + "kind": "audit-log-to-restv2" + }, "[production]": { "kind": "audit-log-to-restv2" } diff --git a/test/personal-data/deep.test.js b/test/personal-data/deep.test.js new file mode 100644 index 0000000..222b995 --- /dev/null +++ b/test/personal-data/deep.test.js @@ -0,0 +1,10 @@ +const cds = require('@sap/cds') + +cds.test('serve', 'srv/deep-service.cds').in(__dirname) + +describe('personal data audit logging for deep operations', () => { + test('promotions', async () => { + const { DeepService } = cds.services + debugger + }) +}) diff --git a/test/personal-data/srv/deep-service.cds b/test/personal-data/srv/deep-service.cds new file mode 100644 index 0000000..b8943a1 --- /dev/null +++ b/test/personal-data/srv/deep-service.cds @@ -0,0 +1,41 @@ +service DeepService { + + entity Foo { + key ID : UUID; + bars : Composition of many Bar + on bars.foo = $self; + moos : Composition of many { + key ID : UUID; + descr : String; + shus : Composition of many { + key ID : UUID; + descr : String; + }; + }; + }; + + entity Bar { + key ID : UUID; + foo : Association to Foo; + descr : String; + bazs : Composition of many Baz + on bazs.bar = $self; + }; + + entity Baz { + key ID : UUID; + bar : Association to Bar; + descr : String; + }; + + annotate Baz with @PersonalData: {EntitySemantics: 'DataSubject'} { + ID @PersonalData : {FieldSemantics: 'DataSubjectID', }; + descr @PersonalData.IsPotentiallyPersonal; + }; + + annotate Foo.moos.shus with @PersonalData: {EntitySemantics: 'DataSubject'} { + ID @PersonalData : {FieldSemantics: 'DataSubjectID', }; + descr @PersonalData.IsPotentiallyPersonal; + }; + +} From d62b5f0783c78f0ca5679156a7787ba780a1fccf Mon Sep 17 00:00:00 2001 From: sjvans <30337871+sjvans@users.noreply.github.com> Date: Thu, 23 May 2024 23:18:01 +0200 Subject: [PATCH 2/2] revert unrelated changes --- CHANGELOG.md | 9 +-------- package.json | 5 +---- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0923c73..f027ada 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,14 +4,7 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). The format is based on [Keep a Changelog](http://keepachangelog.com/). -## Version 0.8.0 - TBD - -### Added - -- Default kind `audit-log-to-restv2` for profile `hybrid` -- Support for @sap/cds^8 - -## Version 0.7.0 - 2024-05-15 +## Version 0.7.0 - tbd ### Added diff --git a/package.json b/package.json index 2f849e2..5860363 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cap-js/audit-logging", - "version": "0.8.0", + "version": "0.7.0", "description": "CDS plugin providing integration to the SAP Audit Log service as well as out-of-the-box personal data-related audit logging based on annotations.", "repository": "cap-js/audit-logging", "author": "SAP SE (https://www.sap.com)", @@ -44,9 +44,6 @@ "[development]": { "kind": "audit-log-to-console" }, - "[hybrid]": { - "kind": "audit-log-to-restv2" - }, "[production]": { "kind": "audit-log-to-restv2" }