Skip to content
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: secure flag persisted as string #3430

Merged
merged 12 commits into from
May 24, 2023

Conversation

michaldziuba03
Copy link
Contributor

@michaldziuba03 michaldziuba03 commented May 16, 2023

What change does this PR introduce?

It makes secure flag persisted as boolean.

To be more specific it changes Integration mongoose schema, because credentials.secure had String type instead of Boolean and for that reason secure was persisted as string.

Second thing - I added transformer @TransformToBoolean, because frontend sends "true"/"false" values for credentials and DTO is typed as boolean what makes dto not reliable. Transformer transforms only "true"/"false" it doesn't work like value === "true" where any other value than "true" returns false.

New transformer is supposed to be used in combination with @IsBoolean validator. I also dropped my previous validator @IsBooleanAny because new transformer + regular @IsBoolean makes it obsolete and is just better.

New transformer can be used in places like dtos for query params where booleans are expected, because their values are always strings.

Why was this change needed?

Closes #3360

Other information (Screenshots)

@p-fernandez
Copy link
Contributor

@michaldziuba03 at first sight looks like a very good work but I am missing the way the current data is going to be migrated to be able to not break any user using Novu. How would you solve that issue in this PR?

@scopsy
Copy link
Contributor

scopsy commented May 16, 2023

@p-fernandez from my experience mongoose will perfrom casting from a string to boolean when fetching. I think we can do a small test for it. And if not, we can do quite an easily mongo db query for that (one for 'false' and one for 'true')

@michaldziuba03
Copy link
Contributor Author

michaldziuba03 commented May 16, 2023

@scopsy I think it depends because if .lean() is used somewhere in repository layer then mongoose returns "raw" data as is.

@michaldziuba03
Copy link
Contributor Author

michaldziuba03 commented May 17, 2023

@p-fernandez @scopsy

I decided to write migration script for changing type... but I have problem.

Mongoose casts types during updates so when I query something like { "credentials.secure": "true" } mongoose casts it to { "credentials.secure": true } and it updates from true to true :)

I know @novu/dal tries to abstract data access layer but I think I need direct access to connection and perform query using underlying mongodb driver.

I had problem with type casting by mongoose but I found _model property in BaseRepository and I was able to make "raw" query with underlying mongodb driver.

What do you think about my migration script?

@jainpawan21
Copy link
Member

@p-fernandez / @scopsy Can we please prioritize this PR?

Comment on lines 14 to 24
console.log('Start migration - update credentials.secure from string to boolean');

console.log('Updating from "true" to true...');
const resultTrue = await updateTrueValues();
console.log(`Matched: ${resultTrue.matchedCount}\nModified: ${resultTrue.modifiedCount} \n`);

console.log('Updating from "false" to false...');
const resultFalse = await updateFalseValues();
console.log(`Matched: ${resultFalse.matchedCount}\nModified: ${resultFalse.modifiedCount}`);

console.log('End migration.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Logger from @nestjs/common rather than console.log so we can track in out telemetry tools.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. In other migration scripts I have seen console.logs so I decided to use them in my script as well.

I switched to Nest.js Logger in recent changes.

@p-fernandez
Copy link
Contributor

@scopsy it looks ok from my side

@michaldziuba03
Copy link
Contributor Author

@scopsy @p-fernandez

@scopsy scopsy added this pull request to the merge queue May 24, 2023
Merged via the queue into novuhq:next with commit f75c15b May 24, 2023
31 of 34 checks passed
@michaldziuba03 michaldziuba03 deleted the fix-credentials-secure branch May 24, 2023 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[NV-2291] 🐛 Bug Report: APNs integration dialog does not allow turning Production off
5 participants