Skip to content

Commit 249bc57

Browse files
committed
#380 Allow sending a copy of alerts to the current user
1 parent ed0886b commit 249bc57

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

grails-app/controllers/au/org/ala/alerts/AdminController.groovy

+6-3
Original file line numberDiff line numberDiff line change
@@ -730,16 +730,19 @@ class AdminController {
730730
}
731731

732732
/**
733-
* Simulating hourly jobs
733+
* Simulating Quartz jobs
734734
*
735735
* Only send emails in Development environment
736736
* And NO database updates
737737
*/
738-
def triggerQueriesByFrequency(String frequency) {
738+
def triggerQueriesByFrequency(String frequency, Boolean testMode) {
739739
def allowedFrequencies = ['hourly', 'weekly', 'daily', 'monthly']
740740
def jobFrequency = (frequency in allowedFrequencies) ? frequency : 'daily'
741+
// Set the test mode.
742+
// It is used to determine if a copy of email should be sent to the current user
743+
grailsApplication.config.testMode = testMode ?: false
741744

742-
log.info("****** Simulating ${jobFrequency} jobs, NO Database updates****** " + new Date())
745+
log.info("****** Simulating ${jobFrequency} jobs, Test mode: ${grailsApplication.config.testMode}, NO Database updates ****** " + new Date())
743746
def logs = notificationService.execQueryForFrequency(jobFrequency, Environment.current == Environment.DEVELOPMENT, true)
744747
log.info("****** End ${jobFrequency} job simulation ****** " + new Date())
745748
render(logs.sort { [it.succeeded ? 1 : 0, it.hasChanged ? 0 : 1] } as JSON)

grails-app/services/au/org/ala/alerts/MyAnnotationService.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class MyAnnotationService{
8181
}
8282
Collection missingRecords = missingEntries.values()
8383
if (missingRecords.size() > 0) {
84-
log.debug("Found ${missingRecords.size()} missing records: ${missingRecords.collect { it.uuid }}")
84+
log.info("Found ${missingRecords.size()} missing records: ${missingRecords.collect { it.uuid }}")
8585
mutableRecords.addAll(missingRecords)
8686
}
8787

grails-app/services/au/org/ala/alerts/NotificationService.groovy

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class NotificationService {
1717
int PAGING_MAX = 500
1818
def sessionFactory
1919
def httpService
20+
def userService
2021
def emailService
2122
def diffService
2223
def queryService
@@ -634,6 +635,13 @@ class NotificationService {
634635
if (!users.isEmpty() && sendEmails) {
635636
emailService.sendGroupNotification(qr, frequency, recipients)
636637
}
638+
639+
User currentUser = userService.getUser()
640+
if (currentUser && grailsApplication.config.testMode) {
641+
def me =
642+
[email: currentUser.email, userUnsubToken: currentUser.unsubscribeToken, notificationUnsubToken: '']
643+
emailService.sendGroupNotification(qr, frequency, [me])
644+
}
637645
}
638646
logs << info
639647
}

grails-app/views/admin/index.gsp

+18-6
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@
4545
<option value="weekly">Weekly</option>
4646
<option value="monthly">Monthly</option>
4747
</select>
48-
Scheduled Job <a class="btn btn-info" id="simulatedFrequencyLink" href="${g.createLink(controller: 'admin', action: 'triggerQueriesByFrequency', params: [frequency: 'daily'])}" target="_blank">Run</a>
49-
- Will NOT update the database, and emails will ONLY be sent in the Development environment.
48+
Scheduled Job
49+
<a class="btn btn-info" id="simulatedFrequencyLink" href="${g.createLink(controller: 'admin', action: 'triggerQueriesByFrequency', params: [frequency: 'daily'])}" target="_blank">Run</a>
50+
<label> <g:checkBox name="testMode" checked="${grailsApplication.config.testMode ?: false}" /> Email me a copy </label>
51+
<br/><i> - Will NOT update the database, and emails will ONLY be sent in the Development environment. </i>
5052
</li>
5153
</ul>
5254
<h4>Fix empty/invalid notification_token</h4>
@@ -99,11 +101,21 @@
99101

100102
<script>
101103
$(document).ready(function() {
102-
$('#frequencySimulated').change(function() {
103-
let selectedValue = $(this).val();
104+
// Update the link simulating the Quartz job
105+
function updateSimulationQueryLink() {
106+
let selectedValue = $('#frequencySimulated').val();
107+
let testModeChecked = $('[name=testMode]').is(':checked'); // Check if the checkbox is checked
104108
let queryLink = $('#simulatedFrequencyLink');
105-
queryLink.attr('href', "${g.createLink(controller: 'admin', action: 'triggerQueriesByFrequency')}?frequency=" + selectedValue);
106-
});
109+
110+
let url = "${g.createLink(controller: 'admin', action: 'triggerQueriesByFrequency')}";
111+
url += "?frequency=" + selectedValue;
112+
if (testModeChecked) {
113+
url += "&testMode=true"; // Append testMode only if checked
114+
}
115+
queryLink.attr('href', url);
116+
}
117+
118+
$('#frequencySimulated, [name=testMode]').change(updateSimulationQueryLink);
107119
});
108120
</script>
109121
</body>

0 commit comments

Comments
 (0)