From eb70b91806390d53242a0c28f49d388af966ea76 Mon Sep 17 00:00:00 2001 From: dhaura Date: Tue, 10 Dec 2024 17:40:28 +0530 Subject: [PATCH] Update template existence check with resolve param in org templates. --- .../template/v1/core/ServerEmailTemplatesService.java | 10 ++++++---- .../template/v2/core/ServerEmailTemplatesService.java | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v1/core/ServerEmailTemplatesService.java b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v1/core/ServerEmailTemplatesService.java index 9f1961bfa7..a90f456de3 100644 --- a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v1/core/ServerEmailTemplatesService.java +++ b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v1/core/ServerEmailTemplatesService.java @@ -246,7 +246,7 @@ public SimpleEmailTemplate addEmailTemplate(String templateTypeId, EmailTemplate try { boolean isTemplateExists = EmailTemplatesServiceHolder.getEmailTemplateManager() .isEmailTemplateExists(templateTypeDisplayName, emailTemplateWithID.getId(), - getTenantDomainFromContext()); + getTenantDomainFromContext(), null, false); if (!isTemplateExists) { // Email template is new, hence add to the system. addEmailTemplateToTheSystem(templateTypeDisplayName, emailTemplateWithID); @@ -308,7 +308,7 @@ public void deleteEmailTemplate(String templateTypeId, String templateId) { } try { boolean isTemplateExists = EmailTemplatesServiceHolder.getEmailTemplateManager().isEmailTemplateExists( - templateTypeDisplayName, templateId, getTenantDomainFromContext()); + templateTypeDisplayName, templateId, getTenantDomainFromContext(), null, false); if (isTemplateExists) { EmailTemplatesServiceHolder.getEmailTemplateManager().deleteEmailTemplate(templateTypeDisplayName, templateId, getTenantDomainFromContext()); @@ -329,9 +329,11 @@ public void updateEmailTemplate(String templateTypeId, String templateId, EmailT String templateTypeDisplayName = decodeTemplateTypeId(templateTypeId); try { - // Check whether the email template exists, first. + /* Check whether the email template exists, first. Here, resolve param is specified as true since + resolved org templates are returned in GET endpoint, by default. Therefore, resolved template existence + is checked before updating. */ boolean isTemplateExists = EmailTemplatesServiceHolder.getEmailTemplateManager().isEmailTemplateExists( - templateTypeDisplayName, templateId, getTenantDomainFromContext()); + templateTypeDisplayName, templateId, getTenantDomainFromContext(), null, true); if (isTemplateExists) { addEmailTemplateToTheSystem(templateTypeDisplayName, emailTemplateWithID); } else { diff --git a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/core/ServerEmailTemplatesService.java b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/core/ServerEmailTemplatesService.java index 5b91d4dfc1..cb47321fc3 100644 --- a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/core/ServerEmailTemplatesService.java +++ b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/core/ServerEmailTemplatesService.java @@ -243,7 +243,7 @@ public SimpleEmailTemplate addEmailTemplate(String templateTypeId, EmailTemplate try { boolean isTemplateExists = EmailTemplatesServiceHolder.getEmailTemplateManager() .isEmailTemplateExists(templateTypeDisplayName, emailTemplateWithID.getLocale(), - getTenantDomainFromContext()); + getTenantDomainFromContext(), null, false); if (!isTemplateExists) { // Email template is new, hence add to the system. addEmailTemplateToTheSystem(templateTypeDisplayName, emailTemplateWithID); @@ -332,7 +332,7 @@ public void deleteEmailTemplate(String templateTypeId, String templateId) { } try { boolean isTemplateExists = EmailTemplatesServiceHolder.getEmailTemplateManager().isEmailTemplateExists( - templateTypeDisplayName, templateId, getTenantDomainFromContext()); + templateTypeDisplayName, templateId, getTenantDomainFromContext(), null, false); if (isTemplateExists) { EmailTemplatesServiceHolder.getEmailTemplateManager().deleteEmailTemplate(templateTypeDisplayName, templateId, getTenantDomainFromContext()); @@ -353,9 +353,11 @@ public void updateEmailTemplate(String templateTypeId, String templateId, EmailT String templateTypeDisplayName = decodeTemplateTypeId(templateTypeId); try { - // Check whether the email template exists, first. + /* Check whether the email template exists, first. Here, resolve param is specified as true since + resolved org templates are returned in GET endpoint, by default. Therefore, resolved template existence + is checked before updating. */ boolean isTemplateExists = EmailTemplatesServiceHolder.getEmailTemplateManager().isEmailTemplateExists( - templateTypeDisplayName, templateId, getTenantDomainFromContext()); + templateTypeDisplayName, templateId, getTenantDomainFromContext(), null, true); if (isTemplateExists) { addEmailTemplateToTheSystem(templateTypeDisplayName, emailTemplateWithID); } else {