-
Notifications
You must be signed in to change notification settings - Fork 5
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
[JN-1547] allow ternary in email templates #1421
base: development
Are you sure you want to change the base?
Conversation
@@ -45,6 +45,12 @@ protected EnrolleeEmailSubstitutor(EnrolleeContext ruleData, NotificationContext | |||
valueMap.put("siteMediaBaseUrl", getImageBaseUrl(contextInfo.portalEnv(), contextInfo.portalEnvConfig(), contextInfo.portal().getShortcode())); | |||
valueMap.put("siteImageBaseUrl", getImageBaseUrl(contextInfo.portalEnv(), contextInfo.portalEnvConfig(), contextInfo.portal().getShortcode())); | |||
valueMap.put("profile", enrolleeContext.getProfile()); | |||
if (enrolleeContext.getParticipantUser().getUsername().contains("-prox-")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find another way to glean this information from the enrollee context. I think this is probably OK but obviously not foolproof, so let me know if there's a better way to do this.
As an aside, seeing this (+ Matt's participant document PR where he does some profileId checks) makes me think we should have some kind of EnrolleeAccountType
enum where the values are something like PROXY_ONLY
GOVERNED_USER
SELF_ENROLL
and SELF_AND_PROXY
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the implementation of the ternaries -- just needs some tweaks to handling the isProxy/Governed logic
@@ -45,6 +46,13 @@ protected EnrolleeEmailSubstitutor(EnrolleeContext ruleData, NotificationContext | |||
valueMap.put("siteMediaBaseUrl", getImageBaseUrl(contextInfo.portalEnv(), contextInfo.portalEnvConfig(), contextInfo.portal().getShortcode())); | |||
valueMap.put("siteImageBaseUrl", getImageBaseUrl(contextInfo.portalEnv(), contextInfo.portalEnvConfig(), contextInfo.portal().getShortcode())); | |||
valueMap.put("profile", enrolleeContext.getProfile()); | |||
if (Objects.nonNull(enrolleeContext.getParticipantUser()) | |||
&& StringUtils.contains(enrolleeContext.getParticipantUser().getUsername(), "-prox-")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'll want to make this more robust -- this might not work in the context of age-up protocols, there may be a period of time when they have their real email address as their account name but are still proxied.
I'd add an "isGoverned" field to EnrolleeContext, and a query in EnrolleeContextService to populate it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found it simpler to just fetch all the enrollee relations and populate them - perhaps a heavyweight solution, though
&& StringUtils.contains(enrolleeContext.getParticipantUser().getUsername(), "-prox-")) { | ||
valueMap.put("isProxy", "true"); | ||
} else { | ||
valueMap.put("isSubject", "true"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's go ahead and just put the whole enrolleee
on the valueMap -- that way we have subject
and consented
available
} | ||
|
||
public static boolean isTernary(String key) { | ||
return key.contains("?") && key.contains(":") && key.indexOf('?') < key.indexOf(':'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be just my personal preference, but I lean towards (commented) regexes for stuff like this -- something like/[^:]+\?.+:
@@ -80,6 +90,37 @@ public String lookup(String key) { | |||
return ""; | |||
} | |||
|
|||
private record Ternary(String condition, String left, String right) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I like how you made this as a record -- good encapsulation of logic
Quality Gate failedFailed conditions |
test failure is a fluke and sonarcloud is flagging the regex which shouldn't be a security problem |
DESCRIPTION (include screenshots, and mobile screenshots for participant UX)
Allow ternary e.g.
{isSubject ? "your" : "your child's"}
in email templates. Not super robust (doesn't allow escaping quotes, doesn't allow nesting) but should work for 99.9% of use cases.TO TEST: (simple manual steps for confirming core behavior -- used for pre-release checks)