mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-10 10:22:04 +02:00
Notify user about results of manually executed health check (#2044)
When manually starting health checks, the user should always receive a notification about the status, whether successful or not.
This commit is contained in:
2
gradle/changelog/notify_current_user.yaml
Normal file
2
gradle/changelog/notify_current_user.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
- type: changed
|
||||
description: Notify user about results of manually executed health check ([#2044](https://github.com/scm-manager/scm-manager/pull/2044))
|
||||
@@ -227,22 +227,28 @@ final class HealthChecker {
|
||||
}
|
||||
|
||||
private void notifyCurrentUser(Repository repository, HealthCheckResult result) {
|
||||
if (!(repository.isHealthy() && result.isHealthy())) {
|
||||
String currentUser = SecurityUtils.getSubject().getPrincipal().toString();
|
||||
if (!scmConfiguration.getEmergencyContacts().contains(currentUser)) {
|
||||
notificationSender.send(getHealthCheckFailedNotification(repository));
|
||||
}
|
||||
if (repository.isHealthy() && result.isHealthy()) {
|
||||
notificationSender.send(getHealthCheckSuccessNotification(repository));
|
||||
} else {
|
||||
notificationSender.send(getHealthCheckFailedNotification(repository));
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyEmergencyContacts(Repository repository) {
|
||||
String currentUser = SecurityUtils.getSubject().getPrincipal().toString();
|
||||
Set<String> emergencyContacts = scmConfiguration.getEmergencyContacts();
|
||||
for (String user : emergencyContacts) {
|
||||
notificationSender.send(getHealthCheckFailedNotification(repository), user);
|
||||
if (!user.equals(currentUser)) {
|
||||
notificationSender.send(getHealthCheckFailedNotification(repository), user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Notification getHealthCheckFailedNotification(Repository repository) {
|
||||
return new Notification(Type.ERROR, "/repo/" + repository.getNamespaceAndName() + "/settings/general", "healthCheckFailed");
|
||||
}
|
||||
|
||||
private Notification getHealthCheckSuccessNotification(Repository repository) {
|
||||
return new Notification(Type.SUCCESS, "/repo/" + repository.getNamespaceAndName() + "/settings/general", "healthCheckSuccess");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -480,7 +480,8 @@
|
||||
"notifications": {
|
||||
"exportFinished": "Der Repository Export wurde abgeschlossen.",
|
||||
"exportFailed": "Der Repository Export ist fehlgeschlagen. Versuchen Sie es erneut oder wenden Sie sich an einen Administrator.",
|
||||
"healthCheckFailed": "Der Repository Health Check ist fehlgeschlagen."
|
||||
"healthCheckFailed": "Der Repository Health Check ist fehlgeschlagen.",
|
||||
"healthCheckSuccess": "Der Repository Health Check war erfolgreich."
|
||||
},
|
||||
"search": {
|
||||
"types": {
|
||||
|
||||
@@ -424,7 +424,8 @@
|
||||
"notifications": {
|
||||
"exportFinished": "The repository export has been finished.",
|
||||
"exportFailed": "The repository export has failed. Try it again or contact your administrator.",
|
||||
"healthCheckFailed": "The repository health check has failed."
|
||||
"healthCheckFailed": "The repository health check has failed.",
|
||||
"healthCheckSuccess": "The repository health check was successful."
|
||||
},
|
||||
"search": {
|
||||
"types": {
|
||||
|
||||
@@ -119,6 +119,7 @@ class HealthCheckerTest {
|
||||
|
||||
@Test
|
||||
void shouldComputeLightChecks() {
|
||||
when(subject.getPrincipal()).thenReturn("trillian");
|
||||
when(healthCheck1.check(repository)).thenReturn(HealthCheckResult.unhealthy(createFailure("error1")));
|
||||
when(healthCheck2.check(repository)).thenReturn(HealthCheckResult.unhealthy(createFailure("error2")));
|
||||
|
||||
@@ -261,8 +262,8 @@ class HealthCheckerTest {
|
||||
|
||||
checker.fullCheck(repositoryId);
|
||||
|
||||
verify(notificationSender, never()).send(any());
|
||||
verify(notificationSender,times(1)).send(any(), eq("trillian"));
|
||||
verify(notificationSender, times(1)).send(any());
|
||||
verify(notificationSender, never()).send(any(), eq("trillian"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -274,7 +275,7 @@ class HealthCheckerTest {
|
||||
|
||||
checker.fullCheck(repositoryId);
|
||||
|
||||
verify(notificationSender).send(any(), eq("trillian"));
|
||||
verify(notificationSender).send(any());
|
||||
verify(notificationSender).send(any(), eq("Arthur"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user