Fix bug with updating overwritten secrets

This commit is contained in:
Daniel Hougaard
2023-11-28 12:07:02 +04:00
parent 8e33692cda
commit d5c5495475
2 changed files with 22 additions and 20 deletions

View File

@@ -1116,25 +1116,27 @@ export const updateSecretByName = async (req: Request, res: Response) => {
authData: req.authData
});
if (
(secretReminderCron && existingSecret.secretReminderCron !== secretReminderCron) ||
(secretReminderNote && existingSecret.secretReminderNote !== secretReminderNote)
) {
await createReminder(existingSecret, {
_id: existingSecret._id,
secretReminderCron,
secretReminderNote,
workspace: existingSecret.workspace
});
} else if (
secretReminderCron === null &&
secretReminderNote === null &&
existingSecret.secretReminderCron
) {
await deleteReminder({
_id: existingSecret._id,
secretReminderCron: existingSecret.secretReminderCron
});
if (secretReminderCron !== undefined) {
if (
(secretReminderCron && existingSecret.secretReminderCron !== secretReminderCron) ||
(secretReminderNote && existingSecret.secretReminderNote !== secretReminderNote)
) {
await createReminder(existingSecret, {
_id: existingSecret._id,
secretReminderCron,
secretReminderNote,
workspace: existingSecret.workspace
});
} else if (
secretReminderCron === null &&
secretReminderNote === null &&
existingSecret.secretReminderCron
) {
await deleteReminder({
_id: existingSecret._id,
secretReminderCron: existingSecret.secretReminderCron
});
}
}
}

View File

@@ -368,7 +368,7 @@ export const UpdateSecretByNameV3 = z.object({
.trim()
.optional()
.nullable()
.refine((val) => val === null || (val && isValidCron(val))),
.refine((val) => val === null || val === undefined || (val && isValidCron(val))),
secretReminderNote: z.string().trim().nullable().optional(),
tags: z.string().array().optional(),