From 4d6069832799ac6082c0018f72bf3a09683aa09f Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Thu, 11 Jan 2024 18:23:21 +0200 Subject: [PATCH] public contact send changes --- .../notification/NotificationPersist.java | 8 +++++++- .../ContactSupportServiceImpl.java | 2 +- .../notification/NotificationServiceImpl.java | 2 +- .../v2/ContactSupportController.java | 18 ++++++++++++++++-- dmp-frontend/src/assets/splash/contact.html | 2 +- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/notification/NotificationPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/notification/NotificationPersist.java index 9b8461504..96a8a061f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/notification/NotificationPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/notification/NotificationPersist.java @@ -31,6 +31,7 @@ public class NotificationPersist { private NotificationContactType contactTypeHint; + public static final String _contactHint = "contactHint"; private String contactHint; private String data; @@ -205,8 +206,13 @@ public class NotificationPersist { .must(() -> !this.isValidHash(item.getHash())) .failOn(NotificationPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())), this.spec() + .iff(() -> this.isEmpty(item.getContactHint())) .must(() -> this.isValidGuid(item.getUserId())) - .failOn(NotificationPersist._userId).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationPersist._userId}, LocaleContextHolder.getLocale())) + .failOn(NotificationPersist._userId).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationPersist._userId}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isValidGuid(item.getUserId())) + .must(() -> !this.isEmpty(item.getContactHint())) + .failOn(NotificationPersist._userId).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationPersist._contactHint}, LocaleContextHolder.getLocale())) ); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/contactsupport/ContactSupportServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/contactsupport/ContactSupportServiceImpl.java index 062799bd0..16550be3d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/contactsupport/ContactSupportServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/contactsupport/ContactSupportServiceImpl.java @@ -92,7 +92,7 @@ public class ContactSupportServiceImpl implements ContactSupportService { @Override public void sendPublicContactEmail(PublicContactSupportPersist model) throws InvalidApplicationException { logger.debug(new MapLogEntry("public send contact email").And("model", model)); - this.authorizationService.authorizeForce(Permission.SendContactSupport); + this.authorizationService.authorizeForce(Permission.PublicSendContactSupport); NotificationIntegrationEvent event = new NotificationIntegrationEvent(); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/notification/NotificationServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/notification/NotificationServiceImpl.java index c6a6e4e4f..48699b10a 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/notification/NotificationServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/notification/NotificationServiceImpl.java @@ -65,7 +65,7 @@ public class NotificationServiceImpl implements NotificationService { public void persist(NotificationPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException { logger.debug(new MapLogEntry("persisting notification").And("model", model).And("fields", fields)); - this.authorizationService.authorizeForce(Permission.AuthenticatedRole); + this.authorizationService.authorizeForce(Permission.PublicRole); Boolean isUpdate = this.conventionService.isValidGuid(model.getId()); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ContactSupportController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ContactSupportController.java index 58dc991d4..eb0070a03 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ContactSupportController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ContactSupportController.java @@ -23,6 +23,7 @@ import gr.cite.tools.exception.MyNotFoundException; import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.MapLogEntry; import org.slf4j.LoggerFactory; +import org.springframework.http.MediaType; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; @@ -67,10 +68,10 @@ public class ContactSupportController { - @PostMapping("public/send") + @PostMapping(path = "public/send", consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE}) @Transactional @ValidationFilterAnnotation(validator = PublicContactSupportPersist.PublicContactSupportPersistValidator.ValidatorName, argumentName ="model") - public void sendPublicContactEmail(@RequestBody PublicContactSupportPersist model) throws InvalidApplicationException { + public void sendPublicContactEmail(@ModelAttribute PublicContactSupportPersist model) throws InvalidApplicationException { logger.debug(new MapLogEntry("send public support email").And("model", model)); this.contactSupportService.sendPublicContactEmail(model); @@ -81,4 +82,17 @@ public class ContactSupportController { //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); } + @PostMapping("public/send") + @Transactional + @ValidationFilterAnnotation(validator = PublicContactSupportPersist.PublicContactSupportPersistValidator.ValidatorName, argumentName ="model") + public void sendPublicContactEmailJson(@RequestBody PublicContactSupportPersist model) throws InvalidApplicationException { + logger.debug(new MapLogEntry("send public support email").And("model", model)); + + this.contactSupportService.sendPublicContactEmail(model); + + this.auditService.track(AuditableAction.ContactSupport_PublicSent, Map.ofEntries( + new AbstractMap.SimpleEntry("model", model) + )); + //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); + } } diff --git a/dmp-frontend/src/assets/splash/contact.html b/dmp-frontend/src/assets/splash/contact.html index 7a0c03314..1af8280c0 100644 --- a/dmp-frontend/src/assets/splash/contact.html +++ b/dmp-frontend/src/assets/splash/contact.html @@ -68,7 +68,7 @@ -
+
Contact us to learn more