Browse Source

Minor improvements for Teams notifications

pull/8843/head
ViacheslavKlimov 3 years ago
parent
commit
fb149b720c
  1. 6
      application/src/main/java/org/thingsboard/server/service/notification/channels/MicrosoftTeamsNotificationChannel.java
  2. 2
      application/src/main/java/org/thingsboard/server/service/security/system/DefaultSystemSecurityService.java
  3. 4
      application/src/test/java/org/thingsboard/server/service/notification/NotificationApiTest.java
  4. 5
      ui-ngx/src/assets/locale/locale.constant-en_US.json

6
application/src/main/java/org/thingsboard/server/service/notification/channels/MicrosoftTeamsNotificationChannel.java

@ -88,7 +88,11 @@ public class MicrosoftTeamsNotificationChannel implements NotificationChannel<Mi
}
state = Base64.encodeBase64String(JacksonUtil.OBJECT_MAPPER.writeValueAsBytes(List.of(stateObject)));
}
uri = systemSecurityService.getBaseUrl(ctx.getTenantId(), null, null) + "/dashboards/" + button.getDashboardId();
String baseUrl = systemSecurityService.getBaseUrl(ctx.getTenantId(), null, null);
if (StringUtils.isEmpty(baseUrl)) {
throw new IllegalStateException("Failed to determine base url to construct dashboard link");
}
uri = baseUrl + "/dashboards/" + button.getDashboardId();
if (state != null) {
uri += "?state=" + state;
}

2
application/src/main/java/org/thingsboard/server/service/security/system/DefaultSystemSecurityService.java

@ -253,7 +253,7 @@ public class DefaultSystemSecurityService implements SystemSecurityService {
baseUrl = generalSettings.getJsonValue().get("baseUrl").asText();
}
if (StringUtils.isEmpty(baseUrl)) {
if (StringUtils.isEmpty(baseUrl) && httpServletRequest != null) {
baseUrl = MiscUtils.constructBaseUrl(httpServletRequest);
}

4
application/src/test/java/org/thingsboard/server/service/notification/NotificationApiTest.java

@ -51,6 +51,7 @@ import org.thingsboard.server.common.data.notification.targets.slack.SlackNotifi
import org.thingsboard.server.common.data.notification.template.DeliveryMethodNotificationTemplate;
import org.thingsboard.server.common.data.notification.template.EmailDeliveryMethodNotificationTemplate;
import org.thingsboard.server.common.data.notification.template.MicrosoftTeamsDeliveryMethodNotificationTemplate;
import org.thingsboard.server.common.data.notification.template.MicrosoftTeamsDeliveryMethodNotificationTemplate.Button.LinkType;
import org.thingsboard.server.common.data.notification.template.NotificationTemplate;
import org.thingsboard.server.common.data.notification.template.NotificationTemplateConfig;
import org.thingsboard.server.common.data.notification.template.SlackDeliveryMethodNotificationTemplate;
@ -560,6 +561,7 @@ public class NotificationApiTest extends AbstractNotificationApiTest {
var button = new MicrosoftTeamsDeliveryMethodNotificationTemplate.Button();
button.setEnabled(true);
button.setText("Button: " + templateParams);
button.setLinkType(LinkType.LINK);
button.setLink("https://" + templateParams);
template.setButton(button);
NotificationTemplate notificationTemplate = new NotificationTemplate();
@ -578,7 +580,7 @@ public class NotificationApiTest extends AbstractNotificationApiTest {
.templateId(notificationTemplate.getId())
.targets(List.of(target.getUuidId()))
.info(EntityActionNotificationInfo.builder()
.entityId(new DeviceId(UUID.randomUUID())) // to test templatization
.entityId(new DeviceId(UUID.randomUUID()))
.actionType(ActionType.ADDED)
.userId(tenantAdminUserId.getId())
.build())

5
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -3106,9 +3106,8 @@
"warning": "Warning",
"webhook-url": "Webhook URL",
"webhook-url-required": "Webhook URL is required",
"channel-name": "Chanel name",
"channel-name-required": "Chanel name is required"
"channel-name": "Channel name",
"channel-name-required": "Channel name is required"
},
"ota-update": {
"add": "Add package",

Loading…
Cancel
Save