-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(repository): remove hidden properties from entities #1947
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,12 +49,17 @@ describe('DefaultCrudRepository', () => { | |
properties: { | ||
title: 'string', | ||
content: 'string', | ||
secret: 'string', | ||
id: {name: 'id', type: 'number', id: true}, | ||
}, | ||
settings: { | ||
hiddenProperties: ['secret'], | ||
}, | ||
}); | ||
|
||
title?: string; | ||
content?: string; | ||
secret?: string; | ||
id: number; | ||
|
||
constructor(data: Partial<Note>) { | ||
|
@@ -137,6 +142,18 @@ describe('DefaultCrudRepository', () => { | |
expect(result.toJSON()).to.eql(note.toJSON()); | ||
}); | ||
|
||
it('hides hidden properties', async () => { | ||
const repo = new DefaultCrudRepository(Note, ds); | ||
const note = await repo.create({ | ||
title: 't3', | ||
content: 'c3', | ||
secret: 'secret', | ||
}); | ||
expect(note.secret).to.be.undefined(); | ||
const result = await repo.findById(note.id); | ||
expect(result.secret).to.be.undefined(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is wrong behavior. In LB4, the Repository API is the only way how to access and modify model data. How are we going to modify secret properties after your change? IMO, the current implementation is correct, secret properties must stay available to JS/TS code. What we may need to change is the way how CRUD Controller methods and/or REST layer converts the data returned by remote methods into JSON payload send to the clients. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The repo.updateById(note.id, {secret: 'new-secret'}); But I agree with you that unconditionally removing them from CRUD is not ideal as we won't be able to support the use cases such as username/password verification. I propose the following:
|
||
}); | ||
|
||
it('implements Repository.createAll()', async () => { | ||
const repo = new DefaultCrudRepository(Note, ds); | ||
const notes = await repo.createAll([ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's stop growing the size of
Note
model please. Soon it will be way too large to reasonably work with.Create a new model for the new hiddenProperties tests. This new model should be small and contain only properties needed to verify how hidden properties are treated.