Skip to content

Commit

Permalink
Fixed data subject for renamed child key
Browse files Browse the repository at this point in the history
  • Loading branch information
mariayord committed Jan 29, 2024
1 parent a041580 commit 3068260
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ 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.5.3 - tbd

### Fixed

- Data subject details logging for renamed key of child entity by `DELETE`

## Version 0.5.2 - 2023-12-08

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const _addKeysToWhere = (keys, row, alias) => {
.filter(key => !key.isAssociation && key.name !== 'IsActiveEntity')
.reduce((keys, key) => {
if (keys.length) keys.push('and')
keys.push({ ref: [alias, key.name] }, '=', { val: row[key.name] })
keys.push({ ref: [alias, key.name] }, '=', { val: row[key.name] || row._old?.[key.name] })
return keys
}, [])
}
Expand Down
28 changes: 28 additions & 0 deletions test/personal-data/crud.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2111,5 +2111,33 @@ describe('personal data audit logging in CRUD', () => {
expect(_logs).toContainMatchObject({ attributes: [{ name: 'aa_todo', old: 'boo', new: 'doo' }] })
expect(_logs).toContainMatchObject({ attributes: [{ name: 'aa_todo', old: 'who' }] })
})
test('rename child key', async () => {
const parentID = 'bcd4a37a-6319-4d52-bb48-02fd06b9aaaa'
const childID = 'c49fe764-75aa-49f1-9475-cf67cf0b03f7'
const data = {
ID: parentID,
subEntities: [
{
renamedID: childID,
name: 'foo'
}
]
}
await POST('/crud-4/RenamedMainEntities', data, { auth: ALICE })
expect(_logs.length).toBe(1)

// reset logs
_logs = []

await DELETE(`/crud-4/RenamedSubEntities(${childID})`, { auth: ALICE })
const object = { type: 'CRUD_4.RenamedSubEntities', id: { renamedID: childID } }
const data_subject = { id: { ID: parentID}, role: 'MainEntity', type: 'CRUD_4.RenamedMainEntities'}
expect(_logs.length).toBe(1)
expect(_logs).toContainMatchObject({
user: 'alice',
object,
data_subject
})
})
})
})
30 changes: 30 additions & 0 deletions test/personal-data/db/schema.cds
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,33 @@ annotate RBase with @PersonalData : {
lastName @PersonalData.IsPotentiallyPersonal;
creditCardNo @PersonalData.IsPotentiallySensitive;
}

entity MainEntities {
key ID : UUID;
name : String;
subEntities : Composition of many SubEntities
on subEntities.mainEntity = $self;
}

entity SubEntities {
key ID : UUID;
name : String;
mainEntity : Association to MainEntities;
}


annotate MainEntities with @PersonalData: {
EntitySemantics: 'DataSubject',
DataSubjectRole: 'MainEntity',
} {
ID @PersonalData.FieldSemantics : 'DataSubjectID';
name @PersonalData.IsPotentiallyPersonal;
}

annotate SubEntities with @PersonalData : {
EntitySemantics: 'DataSubjectDetails',
DataSubjectRole: 'MainEntity'
} {
mainEntity @PersonalData.FieldSemantics: 'DataSubjectID';
name @PersonalData.IsPotentiallyPersonal;
}
20 changes: 20 additions & 0 deletions test/personal-data/srv/crud-service.cds
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,23 @@ service CRUD_3 {
address as aa_address
};
}
@path : '/crud-4'
@requires: 'admin'
service CRUD_4 {

entity RenamedMainEntities as projection on db.MainEntities;

entity RenamedSubEntities as projection on db.SubEntities {
key ID as renamedID,
name,
mainEntity
};

}

annotate CRUD_4 with @(AuditLog.Operation: {
Read : false,
Insert: true,
Update: true,
Delete: true
});

0 comments on commit 3068260

Please sign in to comment.