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

Nv 2215 delete messagetemplates of deleted templates #3524

Merged
merged 13 commits into from
Jun 10, 2023

Conversation

BiswaViraj
Copy link
Member

What change does this PR introduce?

  • Delete the message templates and add them to the changes upon deletion of the Notification template

Why was this change needed?

Other information (Screenshots)

@linear
Copy link

linear bot commented May 29, 2023

NV-2215 delete messageTemplates of deleted templates

Why? (Context)

Within each Template, we have steps. each step has messageTemplate (content). When the user delete the templates, message templates are not deleted.

What?

As message templates are still there without the parent template, in the case of an in-app step, the feed is associated with the message template, User is not able to delete the feed

Definition of Done

  1. message templates should be deleted with the deletion of the template
  2. user should be able to delete the feed
  3. to check if the feed can be deleted in there are some sent notifications of this template.
  4. Do we need to delete previously sent notifications of this template also if the user delete the template
  5. A change should be generated to promote to production

@BiswaViraj BiswaViraj force-pushed the nv-2215-delete-messagetemplates-of-deleted-templates branch from 5e07a28 to c24ada1 Compare May 29, 2023 05:31
Comment on lines +195 to +198
reset({
...form,
steps: response.steps,
});
Copy link
Member Author

@BiswaViraj BiswaViraj May 29, 2023

Choose a reason for hiding this comment

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

This fixes the issue where multiple duplicate message templates were being created while updating the Notification template from the UI, also fixes the deletion of feed error.

Steps to reproduce(without this code change):

  • Create a new workflow
  • add an in-app step, fill the details
  • within the in-app editor screen, click update button
  • go back, and add another in-app step
  • keep the second in-app editor screen open, click update
  • do some minor changes in the content, click update
  • Check DB, there will be multiple copies of the 2nd step.

@LetItRock You added this for some digest related issue. can you please confirm if this change works for that issue?

Copy link
Contributor

@ainouzgali ainouzgali left a comment

Choose a reason for hiding this comment

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

Great job @BiswaViraj🤩
I just have a few concerns:

  1. Let's do a soft delete of the message template like we do for the other repositories.
  2. In promoting the notification template change it calls the promote message template, which currently has no delete behavior.
  3. When removing a step - not in the delete template - what do you think of also deleting the message template? I believe we are just updating the notification template now.
  4. Lets add a couple of tests for the promotion of notification template promotes deletion of the message templates + able to delete a feed.

@@ -139,6 +145,47 @@ describe('Delete notification template by id - /notification-templates/:template

expect(response.body.message).to.contains('Could not find workflow with id');
});

it('should delete the notification template along with the message templates', async function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about also adding a test of deleting a notification template that has a feed assigned to it and then see that the feed can be deleted?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree, that will be a good addition, will add it.

item: template,
type: ChangeEntityTypeEnum.MESSAGE_TEMPLATE,
parentChangeId: command.parentChangeId,
changeId: MessageTemplateRepository.createObjectId(),
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe here changeId should get the value from changeRepository.getChangeId because then it will aggregate all current changes made to that message template into one.

Copy link
Contributor

@p-fernandez p-fernandez left a comment

Choose a reason for hiding this comment

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

🌟

Comment on lines 15 to 18
const template = await this.messageTemplateRepository.findById(command.messageTemplateId, command.environmentId);
if (!template) {
throw new NotFoundException(`Message Template with id ${command.messageTemplateId} not found`);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

As a tech debt we should create an use case to find the message template to handle this logic as it can be reused in UpdateMessageTemplate.

Comment on lines +175 to +179
const deletedIntegration = (
await notificationTemplateRepository.findDeleted({ _environmentId: session.environment._id, _id: template._id })
)[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const deletedIntegration = (
await notificationTemplateRepository.findDeleted({ _environmentId: session.environment._id, _id: template._id })
)[0];
const [deletedIntegration] = await notificationTemplateRepository.findDeleted({ _environmentId: session.environment._id, _id: template._id });

Same vibes. 🙂
Not to address it as it is stylistic and we have no defined preference for any.

Comment on lines 73 to 79
await this.deleteMessageTemplate.execute(
DeleteMessageTemplateCommand.create({
organizationId: command.organizationId,
environmentId: command.environmentId,
userId: command.userId,
messageTemplateId: step._templateId,
parentChangeId: parentChangeId,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to stop the execution of the notification template deletion if any of the message template deletions fail?

@BiswaViraj BiswaViraj force-pushed the nv-2215-delete-messagetemplates-of-deleted-templates branch from c24ada1 to e017019 Compare May 30, 2023 14:57
@BiswaViraj BiswaViraj force-pushed the nv-2215-delete-messagetemplates-of-deleted-templates branch from b962087 to 705b3e7 Compare June 10, 2023 09:19
@BiswaViraj BiswaViraj added this pull request to the merge queue Jun 10, 2023
Merged via the queue into next with commit f4a0481 Jun 10, 2023
@BiswaViraj BiswaViraj deleted the nv-2215-delete-messagetemplates-of-deleted-templates branch June 10, 2023 09:39
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.

3 participants