From 7401c081af9d3543963ea492ec0a822c18f3fd7b Mon Sep 17 00:00:00 2001 From: milanmajchrak <90026355+milanmajchrak@users.noreply.github.com> Date: Wed, 13 Dec 2023 14:18:52 +0100 Subject: [PATCH] ufal/be-fix-email-parameters Fixed emails sending - added arguments and cfg properties that are sent in the email. (#470) --- .../ClarinAutoRegistrationController.java | 12 ++++++- .../ClarinUserMetadataRestController.java | 18 ++++++++-- dspace/config/clarin-dspace.cfg | 6 ++++ dspace/config/emails/clarin_autoregistration | 35 +++++++++++++------ dspace/config/emails/clarin_download_link | 23 +++++++----- 5 files changed, 71 insertions(+), 23 deletions(-) diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/ClarinAutoRegistrationController.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/ClarinAutoRegistrationController.java index 31e234ec2c0c..de2dccb9e866 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/ClarinAutoRegistrationController.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/ClarinAutoRegistrationController.java @@ -84,12 +84,17 @@ public ResponseEntity sendEmail(HttpServletRequest request, HttpServletResponse return null; } + // Fetch DSpace main cfg info and send it in the email String uiUrl = configurationService.getProperty("dspace.ui.url"); + String helpDeskEmail = configurationService.getProperty("lr.help.mail", ""); + String helpDeskPhoneNum = configurationService.getProperty("lr.help.phone", ""); + String dspaceName = configurationService.getProperty("dspace.name", ""); + String dspaceNameShort = configurationService.getProperty("dspace.name.short", ""); + if (StringUtils.isEmpty(uiUrl)) { log.error("Cannot load the `dspace.ui.url` property from the cfg."); throw new RuntimeException("Cannot load the `dspace.ui.url` property from the cfg."); } - // Generate token and create ClarinVerificationToken record with the token and user email. String verificationToken = Utils.generateHexKey(); clarinVerificationToken.setEmail(email); @@ -103,6 +108,11 @@ public ResponseEntity sendEmail(HttpServletRequest request, HttpServletResponse Locale locale = context.getCurrentLocale(); Email bean = Email.getEmail(I18nUtil.getEmailFilename(locale, "clarin_autoregistration")); bean.addArgument(autoregistrationURL); + bean.addArgument(helpDeskEmail); + bean.addArgument(helpDeskPhoneNum); + bean.addArgument(dspaceNameShort); + bean.addArgument(dspaceName); + bean.addArgument(uiUrl); bean.addRecipient(email); bean.send(); } catch (Exception e) { diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinUserMetadataRestController.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinUserMetadataRestController.java index 170e85bd6035..e726c600ce80 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinUserMetadataRestController.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinUserMetadataRestController.java @@ -173,9 +173,18 @@ private void sendEmailWithDownloadLink(Context context, UUID bitstreamUUID, throw new BadRequestException("Cannot find the clarin license for the bitstream with ID: " + bitstreamUUID); } + // Fetch DSpace main cfg info and send it in the email + String uiUrl = configurationService.getProperty("dspace.ui.url", ""); + String helpDeskEmail = configurationService.getProperty("lr.help.mail", ""); + String helpDeskPhoneNum = configurationService.getProperty("lr.help.phone", ""); + String dspaceName = configurationService.getProperty("dspace.name", ""); + String dspaceNameShort = configurationService.getProperty("dspace.name.short", ""); + + if (StringUtils.isEmpty(uiUrl)) { + log.error("Cannot load the `dspace.ui.url` property from the cfg."); + throw new RuntimeException("Cannot load the `dspace.ui.url` property from the cfg."); + } // Compose download link - // Get UI url - String uiUrl = configurationService.getProperty("dspace.ui.url"); String downloadLink = uiUrl + "/" + BitstreamRest.PLURAL_NAME + "/" + bitstream.getID() + "/download?dtoken=" + downloadToken; @@ -185,6 +194,11 @@ private void sendEmailWithDownloadLink(Context context, UUID bitstreamUUID, bean.addArgument(bitstream.getName()); bean.addArgument(downloadLink); bean.addArgument(clarinLicense.getDefinition()); + bean.addArgument(helpDeskEmail); + bean.addArgument(helpDeskPhoneNum); + bean.addArgument(dspaceNameShort); + bean.addArgument(dspaceName); + bean.addArgument(uiUrl); bean.addRecipient(email); bean.send(); } catch (MessagingException e) { diff --git a/dspace/config/clarin-dspace.cfg b/dspace/config/clarin-dspace.cfg index 3d317c77b41a..e51dca06ba8e 100644 --- a/dspace/config/clarin-dspace.cfg +++ b/dspace/config/clarin-dspace.cfg @@ -2,6 +2,12 @@ # one day similar to this # https://github.com/ufal/clarin-dspace/blob/clarin/utilities/project_helpers/config/local.conf.dist +#------------------------------------------------------------------# +#---------------------------DSpace---------------------------------# +#------------------------------------------------------------------# +dspace.name.short = DSpace +dspace.name = CLARIN DSpace + #------------------------------------------------------------------# #---------------------------UPLOAD FILE----------------------------# #------------------------------------------------------------------# diff --git a/dspace/config/emails/clarin_autoregistration b/dspace/config/emails/clarin_autoregistration index f39770cfd258..c05ba67d9e78 100644 --- a/dspace/config/emails/clarin_autoregistration +++ b/dspace/config/emails/clarin_autoregistration @@ -1,14 +1,27 @@ -## E-mail sent to confirm authenticity of the user's e-mail. -## -## Parameters: {0} confirmation e-mail -## -## See org.dspace.core.Email for information on the format of this file. -## +# E-mail sent to confirm authenticity of the user's e-mail. +# +# Parameters: {0} confirmation e-mail +# {1} helpdesk email +# {2} helpdesk phone number +# {3} DSpace name short +# {4} DSpace name +# {5} DSpace UI url +# +# See org.dspace.core.Email for information on the format of this file. +# +Subject: ${params[3]}: Account Registration +To complete registration for a ${params[3]} repository account at {params[5]}, please click the link below: -Confirmation e-mail: ${params[0]} + ${params[0]} + +If you need assistance with your account, please email +${params[1]} or call us at ${params[2]} + + +${params[3]} Team _____________________________________ -${dspace.name}, -WWW: ${dspace.url} -Email: ${lr.help.mail} -Tel.: ${lr.help.phone} +${params[4]}, +WWW: ${params[5]} +Email: ${params[1]} +Tel.: ${params[2]} diff --git a/dspace/config/emails/clarin_download_link b/dspace/config/emails/clarin_download_link index d44e18cca7c0..bf0bb380f3b5 100644 --- a/dspace/config/emails/clarin_download_link +++ b/dspace/config/emails/clarin_download_link @@ -3,24 +3,29 @@ # Parameters: {0} is expanded to filename # {1} to a download URL # {2} to license url +# {3} helpdesk email +# {4} helpdesk phone number +# {5} DSpace name short +# {6} DSpace name +# {7} DSpace UI url # # See org.dspace.core.Email for information on the format of this file. # -Subject: ${lr.dspace.name.short}: Download instructions for {0} +Subject: ${params[5]}: Download instructions for ${params[0]} To download the file you have requested, please click the link below: - {1} + ${params[1]} Remember, the file is distributed under specific license: - {2} + ${params[2]} If you have trouble downloading the file or if you did not request this download please contact -${lr.help.mail} or call us at ${lr.help.phone} +${params[3]} or call us at ${params[4]} -${lr.dspace.name.short} Team +${params[5]} Team _____________________________________ -${dspace.name}, -WWW: ${dspace.url} -Email: ${lr.help.mail} -Tel.: ${lr.help.phone} \ No newline at end of file +${params[6]}, +WWW: ${params[7]} +Email: ${params[3]} +Tel.: ${params[4]} \ No newline at end of file