1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-24 17:51:14 +02:00

feat: enforce email null when deleted is set (#10680)

## About the changes
When deleting a user we set the email to null and deleted_at to the
current date, there's no case where email is set and deleted_at is also
set.

We found some situations where this happens, specifically when SAML and
SCIM are used in conjunction
This commit is contained in:
Gastón Fournier 2025-09-23 14:43:53 +02:00 committed by GitHub
parent 4dd97b97f4
commit d33e57a05f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 1 deletions

View File

@ -16,7 +16,7 @@ const mockUser = (deletedDaysAgo: number | null, uniqueId: number) => {
? new Date(Date.now() - deletedDaysAgo * 24 * 60 * 60 * 1000) ? new Date(Date.now() - deletedDaysAgo * 24 * 60 * 60 * 1000)
: null; : null;
return { return {
email: `${uniqueId}.user@example.com`, email: deletedAt === null ? `${uniqueId}.user@example.com` : null,
email_hash: `${uniqueId}.user@example.com`, email_hash: `${uniqueId}.user@example.com`,
deleted_at: deletedAt, deleted_at: deletedAt,
}; };

View File

@ -0,0 +1,25 @@
exports.up = (db, callback) => {
db.runSql(
`
UPDATE users
SET deleted_at = NULL
WHERE deleted_at IS NOT NULL and length(email) > 0;
ALTER TABLE users
ADD CONSTRAINT deleted_at_requires_email_null
CHECK (deleted_at IS NULL OR email IS NULL);
`,
callback,
);
};
exports.down = (db, callback) => {
db.runSql(
`
ALTER TABLE users
DROP CONSTRAINT deleted_at_requires_email_null;
`,
callback,
);
};