Skip to content

Commit

Permalink
10581 request access email fix (#10653)
Browse files Browse the repository at this point in the history
* #10581 fix subject line of request access email

* #10581 add sorter

* #10581 addl user info for request email

* #10581 add break between custom Q responses

* #10581 remove orderby
  • Loading branch information
sekmiller authored Jun 25, 2024
1 parent 3dccdb7 commit 9fc757f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
40 changes: 33 additions & 7 deletions src/main/java/edu/harvard/iq/dataverse/GuestbookResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import java.util.List;
import jakarta.persistence.*;
import jakarta.validation.constraints.Size;
import java.util.Collections;
import java.util.Comparator;

/**
*
Expand Down Expand Up @@ -178,7 +180,7 @@ public GuestbookResponse(GuestbookResponse source){
this.setSessionId(source.getSessionId());
List <CustomQuestionResponse> customQuestionResponses = new ArrayList<>();
if (!source.getCustomQuestionResponses().isEmpty()){
for (CustomQuestionResponse customQuestionResponse : source.getCustomQuestionResponses() ){
for (CustomQuestionResponse customQuestionResponse : source.getCustomQuestionResponsesSorted() ){
CustomQuestionResponse customQuestionResponseAdd = new CustomQuestionResponse();
customQuestionResponseAdd.setResponse(customQuestionResponse.getResponse());
customQuestionResponseAdd.setCustomQuestion(customQuestionResponse.getCustomQuestion());
Expand Down Expand Up @@ -254,6 +256,18 @@ public String getResponseDate() {
public List<CustomQuestionResponse> getCustomQuestionResponses() {
return customQuestionResponses;
}

public List<CustomQuestionResponse> getCustomQuestionResponsesSorted(){

Collections.sort(customQuestionResponses, (CustomQuestionResponse cqr1, CustomQuestionResponse cqr2) -> {
int a = cqr1.getCustomQuestion().getDisplayOrder();
int b = cqr2.getCustomQuestion().getDisplayOrder();
return Integer.valueOf(a).compareTo(b);
});


return customQuestionResponses;
}

public void setCustomQuestionResponses(List<CustomQuestionResponse> customQuestionResponses) {
this.customQuestionResponses = customQuestionResponses;
Expand Down Expand Up @@ -317,7 +331,11 @@ public void setSessionId(String sessionId) {
this.sessionId= sessionId;
}

public String toHtmlFormattedResponse() {
public String toHtmlFormattedResponse(){
return toHtmlFormattedResponse(null);
}

public String toHtmlFormattedResponse(AuthenticatedUser requestor) {

StringBuilder sb = new StringBuilder();

Expand All @@ -326,17 +344,25 @@ public String toHtmlFormattedResponse() {
sb.append(BundleUtil.getStringFromBundle("dataset.guestbookResponse.respondent") + "<br><ul style=\"list-style-type:none;\">\n<li>"
+ BundleUtil.getStringFromBundle("name") + ": " + getName() + "</li>\n<li>");
sb.append(" " + BundleUtil.getStringFromBundle("email") + ": " + getEmail() + "</li>\n<li>");
sb.append(
" " + BundleUtil.getStringFromBundle("institution") + ": " + wrapNullAnswer(getInstitution()) + "</li>\n<li>");
sb.append(" " + BundleUtil.getStringFromBundle("position") + ": " + wrapNullAnswer(getPosition()) + "</li></ul>\n");
sb.append(" " + BundleUtil.getStringFromBundle("institution") + ": " + wrapNullAnswer(getInstitution()) + "</li>\n<li>");
sb.append(" " + BundleUtil.getStringFromBundle("position") + ": " + wrapNullAnswer(getPosition()) + "</li>");

//Add requestor information to response to help dataset admin with request processing
if (requestor != null){
sb.append("\n<li>" + BundleUtil.getStringFromBundle("dataset.guestbookResponse.requestor.id") + ": " + requestor.getId()+ "</li>");
sb.append("\n<li>" + BundleUtil.getStringFromBundle("dataset.guestbookResponse.requestor.identifier") + ": " + requestor.getIdentifier()+ "</li></ul>\n");
} else {
sb.append("</ul>\n");
}

sb.append(BundleUtil.getStringFromBundle("dataset.guestbookResponse.guestbook.additionalQuestions")
+ ":<ul style=\"list-style-type:none;\">\n");

for (CustomQuestionResponse cqr : getCustomQuestionResponses()) {
for (CustomQuestionResponse cqr : getCustomQuestionResponsesSorted()) {
sb.append("<li>" + BundleUtil.getStringFromBundle("dataset.guestbookResponse.question") + ": "
+ cqr.getCustomQuestion().getQuestionString() + "<br>"
+ BundleUtil.getStringFromBundle("dataset.guestbookResponse.answer") + ": "
+ wrapNullAnswer(cqr.getResponse()) + "</li>\n");
+ wrapNullAnswer(cqr.getResponse()) + "</li>\n<br>");
}
sb.append("</ul>");
return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public String getMessageTextBasedOnNotification(UserNotification userNotificatio
GuestbookResponse gbr = far.getGuestbookResponse();
if (gbr != null) {
messageText += MessageFormat.format(
BundleUtil.getStringFromBundle("notification.email.requestFileAccess.guestbookResponse"), gbr.toHtmlFormattedResponse());
BundleUtil.getStringFromBundle("notification.email.requestFileAccess.guestbookResponse"), gbr.toHtmlFormattedResponse(requestor));
}
return messageText;
case GRANTFILEACCESS:
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/util/MailUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ public static String getSubjectTextBasedOnNotification(UserNotification userNoti
case CREATEDV:
return BundleUtil.getStringFromBundle("notification.email.create.dataverse.subject", rootDvNameAsList);
case REQUESTFILEACCESS:
return BundleUtil.getStringFromBundle("notification.email.request.file.access.subject", Arrays.asList(rootDvNameAsList.get(0), datasetDisplayName));
String userNameFirst = userNotification.getRequestor().getFirstName();
String userNameLast = userNotification.getRequestor().getLastName();
String userIdentifier = userNotification.getRequestor().getIdentifier();
return BundleUtil.getStringFromBundle("notification.email.request.file.access.subject", Arrays.asList(rootDvNameAsList.get(0), userNameFirst, userNameLast, userIdentifier, datasetDisplayName));
case REQUESTEDFILEACCESS:
return BundleUtil.getStringFromBundle("notification.email.requested.file.access.subject", Arrays.asList(rootDvNameAsList.get(0), datasetDisplayName));
case GRANTFILEACCESS:
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/propertyFiles/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,8 @@ dashboard.card.datamove.dataset.command.error.indexingProblem=Dataset could not
notification.email.create.dataverse.subject={0}: Your dataverse has been created
notification.email.create.dataset.subject={0}: Dataset "{1}" has been created
notification.email.dataset.created.subject={0}: Dataset "{1}" has been created
notification.email.request.file.access.subject={0}: Access has been requested for a restricted file in dataset "{1}"
notification.email.requested.file.access.subject={0}: You have requested access to a restricted file in dataset "{1}"
notification.email.request.file.access.subject={0}: {1} {2} ({3}) requested access to dataset "{4}"
notification.email.requested.file.access.subject={0}: You have requested access to a restricted file in dataset "{1}"
notification.email.grant.file.access.subject={0}: You have been granted access to a restricted file
notification.email.rejected.file.access.subject={0}: Your request for access to a restricted file has been rejected
notification.email.submit.dataset.subject={0}: Dataset "{1}" has been submitted for review
Expand Down Expand Up @@ -1400,6 +1400,8 @@ dataset.guestbookResponse.respondent=Respondent
dataset.guestbookResponse.question=Q
dataset.guestbookResponse.answer=A
dataset.guestbookResponse.noResponse=(No Response)
dataset.guestbookResponse.requestor.id=authenticatedUserId
dataset.guestbookResponse.requestor.identifier=authenticatedUserIdentifier


# dataset.xhtml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import edu.harvard.iq.dataverse.DataverseServiceBean;
import edu.harvard.iq.dataverse.UserNotification;
import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
import edu.harvard.iq.dataverse.branding.BrandingUtil;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;

Expand Down Expand Up @@ -82,7 +83,12 @@ public void testSubjectRevokeRole() {
@Test
public void testSubjectRequestFileAccess() {
userNotification.setType(UserNotification.Type.REQUESTFILEACCESS);
assertEquals("LibraScholar: Access has been requested for a restricted file in dataset \"\"", MailUtil.getSubjectTextBasedOnNotification(userNotification, null));
AuthenticatedUser requestor = new AuthenticatedUser();
requestor.setFirstName("Tom");
requestor.setLastName("Jones");
requestor.setUserIdentifier("TJ-1234");
userNotification.setRequestor(requestor);
assertEquals("LibraScholar: Tom Jones (@TJ-1234) requested access to dataset \"\"", MailUtil.getSubjectTextBasedOnNotification(userNotification, null));
}

@Test
Expand Down

0 comments on commit 9fc757f

Please sign in to comment.