-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #430 from NationalSecurityAgency/t#424/notify_appr…
…ove_reject #424 - notify users when self reported skills are approved or denied
- Loading branch information
Showing
5 changed files
with
469 additions
and
21 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
service/src/main/java/skills/notify/builders/SkillApprovalResponseNotificationBuilder.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* Copyright 2020 SkillTree | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package skills.notify.builders | ||
|
||
import groovy.json.JsonSlurper | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.stereotype.Component | ||
import org.thymeleaf.context.Context | ||
import org.thymeleaf.spring5.SpringTemplateEngine | ||
import skills.storage.model.Notification | ||
|
||
@Component | ||
class SkillApprovalResponseNotificationBuilder implements NotificationEmailBuilder{ | ||
|
||
JsonSlurper jsonSlurper = new JsonSlurper() | ||
|
||
@Autowired | ||
SpringTemplateEngine thymeleafTemplateEngine; | ||
|
||
@Override | ||
String getId() { | ||
return Notification.Type.SkillApprovalResponse.toString() | ||
} | ||
|
||
@Override | ||
Res build(Notification notification, Formatting formatting) { | ||
def parsed = jsonSlurper.parseText(notification.encodedParams) | ||
Context context = buildThymeleafContext(parsed, formatting) | ||
String htmlBody = thymeleafTemplateEngine.process("skill_approval_response.html", context) | ||
String plainText = buildPlainText(parsed, formatting) | ||
return new Res( | ||
subject: "SkillTree Points ${parsed.approved ? 'Approved' : 'Denied'}", | ||
html: htmlBody, | ||
plainText: plainText | ||
) | ||
} | ||
|
||
private Context buildThymeleafContext(parsed, Formatting formatting) { | ||
Context templateContext = new Context() | ||
templateContext.setVariable("approver", parsed.approver) | ||
templateContext.setVariable("approved", parsed.approved) | ||
templateContext.setVariable("skillName", parsed.skillName) | ||
templateContext.setVariable("skillId", parsed.skillId) | ||
templateContext.setVariable("projectName", parsed.projectName) | ||
templateContext.setVariable("projectId", parsed.projectId) | ||
templateContext.setVariable("rejectionMsg", parsed.rejectionMsg ?: '') | ||
templateContext.setVariable("publicUrl", parsed.publicUrl) | ||
templateContext.setVariable("htmlHeader", formatting.htmlHeader) | ||
templateContext.setVariable("htmlFooter", formatting.htmlFooter) | ||
|
||
return templateContext | ||
} | ||
|
||
private String buildPlainText(parsed, Formatting formatting) { | ||
String message | ||
if (parsed.approved) { | ||
message = "Congratulations! Your request for the ${parsed.skillName} skill in the ${parsed.projectName} project has been approved." | ||
} else { | ||
message = "Your request for the ${parsed.skillName} skill in the ${parsed.projectName} project has been denied." | ||
} | ||
String pt = "${message}" + | ||
"\n Project: ${parsed.projectName}" + | ||
"\n Skill: ${parsed.skillName}" + | ||
"\n Approver: ${parsed.approver}" + | ||
"\n ${parsed.approved ? '' : "Message: ${parsed.rejectionMsg ?: ''}\n"}" + | ||
"\n" + | ||
"\nAlways yours," + | ||
"\nSkillTree Bot" | ||
|
||
if (formatting.plaintextHeader) { | ||
pt = "${formatting.plaintextHeader}\n${pt}" | ||
} | ||
if (formatting.plaintextFooter) { | ||
pt = "${pt}\n${formatting.plaintextFooter}" | ||
} | ||
|
||
return pt | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
service/src/main/resources/templates/skill_approval_response.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<!-- | ||
Copyright 2020 SkillTree | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
https://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<!DOCTYPE html> | ||
<html lang="en" | ||
xmlns:th="http://www.thymeleaf.org" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.thymeleaf.org http://www.thymeleaf.org"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||
<style> | ||
.label { | ||
color: #525252; | ||
} | ||
</style> | ||
</head> | ||
<body class="overall-container"> | ||
<div th:remove="tag" th:utext="${htmlHeader}" th:if= "${htmlHeader != null}">[[${htmlHeader}]]</div> | ||
<h1>SkillTree Points <span th:text="${approved} ? 'Approved!' : 'Denied'"></span></h1> | ||
<p th:if="${approved}">Congratulations! Your request for the <b>[[${skillName}]]</b> skill in the <b>[[${projectName}]]</b> project has been approved!</p> | ||
<p th:if="${!approved}">Your request for the <b>[[${skillName}]]</b> skill in the <b>[[${projectName}]]</b> project has been denied.</p> | ||
|
||
<ul> | ||
<li><span class="label">Project</span>: [[${projectName}]]</li> | ||
<li><span class="label">Skill</span>: [[${skillName}]]</li> | ||
<li><span class="label">Approver</span>: [[${approver}]]</li> | ||
<li th:if="${!approved}"><span class="label">Message</span>: [[${rejectionMsg}]]</li> | ||
</ul> | ||
|
||
<p>You can view your progress for the <a th:href="@{${publicUrl}+'progress-and-rankings/projects/'+${projectId}}">[[${projectName}]]</a> project in the SkillTree dashboard.</p> | ||
|
||
<p> | ||
Always yours, <br/> -SkillTree Bot | ||
</p> | ||
|
||
<div th:remove="tag" th:utext="${htmlFooter}" th:if= "${htmlFooter != null}">[[${htmlFooter}]]</div> | ||
</body> | ||
</html> |
Oops, something went wrong.