Browse Source

Remove tenant_id constraint from notification entities; permission checks refactoring

pull/7911/head
ViacheslavKlimov 4 years ago
parent
commit
627889a437
  1. 8
      application/src/main/data/upgrade/3.4.4/schema_update.sql
  2. 13
      application/src/main/java/org/thingsboard/server/controller/BaseController.java
  3. 11
      application/src/main/java/org/thingsboard/server/controller/NotificationController.java
  4. 5
      application/src/main/java/org/thingsboard/server/controller/NotificationRuleController.java
  5. 7
      application/src/main/java/org/thingsboard/server/controller/NotificationTargetController.java
  6. 5
      application/src/main/java/org/thingsboard/server/controller/NotificationTemplateController.java
  7. 18
      application/src/main/java/org/thingsboard/server/service/install/DefaultSystemDataLoaderService.java
  8. 2
      application/src/main/java/org/thingsboard/server/service/install/SystemDataLoaderService.java
  9. 19
      application/src/main/java/org/thingsboard/server/service/security/permission/Resource.java
  10. 2
      common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationRequestService.java
  11. 2
      common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationRuleService.java
  12. 2
      common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationSettingsService.java
  13. 2
      common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationTargetService.java
  14. 2
      common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationTemplateService.java
  15. 5
      dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationRequestService.java
  16. 5
      dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationRuleService.java
  17. 32
      dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationSettingsService.java
  18. 5
      dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationTargetService.java
  19. 5
      dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationTemplateService.java
  20. 2
      dao/src/main/java/org/thingsboard/server/dao/notification/NotificationRequestDao.java
  21. 2
      dao/src/main/java/org/thingsboard/server/dao/notification/NotificationRuleDao.java
  22. 2
      dao/src/main/java/org/thingsboard/server/dao/notification/NotificationTargetDao.java
  23. 2
      dao/src/main/java/org/thingsboard/server/dao/notification/NotificationTemplateDao.java
  24. 5
      dao/src/main/java/org/thingsboard/server/dao/sql/notification/JpaNotificationRequestDao.java
  25. 5
      dao/src/main/java/org/thingsboard/server/dao/sql/notification/JpaNotificationRuleDao.java
  26. 5
      dao/src/main/java/org/thingsboard/server/dao/sql/notification/JpaNotificationTargetDao.java
  27. 5
      dao/src/main/java/org/thingsboard/server/dao/sql/notification/JpaNotificationTemplateDao.java
  28. 2
      dao/src/main/java/org/thingsboard/server/dao/sql/notification/NotificationRequestRepository.java
  29. 2
      dao/src/main/java/org/thingsboard/server/dao/sql/notification/NotificationRuleRepository.java
  30. 2
      dao/src/main/java/org/thingsboard/server/dao/sql/notification/NotificationTargetRepository.java
  31. 2
      dao/src/main/java/org/thingsboard/server/dao/sql/notification/NotificationTemplateRepository.java
  32. 20
      dao/src/main/java/org/thingsboard/server/dao/tenant/TenantServiceImpl.java
  33. 8
      dao/src/main/resources/sql/schema-entities.sql

8
application/src/main/data/upgrade/3.4.4/schema_update.sql

@ -28,7 +28,7 @@ CREATE INDEX IF NOT EXISTS idx_alarm_comment_alarm_id ON alarm_comment(alarm_id)
CREATE TABLE IF NOT EXISTS notification_target ( CREATE TABLE IF NOT EXISTS notification_target (
id UUID NOT NULL CONSTRAINT notification_target_pkey PRIMARY KEY, id UUID NOT NULL CONSTRAINT notification_target_pkey PRIMARY KEY,
created_time BIGINT NOT NULL, created_time BIGINT NOT NULL,
tenant_id UUID NULL CONSTRAINT fk_notification_target_tenant_id REFERENCES tenant(id) ON DELETE CASCADE, tenant_id UUID NOT NULL,
name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
configuration VARCHAR(10000) NOT NULL, configuration VARCHAR(10000) NOT NULL,
CONSTRAINT uq_notification_target_name UNIQUE (tenant_id, name) CONSTRAINT uq_notification_target_name UNIQUE (tenant_id, name)
@ -38,7 +38,7 @@ CREATE INDEX IF NOT EXISTS idx_notification_target_tenant_id_created_time ON not
CREATE TABLE IF NOT EXISTS notification_template ( CREATE TABLE IF NOT EXISTS notification_template (
id UUID NOT NULL CONSTRAINT notification_template_pkey PRIMARY KEY, id UUID NOT NULL CONSTRAINT notification_template_pkey PRIMARY KEY,
created_time BIGINT NOT NULL, created_time BIGINT NOT NULL,
tenant_id UUID NULL CONSTRAINT fk_notification_template_tenant_id REFERENCES tenant(id) ON DELETE CASCADE, tenant_id UUID NOT NULL,
name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
notification_type VARCHAR(50) NOT NULL, notification_type VARCHAR(50) NOT NULL,
configuration VARCHAR(10000) NOT NULL, configuration VARCHAR(10000) NOT NULL,
@ -49,7 +49,7 @@ CREATE INDEX IF NOT EXISTS idx_notification_template_tenant_id_created_time ON n
CREATE TABLE IF NOT EXISTS notification_rule ( CREATE TABLE IF NOT EXISTS notification_rule (
id UUID NOT NULL CONSTRAINT notification_rule_pkey PRIMARY KEY, id UUID NOT NULL CONSTRAINT notification_rule_pkey PRIMARY KEY,
created_time BIGINT NOT NULL, created_time BIGINT NOT NULL,
tenant_id UUID NULL CONSTRAINT fk_notification_rule_tenant_id REFERENCES tenant(id) ON DELETE CASCADE, tenant_id UUID NOT NULL,
name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
template_id UUID NOT NULL CONSTRAINT fk_notification_rule_template_id REFERENCES notification_template(id), template_id UUID NOT NULL CONSTRAINT fk_notification_rule_template_id REFERENCES notification_template(id),
trigger_type VARCHAR(50) NOT NULL, trigger_type VARCHAR(50) NOT NULL,
@ -63,7 +63,7 @@ CREATE INDEX IF NOT EXISTS idx_notification_rule_tenant_id_created_time ON notif
CREATE TABLE IF NOT EXISTS notification_request ( CREATE TABLE IF NOT EXISTS notification_request (
id UUID NOT NULL CONSTRAINT notification_request_pkey PRIMARY KEY, id UUID NOT NULL CONSTRAINT notification_request_pkey PRIMARY KEY,
created_time BIGINT NOT NULL, created_time BIGINT NOT NULL,
tenant_id UUID NULL CONSTRAINT fk_notification_request_tenant_id REFERENCES tenant(id) ON DELETE CASCADE, tenant_id UUID NOT NULL,
targets VARCHAR(10000) NOT NULL, targets VARCHAR(10000) NOT NULL,
template_id UUID, template_id UUID,
template VARCHAR(10000), template VARCHAR(10000),

13
application/src/main/java/org/thingsboard/server/controller/BaseController.java

@ -601,22 +601,23 @@ public abstract class BaseController {
} }
protected <E extends HasId<I> & HasTenantId, I extends EntityId> E checkEntityId(I entityId, ThrowingBiFunction<TenantId, I, E> findingFunction, Operation operation) throws ThingsboardException { protected <E extends HasId<I> & HasTenantId, I extends EntityId> E checkEntityId(I entityId, ThrowingBiFunction<TenantId, I, E> findingFunction, Operation operation) throws ThingsboardException {
return checkEntityId(Resource.of(entityId.getEntityType()), operation, entityId, findingFunction);
}
protected <E extends HasId<I> & HasTenantId, I extends EntityId> E checkEntityId(Resource resource, Operation operation, I entityId, ThrowingBiFunction<TenantId, I, E> findingFunction) throws ThingsboardException {
try { try {
validateId((UUIDBased) entityId, "Invalid entity id"); validateId((UUIDBased) entityId, "Invalid entity id");
SecurityUser user = getCurrentUser(); SecurityUser user = getCurrentUser();
E entity = findingFunction.apply(user.getTenantId(), entityId); E entity = findingFunction.apply(user.getTenantId(), entityId);
checkNotNull(entity, entityId.getEntityType() + " with id [" + entityId + "] not found"); checkNotNull(entity, entityId.getEntityType() + " with id [" + entityId + "] not found");
accessControlService.checkPermission(user, resource, operation, entityId, entity); return checkEntity(user, entity, operation);
return entity;
} catch (Exception e) { } catch (Exception e) {
throw handleException(e, false); throw handleException(e, false);
} }
} }
protected <E extends HasId<I> & HasTenantId, I extends EntityId> E checkEntity(SecurityUser user, E entity, Operation operation) throws ThingsboardException {
checkNotNull(entity, "Entity not found");
accessControlService.checkPermission(user, Resource.of(entity.getId().getEntityType()), operation, entity.getId(), entity);
return entity;
}
Device checkDeviceId(DeviceId deviceId, Operation operation) throws ThingsboardException { Device checkDeviceId(DeviceId deviceId, Operation operation) throws ThingsboardException {
return checkEntityId(deviceId, deviceService::findDeviceById, operation); return checkEntityId(deviceId, deviceService::findDeviceById, operation);
} }

11
application/src/main/java/org/thingsboard/server/controller/NotificationController.java

@ -58,7 +58,6 @@ import org.thingsboard.server.dao.notification.NotificationTemplateService;
import org.thingsboard.server.queue.util.TbCoreComponent; import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.security.model.SecurityUser; import org.thingsboard.server.service.security.model.SecurityUser;
import org.thingsboard.server.service.security.permission.Operation; import org.thingsboard.server.service.security.permission.Operation;
import org.thingsboard.server.service.security.permission.Resource;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.Collections; import java.util.Collections;
@ -133,7 +132,7 @@ public class NotificationController extends BaseController {
"```\n{\n" + "```\n{\n" +
" \"cmdId\": 1234,\n" + " \"cmdId\": 1234,\n" +
" \"totalUnreadCount\": 5\n" + " \"totalUnreadCount\": 5\n" +
"}\n```" ) "}\n```")
@GetMapping("/notifications") @GetMapping("/notifications")
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
public PageData<Notification> getNotifications(@RequestParam int pageSize, public PageData<Notification> getNotifications(@RequestParam int pageSize,
@ -203,9 +202,7 @@ public class NotificationController extends BaseController {
request.setOriginatorEntityId(user.getId()); request.setOriginatorEntityId(user.getId());
NotificationTemplate template; NotificationTemplate template;
if (request.getTemplateId() != null) { if (request.getTemplateId() != null) {
template = notificationTemplateService.findNotificationTemplateById(user.getTenantId(), request.getTemplateId()); template = checkEntityId(request.getTemplateId(), notificationTemplateService::findNotificationTemplateById, Operation.READ);
checkNotNull(template, "Template not found");
accessControlService.checkPermission(user, NOTIFICATION, Operation.READ, template.getId(), template);
} else { } else {
template = request.getTemplate(); template = request.getTemplate();
} }
@ -254,7 +251,7 @@ public class NotificationController extends BaseController {
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
public NotificationRequestInfo getNotificationRequestById(@PathVariable UUID id) throws ThingsboardException { public NotificationRequestInfo getNotificationRequestById(@PathVariable UUID id) throws ThingsboardException {
NotificationRequestId notificationRequestId = new NotificationRequestId(id); NotificationRequestId notificationRequestId = new NotificationRequestId(id);
return checkEntityId(NOTIFICATION, Operation.READ, notificationRequestId, notificationRequestService::findNotificationRequestInfoById); return checkEntityId(notificationRequestId, notificationRequestService::findNotificationRequestInfoById, Operation.READ);
} }
@GetMapping("/notification/requests") @GetMapping("/notification/requests")
@ -274,7 +271,7 @@ public class NotificationController extends BaseController {
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
public void deleteNotificationRequest(@PathVariable UUID id) throws Exception { public void deleteNotificationRequest(@PathVariable UUID id) throws Exception {
NotificationRequestId notificationRequestId = new NotificationRequestId(id); NotificationRequestId notificationRequestId = new NotificationRequestId(id);
NotificationRequest notificationRequest = checkEntityId(NOTIFICATION, Operation.DELETE, notificationRequestId, notificationRequestService::findNotificationRequestById); NotificationRequest notificationRequest = checkEntityId(notificationRequestId, notificationRequestService::findNotificationRequestById, Operation.DELETE);
doDeleteAndLog(EntityType.NOTIFICATION_REQUEST, notificationRequest, notificationCenter::deleteNotificationRequest); doDeleteAndLog(EntityType.NOTIFICATION_REQUEST, notificationRequest, notificationCenter::deleteNotificationRequest);
} }

5
application/src/main/java/org/thingsboard/server/controller/NotificationRuleController.java

@ -39,7 +39,6 @@ import org.thingsboard.server.dao.notification.NotificationRuleService;
import org.thingsboard.server.queue.util.TbCoreComponent; import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.security.model.SecurityUser; import org.thingsboard.server.service.security.model.SecurityUser;
import org.thingsboard.server.service.security.permission.Operation; import org.thingsboard.server.service.security.permission.Operation;
import org.thingsboard.server.service.security.permission.Resource;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.UUID; import java.util.UUID;
@ -67,7 +66,7 @@ public class NotificationRuleController extends BaseController {
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
public NotificationRuleInfo getNotificationRuleById(@PathVariable UUID id) throws ThingsboardException { public NotificationRuleInfo getNotificationRuleById(@PathVariable UUID id) throws ThingsboardException {
NotificationRuleId notificationRuleId = new NotificationRuleId(id); NotificationRuleId notificationRuleId = new NotificationRuleId(id);
return checkEntityId(NOTIFICATION, Operation.READ, notificationRuleId, notificationRuleService::findNotificationRuleInfoById); return checkEntityId(notificationRuleId, notificationRuleService::findNotificationRuleInfoById, Operation.READ);
} }
@GetMapping("/rules") @GetMapping("/rules")
@ -88,7 +87,7 @@ public class NotificationRuleController extends BaseController {
public void deleteNotificationRule(@PathVariable UUID id, public void deleteNotificationRule(@PathVariable UUID id,
@AuthenticationPrincipal SecurityUser user) throws Exception { @AuthenticationPrincipal SecurityUser user) throws Exception {
NotificationRuleId notificationRuleId = new NotificationRuleId(id); NotificationRuleId notificationRuleId = new NotificationRuleId(id);
NotificationRule notificationRule = checkEntityId(NOTIFICATION, Operation.DELETE, notificationRuleId, notificationRuleService::findNotificationRuleById); NotificationRule notificationRule = checkEntityId(notificationRuleId, notificationRuleService::findNotificationRuleById, Operation.DELETE);
doDeleteAndLog(EntityType.NOTIFICATION_RULE, notificationRule, notificationRuleService::deleteNotificationRuleById); doDeleteAndLog(EntityType.NOTIFICATION_RULE, notificationRule, notificationRuleService::deleteNotificationRuleById);
tbClusterService.broadcastEntityStateChangeEvent(user.getTenantId(), notificationRuleId, ComponentLifecycleEvent.DELETED); tbClusterService.broadcastEntityStateChangeEvent(user.getTenantId(), notificationRuleId, ComponentLifecycleEvent.DELETED);
} }

7
application/src/main/java/org/thingsboard/server/controller/NotificationTargetController.java

@ -47,7 +47,6 @@ import org.thingsboard.server.dao.notification.NotificationTargetService;
import org.thingsboard.server.queue.util.TbCoreComponent; import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.security.model.SecurityUser; import org.thingsboard.server.service.security.model.SecurityUser;
import org.thingsboard.server.service.security.permission.Operation; import org.thingsboard.server.service.security.permission.Operation;
import org.thingsboard.server.service.security.permission.Resource;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.Arrays; import java.util.Arrays;
@ -101,7 +100,7 @@ public class NotificationTargetController extends BaseController {
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
public NotificationTarget getNotificationTargetById(@PathVariable UUID id) throws ThingsboardException { public NotificationTarget getNotificationTargetById(@PathVariable UUID id) throws ThingsboardException {
NotificationTargetId notificationTargetId = new NotificationTargetId(id); NotificationTargetId notificationTargetId = new NotificationTargetId(id);
return checkEntityId(NOTIFICATION, Operation.READ, notificationTargetId, notificationTargetService::findNotificationTargetById); return checkEntityId(notificationTargetId, notificationTargetService::findNotificationTargetById, Operation.READ);
} }
@ApiOperation(value = "Get recipients for notification target config (getRecipientsForNotificationTargetConfig)", @ApiOperation(value = "Get recipients for notification target config (getRecipientsForNotificationTargetConfig)",
@ -158,7 +157,7 @@ public class NotificationTargetController extends BaseController {
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
public void deleteNotificationTargetById(@PathVariable UUID id) throws Exception { public void deleteNotificationTargetById(@PathVariable UUID id) throws Exception {
NotificationTargetId notificationTargetId = new NotificationTargetId(id); NotificationTargetId notificationTargetId = new NotificationTargetId(id);
NotificationTarget notificationTarget = checkEntityId(NOTIFICATION, Operation.DELETE, notificationTargetId, notificationTargetService::findNotificationTargetById); NotificationTarget notificationTarget = checkEntityId(notificationTargetId, notificationTargetService::findNotificationTargetById, Operation.DELETE);
doDeleteAndLog(EntityType.NOTIFICATION_TARGET, notificationTarget, notificationTargetService::deleteNotificationTargetById); doDeleteAndLog(EntityType.NOTIFICATION_TARGET, notificationTarget, notificationTargetService::deleteNotificationTargetById);
} }
@ -173,7 +172,7 @@ public class NotificationTargetController extends BaseController {
return notificationTargetService.findRecipientsForNotificationTargetConfig(user.getTenantId(), null, targetConfig, pageLink); return notificationTargetService.findRecipientsForNotificationTargetConfig(user.getTenantId(), null, targetConfig, pageLink);
}, 200); }, 200);
for (User recipient : recipients) { for (User recipient : recipients) {
accessControlService.checkPermission(user, Resource.USER, Operation.READ, recipient.getId(), recipient); checkEntity(user, recipient, Operation.READ);
} }
} else if (usersFilter.getType() == UsersFilterType.CUSTOMER_USERS) { } else if (usersFilter.getType() == UsersFilterType.CUSTOMER_USERS) {
CustomerId customerId = new CustomerId(((CustomerUsersFilter) usersFilter).getCustomerId()); CustomerId customerId = new CustomerId(((CustomerUsersFilter) usersFilter).getCustomerId());

5
application/src/main/java/org/thingsboard/server/controller/NotificationTemplateController.java

@ -45,7 +45,6 @@ import org.thingsboard.server.dao.notification.NotificationTemplateService;
import org.thingsboard.server.queue.util.TbCoreComponent; import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.security.model.SecurityUser; import org.thingsboard.server.service.security.model.SecurityUser;
import org.thingsboard.server.service.security.permission.Operation; import org.thingsboard.server.service.security.permission.Operation;
import org.thingsboard.server.service.security.permission.Resource;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.List; import java.util.List;
@ -94,7 +93,7 @@ public class NotificationTemplateController extends BaseController {
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
public NotificationTemplate getNotificationTemplateById(@PathVariable UUID id) throws ThingsboardException { public NotificationTemplate getNotificationTemplateById(@PathVariable UUID id) throws ThingsboardException {
NotificationTemplateId notificationTemplateId = new NotificationTemplateId(id); NotificationTemplateId notificationTemplateId = new NotificationTemplateId(id);
return checkEntityId(NOTIFICATION, Operation.READ, notificationTemplateId, notificationTemplateService::findNotificationTemplateById); return checkEntityId(notificationTemplateId, notificationTemplateService::findNotificationTemplateById, Operation.READ);
} }
@ApiOperation(value = "Get notification templates (getNotificationTemplates)", @ApiOperation(value = "Get notification templates (getNotificationTemplates)",
@ -126,7 +125,7 @@ public class NotificationTemplateController extends BaseController {
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
public void deleteNotificationTemplateById(@PathVariable UUID id) throws Exception { public void deleteNotificationTemplateById(@PathVariable UUID id) throws Exception {
NotificationTemplateId notificationTemplateId = new NotificationTemplateId(id); NotificationTemplateId notificationTemplateId = new NotificationTemplateId(id);
NotificationTemplate notificationTemplate = checkEntityId(NOTIFICATION, Operation.DELETE, notificationTemplateId, notificationTemplateService::findNotificationTemplateById); NotificationTemplate notificationTemplate = checkEntityId(notificationTemplateId, notificationTemplateService::findNotificationTemplateById, Operation.DELETE);
doDeleteAndLog(EntityType.NOTIFICATION_TEMPLATE, notificationTemplate, notificationTemplateService::deleteNotificationTemplateById); doDeleteAndLog(EntityType.NOTIFICATION_TEMPLATE, notificationTemplate, notificationTemplateService::deleteNotificationTemplateById);
} }

18
application/src/main/java/org/thingsboard/server/service/install/DefaultSystemDataLoaderService.java

@ -62,6 +62,7 @@ import org.thingsboard.server.common.data.kv.BasicTsKvEntry;
import org.thingsboard.server.common.data.kv.BooleanDataEntry; import org.thingsboard.server.common.data.kv.BooleanDataEntry;
import org.thingsboard.server.common.data.kv.DoubleDataEntry; import org.thingsboard.server.common.data.kv.DoubleDataEntry;
import org.thingsboard.server.common.data.kv.LongDataEntry; import org.thingsboard.server.common.data.kv.LongDataEntry;
import org.thingsboard.server.common.data.page.PageDataIterable;
import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.query.BooleanFilterPredicate; import org.thingsboard.server.common.data.query.BooleanFilterPredicate;
import org.thingsboard.server.common.data.query.DynamicValue; import org.thingsboard.server.common.data.query.DynamicValue;
@ -82,13 +83,13 @@ import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileCon
import org.thingsboard.server.common.data.tenant.profile.TenantProfileData; import org.thingsboard.server.common.data.tenant.profile.TenantProfileData;
import org.thingsboard.server.common.data.tenant.profile.TenantProfileQueueConfiguration; import org.thingsboard.server.common.data.tenant.profile.TenantProfileQueueConfiguration;
import org.thingsboard.server.common.data.widget.WidgetsBundle; import org.thingsboard.server.common.data.widget.WidgetsBundle;
import org.thingsboard.server.service.security.auth.jwt.settings.JwtSettingsService;
import org.thingsboard.server.dao.attributes.AttributesService; import org.thingsboard.server.dao.attributes.AttributesService;
import org.thingsboard.server.dao.customer.CustomerService; import org.thingsboard.server.dao.customer.CustomerService;
import org.thingsboard.server.dao.device.DeviceCredentialsService; import org.thingsboard.server.dao.device.DeviceCredentialsService;
import org.thingsboard.server.dao.device.DeviceProfileService; import org.thingsboard.server.dao.device.DeviceProfileService;
import org.thingsboard.server.dao.device.DeviceService; import org.thingsboard.server.dao.device.DeviceService;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.notification.NotificationSettingsService;
import org.thingsboard.server.dao.queue.QueueService; import org.thingsboard.server.dao.queue.QueueService;
import org.thingsboard.server.dao.rule.RuleChainService; import org.thingsboard.server.dao.rule.RuleChainService;
import org.thingsboard.server.dao.settings.AdminSettingsService; import org.thingsboard.server.dao.settings.AdminSettingsService;
@ -97,6 +98,7 @@ import org.thingsboard.server.dao.tenant.TenantService;
import org.thingsboard.server.dao.timeseries.TimeseriesService; import org.thingsboard.server.dao.timeseries.TimeseriesService;
import org.thingsboard.server.dao.user.UserService; import org.thingsboard.server.dao.user.UserService;
import org.thingsboard.server.dao.widget.WidgetsBundleService; import org.thingsboard.server.dao.widget.WidgetsBundleService;
import org.thingsboard.server.service.security.auth.jwt.settings.JwtSettingsService;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
@ -171,6 +173,9 @@ public class DefaultSystemDataLoaderService implements SystemDataLoaderService {
@Autowired @Autowired
private JwtSettingsService jwtSettingsService; private JwtSettingsService jwtSettingsService;
@Autowired
private NotificationSettingsService notificationSettingsService;
@Bean @Bean
protected BCryptPasswordEncoder passwordEncoder() { protected BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder(); return new BCryptPasswordEncoder();
@ -672,8 +677,15 @@ public class DefaultSystemDataLoaderService implements SystemDataLoaderService {
} }
@Override @Override
public void createNotificationConfigs() { public void createDefaultNotificationConfigs() {
// create default notification targets: Alarm's customer PageDataIterable<TenantId> tenants = new PageDataIterable<>(tenantService::findTenantsIds, 500);
for (TenantId tenantId : tenants) {
try {
notificationSettingsService.createDefaultNotificationConfigs(tenantId);
} catch (Exception e) {
log.warn("Failed to create default notification configs for tenant {}: {}", tenantId, e.getMessage());
}
}
} }
} }

2
application/src/main/java/org/thingsboard/server/service/install/SystemDataLoaderService.java

@ -39,6 +39,6 @@ public interface SystemDataLoaderService {
void createQueues(); void createQueues();
void createNotificationConfigs(); void createDefaultNotificationConfigs();
} }

19
application/src/main/java/org/thingsboard/server/service/security/permission/Resource.java

@ -17,7 +17,9 @@ package org.thingsboard.server.service.security.permission;
import org.thingsboard.server.common.data.EntityType; import org.thingsboard.server.common.data.EntityType;
import java.util.Collections;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
public enum Resource { public enum Resource {
ADMIN_SETTINGS(), ADMIN_SETTINGS(),
@ -44,25 +46,26 @@ public enum Resource {
RPC(EntityType.RPC), RPC(EntityType.RPC),
QUEUE(EntityType.QUEUE), QUEUE(EntityType.QUEUE),
VERSION_CONTROL, VERSION_CONTROL,
NOTIFICATION; NOTIFICATION(EntityType.NOTIFICATION_TARGET, EntityType.NOTIFICATION_TEMPLATE,
EntityType.NOTIFICATION_REQUEST, EntityType.NOTIFICATION_RULE);
private final EntityType entityType; private final Set<EntityType> entityTypes;
Resource() { Resource() {
this.entityType = null; this.entityTypes = null;
} }
Resource(EntityType entityType) { Resource(EntityType... entityTypes) {
this.entityType = entityType; this.entityTypes = Set.of(entityTypes);
} }
public Optional<EntityType> getEntityType() { public Set<EntityType> getEntityTypes() {
return Optional.ofNullable(entityType); return Optional.ofNullable(entityTypes).orElse(Collections.emptySet());
} }
public static Resource of(EntityType entityType) { public static Resource of(EntityType entityType) {
for (Resource resource : Resource.values()) { for (Resource resource : Resource.values()) {
if (resource.getEntityType().orElse(null) == entityType) { if (resource.getEntityTypes().contains(entityType)) {
return resource; return resource;
} }
} }

2
common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationRequestService.java

@ -51,4 +51,6 @@ public interface NotificationRequestService {
void updateNotificationRequest(TenantId tenantId, NotificationRequestId requestId, NotificationRequestStatus requestStatus, NotificationRequestStats stats); void updateNotificationRequest(TenantId tenantId, NotificationRequestId requestId, NotificationRequestStatus requestStatus, NotificationRequestStats stats);
void deleteNotificationRequestsByTenantId(TenantId tenantId);
} }

2
common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationRuleService.java

@ -41,4 +41,6 @@ public interface NotificationRuleService {
void deleteNotificationRuleById(TenantId tenantId, NotificationRuleId id); void deleteNotificationRuleById(TenantId tenantId, NotificationRuleId id);
void deleteNotificationRulesByTenantId(TenantId tenantId);
} }

2
common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationSettingsService.java

@ -24,4 +24,6 @@ public interface NotificationSettingsService {
NotificationSettings findNotificationSettings(TenantId tenantId); NotificationSettings findNotificationSettings(TenantId tenantId);
void createDefaultNotificationConfigs(TenantId tenantId);
} }

2
common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationTargetService.java

@ -44,4 +44,6 @@ public interface NotificationTargetService {
void deleteNotificationTargetById(TenantId tenantId, NotificationTargetId id); void deleteNotificationTargetById(TenantId tenantId, NotificationTargetId id);
void deleteNotificationTargetsByTenantId(TenantId tenantId);
} }

2
common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationTemplateService.java

@ -34,4 +34,6 @@ public interface NotificationTemplateService {
void deleteNotificationTemplateById(TenantId tenantId, NotificationTemplateId id); void deleteNotificationTemplateById(TenantId tenantId, NotificationTemplateId id);
void deleteNotificationTemplatesByTenantId(TenantId tenantId);
} }

5
dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationRequestService.java

@ -95,6 +95,11 @@ public class DefaultNotificationRequestService implements NotificationRequestSer
notificationRequestDao.updateById(tenantId, requestId, requestStatus, stats); notificationRequestDao.updateById(tenantId, requestId, requestStatus, stats);
} }
@Override
public void deleteNotificationRequestsByTenantId(TenantId tenantId) {
notificationRequestDao.removeByTenantId(tenantId);
}
private static class NotificationRequestValidator extends DataValidator<NotificationRequest> { private static class NotificationRequestValidator extends DataValidator<NotificationRequest> {

5
dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationRuleService.java

@ -98,6 +98,11 @@ public class DefaultNotificationRuleService extends AbstractCachedEntityService<
notificationRuleDao.removeById(tenantId, id.getId()); notificationRuleDao.removeById(tenantId, id.getId());
} }
@Override
public void deleteNotificationRulesByTenantId(TenantId tenantId) {
notificationRuleDao.removeByTenantId(tenantId);
}
@Override @Override
public void handleEvictEvent(NotificationRule notificationRule) { public void handleEvictEvent(NotificationRule notificationRule) {
NotificationRuleCacheKey cacheKey = NotificationRuleCacheKey.builder() NotificationRuleCacheKey cacheKey = NotificationRuleCacheKey.builder()

32
dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationSettingsService.java

@ -21,6 +21,11 @@ import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.server.common.data.AdminSettings; import org.thingsboard.server.common.data.AdminSettings;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.notification.settings.NotificationSettings; import org.thingsboard.server.common.data.notification.settings.NotificationSettings;
import org.thingsboard.server.common.data.notification.targets.NotificationTarget;
import org.thingsboard.server.common.data.notification.targets.platform.AllUsersFilter;
import org.thingsboard.server.common.data.notification.targets.platform.OriginatorEntityOwnerUsersFilter;
import org.thingsboard.server.common.data.notification.targets.platform.PlatformUsersNotificationTargetConfig;
import org.thingsboard.server.common.data.notification.template.NotificationTemplate;
import org.thingsboard.server.dao.settings.AdminSettingsService; import org.thingsboard.server.dao.settings.AdminSettingsService;
import java.util.Collections; import java.util.Collections;
@ -31,6 +36,9 @@ import java.util.Optional;
public class DefaultNotificationSettingsService implements NotificationSettingsService { public class DefaultNotificationSettingsService implements NotificationSettingsService {
private final AdminSettingsService adminSettingsService; private final AdminSettingsService adminSettingsService;
private final NotificationTargetService notificationTargetService;
private final NotificationTemplateService notificationTemplateService;
private final NotificationRuleService notificationRuleService;
private static final String SETTINGS_KEY = "notifications"; private static final String SETTINGS_KEY = "notifications";
@ -58,4 +66,28 @@ public class DefaultNotificationSettingsService implements NotificationSettingsS
}); });
} }
@Override
public void createDefaultNotificationConfigs(TenantId tenantId) {
NotificationTarget allUsersTarget = new NotificationTarget();
allUsersTarget.setTenantId(tenantId);
allUsersTarget.setName("All users");
PlatformUsersNotificationTargetConfig targetConfig = new PlatformUsersNotificationTargetConfig();
targetConfig.setUsersFilter(new AllUsersFilter());
targetConfig.setDescription("All users in scope of tenant");
allUsersTarget.setConfiguration(targetConfig);
allUsersTarget = notificationTargetService.saveNotificationTarget(tenantId, allUsersTarget);
NotificationTarget originatorEntityOwnerUsers = new NotificationTarget();
originatorEntityOwnerUsers.setTenantId(tenantId);
originatorEntityOwnerUsers.setName("Users of rule trigger entity's owner");
targetConfig.setUsersFilter(new OriginatorEntityOwnerUsersFilter());
targetConfig.setDescription("For usage with notification rules. For example, if alarm trigger type is chosen, " +
"notifications will be sent to alarm owner's users, e.g. it's customer's users");
originatorEntityOwnerUsers.setConfiguration(targetConfig);
originatorEntityOwnerUsers = notificationTargetService.saveNotificationTarget(tenantId, originatorEntityOwnerUsers);
NotificationTemplate alarmNotificationTemplate = new NotificationTemplate();
}
} }

5
dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationTargetService.java

@ -142,4 +142,9 @@ public class DefaultNotificationTargetService extends AbstractEntityService impl
notificationTargetDao.removeById(tenantId, id.getId()); notificationTargetDao.removeById(tenantId, id.getId());
} }
@Override
public void deleteNotificationTargetsByTenantId(TenantId tenantId) {
notificationTargetDao.removeByTenantId(tenantId);
}
} }

5
dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationTemplateService.java

@ -73,4 +73,9 @@ public class DefaultNotificationTemplateService extends AbstractEntityService im
} }
} }
@Override
public void deleteNotificationTemplatesByTenantId(TenantId tenantId) {
notificationTemplateDao.removeByTenantId(tenantId);
}
} }

2
dao/src/main/java/org/thingsboard/server/dao/notification/NotificationRequestDao.java

@ -54,4 +54,6 @@ public interface NotificationRequestDao extends Dao<NotificationRequest> {
NotificationRequestInfo findInfoById(TenantId tenantId, NotificationRequestId id); NotificationRequestInfo findInfoById(TenantId tenantId, NotificationRequestId id);
void removeByTenantId(TenantId tenantId);
} }

2
dao/src/main/java/org/thingsboard/server/dao/notification/NotificationRuleDao.java

@ -39,4 +39,6 @@ public interface NotificationRuleDao extends Dao<NotificationRule> {
NotificationRuleInfo findInfoById(TenantId tenantId, NotificationRuleId id); NotificationRuleInfo findInfoById(TenantId tenantId, NotificationRuleId id);
void removeByTenantId(TenantId tenantId);
} }

2
dao/src/main/java/org/thingsboard/server/dao/notification/NotificationTargetDao.java

@ -30,4 +30,6 @@ public interface NotificationTargetDao extends Dao<NotificationTarget> {
List<NotificationTarget> findByTenantIdAndIds(TenantId tenantId, List<NotificationTargetId> ids); List<NotificationTarget> findByTenantIdAndIds(TenantId tenantId, List<NotificationTargetId> ids);
void removeByTenantId(TenantId tenantId);
} }

2
dao/src/main/java/org/thingsboard/server/dao/notification/NotificationTemplateDao.java

@ -28,4 +28,6 @@ public interface NotificationTemplateDao extends Dao<NotificationTemplate> {
PageData<NotificationTemplate> findByTenantIdAndNotificationTypesAndPageLink(TenantId tenantId, List<NotificationType> notificationTypes, PageLink pageLink); PageData<NotificationTemplate> findByTenantIdAndNotificationTypesAndPageLink(TenantId tenantId, List<NotificationType> notificationTypes, PageLink pageLink);
void removeByTenantId(TenantId tenantId);
} }

5
dao/src/main/java/org/thingsboard/server/dao/sql/notification/JpaNotificationRequestDao.java

@ -107,6 +107,11 @@ public class JpaNotificationRequestDao extends JpaAbstractDao<NotificationReques
return info != null ? info.toData() : null; return info != null ? info.toData() : null;
} }
@Override
public void removeByTenantId(TenantId tenantId) {
notificationRequestRepository.deleteByTenantId(tenantId.getId());
}
@Override @Override
protected Class<NotificationRequestEntity> getEntityClass() { protected Class<NotificationRequestEntity> getEntityClass() {
return NotificationRequestEntity.class; return NotificationRequestEntity.class;

5
dao/src/main/java/org/thingsboard/server/dao/sql/notification/JpaNotificationRuleDao.java

@ -75,6 +75,11 @@ public class JpaNotificationRuleDao extends JpaAbstractDao<NotificationRuleEntit
return infoEntity != null ? infoEntity.toData() : null; return infoEntity != null ? infoEntity.toData() : null;
} }
@Override
public void removeByTenantId(TenantId tenantId) {
notificationRuleRepository.deleteByTenantId(tenantId.getId());
}
@Override @Override
protected Class<NotificationRuleEntity> getEntityClass() { protected Class<NotificationRuleEntity> getEntityClass() {
return NotificationRuleEntity.class; return NotificationRuleEntity.class;

5
dao/src/main/java/org/thingsboard/server/dao/sql/notification/JpaNotificationTargetDao.java

@ -56,6 +56,11 @@ public class JpaNotificationTargetDao extends JpaAbstractDao<NotificationTargetE
return DaoUtil.convertDataList(notificationTargetRepository.findByTenantIdAndIdIn(tenantId.getId(), DaoUtil.toUUIDs(ids))); return DaoUtil.convertDataList(notificationTargetRepository.findByTenantIdAndIdIn(tenantId.getId(), DaoUtil.toUUIDs(ids)));
} }
@Override
public void removeByTenantId(TenantId tenantId) {
notificationTargetRepository.deleteByTenantId(tenantId.getId());
}
@Override @Override
protected Class<NotificationTargetEntity> getEntityClass() { protected Class<NotificationTargetEntity> getEntityClass() {
return NotificationTargetEntity.class; return NotificationTargetEntity.class;

5
dao/src/main/java/org/thingsboard/server/dao/sql/notification/JpaNotificationTemplateDao.java

@ -54,6 +54,11 @@ public class JpaNotificationTemplateDao extends JpaAbstractDao<NotificationTempl
notificationTypes, Strings.nullToEmpty(pageLink.getTextSearch()), DaoUtil.toPageable(pageLink))); notificationTypes, Strings.nullToEmpty(pageLink.getTextSearch()), DaoUtil.toPageable(pageLink)));
} }
@Override
public void removeByTenantId(TenantId tenantId) {
notificationTemplateRepository.deleteByTenantId(tenantId.getId());
}
@Override @Override
protected JpaRepository<NotificationTemplateEntity, UUID> getRepository() { protected JpaRepository<NotificationTemplateEntity, UUID> getRepository() {
return notificationTemplateRepository; return notificationTemplateRepository;

2
dao/src/main/java/org/thingsboard/server/dao/sql/notification/NotificationRequestRepository.java

@ -71,4 +71,6 @@ public interface NotificationRequestRepository extends JpaRepository<Notificatio
int deleteAllByCreatedTimeBefore(long ts); int deleteAllByCreatedTimeBefore(long ts);
void deleteByTenantId(UUID tenantId);
} }

2
dao/src/main/java/org/thingsboard/server/dao/sql/notification/NotificationRuleRepository.java

@ -53,4 +53,6 @@ public interface NotificationRuleRepository extends JpaRepository<NotificationRu
@Param("searchText") String searchText, @Param("searchText") String searchText,
Pageable pageable); Pageable pageable);
void deleteByTenantId(UUID tenantId);
} }

2
dao/src/main/java/org/thingsboard/server/dao/sql/notification/NotificationTargetRepository.java

@ -33,4 +33,6 @@ public interface NotificationTargetRepository extends JpaRepository<Notification
List<NotificationTargetEntity> findByTenantIdAndIdIn(UUID tenantId, List<UUID> ids); List<NotificationTargetEntity> findByTenantIdAndIdIn(UUID tenantId, List<UUID> ids);
void deleteByTenantId(UUID tenantId);
} }

2
dao/src/main/java/org/thingsboard/server/dao/sql/notification/NotificationTemplateRepository.java

@ -39,4 +39,6 @@ public interface NotificationTemplateRepository extends JpaRepository<Notificati
@Param("searchText") String searchText, @Param("searchText") String searchText,
Pageable pageable); Pageable pageable);
void deleteByTenantId(UUID tenantId);
} }

20
dao/src/main/java/org/thingsboard/server/dao/tenant/TenantServiceImpl.java

@ -40,7 +40,11 @@ import org.thingsboard.server.dao.dashboard.DashboardService;
import org.thingsboard.server.dao.device.DeviceProfileService; import org.thingsboard.server.dao.device.DeviceProfileService;
import org.thingsboard.server.dao.device.DeviceService; import org.thingsboard.server.dao.device.DeviceService;
import org.thingsboard.server.dao.entity.AbstractCachedEntityService; import org.thingsboard.server.dao.entity.AbstractCachedEntityService;
import org.thingsboard.server.dao.notification.NotificationRequestService;
import org.thingsboard.server.dao.notification.NotificationRuleService;
import org.thingsboard.server.dao.notification.NotificationSettingsService; import org.thingsboard.server.dao.notification.NotificationSettingsService;
import org.thingsboard.server.dao.notification.NotificationTargetService;
import org.thingsboard.server.dao.notification.NotificationTemplateService;
import org.thingsboard.server.dao.ota.OtaPackageService; import org.thingsboard.server.dao.ota.OtaPackageService;
import org.thingsboard.server.dao.queue.QueueService; import org.thingsboard.server.dao.queue.QueueService;
import org.thingsboard.server.dao.resource.ResourceService; import org.thingsboard.server.dao.resource.ResourceService;
@ -127,6 +131,18 @@ public class TenantServiceImpl extends AbstractCachedEntityService<TenantId, Ten
@Autowired @Autowired
private NotificationSettingsService notificationSettingsService; private NotificationSettingsService notificationSettingsService;
@Autowired
private NotificationRequestService notificationRequestService;
@Autowired
private NotificationRuleService notificationRuleService;
@Autowired
private NotificationTemplateService notificationTemplateService;
@Autowired
private NotificationTargetService notificationTargetService;
@Autowired @Autowired
protected TbTransactionalCache<TenantId, Boolean> existsTenantCache; protected TbTransactionalCache<TenantId, Boolean> existsTenantCache;
@ -209,6 +225,10 @@ public class TenantServiceImpl extends AbstractCachedEntityService<TenantId, Ten
otaPackageService.deleteOtaPackagesByTenantId(tenantId); otaPackageService.deleteOtaPackagesByTenantId(tenantId);
rpcService.deleteAllRpcByTenantId(tenantId); rpcService.deleteAllRpcByTenantId(tenantId);
queueService.deleteQueuesByTenantId(tenantId); queueService.deleteQueuesByTenantId(tenantId);
notificationRequestService.deleteNotificationRequestsByTenantId(tenantId);
notificationRuleService.deleteNotificationRulesByTenantId(tenantId);
notificationTemplateService.deleteNotificationTemplatesByTenantId(tenantId);
notificationTargetService.deleteNotificationTargetsByTenantId(tenantId);
adminSettingsService.deleteAdminSettingsByTenantId(tenantId); adminSettingsService.deleteAdminSettingsByTenantId(tenantId);
tenantDao.removeById(tenantId, tenantId.getId()); tenantDao.removeById(tenantId, tenantId.getId());
publishEvictEvent(new TenantEvictEvent(tenantId, true)); publishEvictEvent(new TenantEvictEvent(tenantId, true));

8
dao/src/main/resources/sql/schema-entities.sql

@ -795,7 +795,7 @@ CREATE TABLE IF NOT EXISTS user_auth_settings (
CREATE TABLE IF NOT EXISTS notification_target ( CREATE TABLE IF NOT EXISTS notification_target (
id UUID NOT NULL CONSTRAINT notification_target_pkey PRIMARY KEY, id UUID NOT NULL CONSTRAINT notification_target_pkey PRIMARY KEY,
created_time BIGINT NOT NULL, created_time BIGINT NOT NULL,
tenant_id UUID NULL CONSTRAINT fk_notification_target_tenant_id REFERENCES tenant(id) ON DELETE CASCADE, tenant_id UUID NOT NULL,
name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
configuration VARCHAR(10000) NOT NULL, configuration VARCHAR(10000) NOT NULL,
CONSTRAINT uq_notification_target_name UNIQUE (tenant_id, name) CONSTRAINT uq_notification_target_name UNIQUE (tenant_id, name)
@ -804,7 +804,7 @@ CREATE TABLE IF NOT EXISTS notification_target (
CREATE TABLE IF NOT EXISTS notification_template ( CREATE TABLE IF NOT EXISTS notification_template (
id UUID NOT NULL CONSTRAINT notification_template_pkey PRIMARY KEY, id UUID NOT NULL CONSTRAINT notification_template_pkey PRIMARY KEY,
created_time BIGINT NOT NULL, created_time BIGINT NOT NULL,
tenant_id UUID NULL CONSTRAINT fk_notification_template_tenant_id REFERENCES tenant(id) ON DELETE CASCADE, tenant_id UUID NOT NULL,
name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
notification_type VARCHAR(50) NOT NULL, notification_type VARCHAR(50) NOT NULL,
configuration VARCHAR(10000) NOT NULL, configuration VARCHAR(10000) NOT NULL,
@ -814,7 +814,7 @@ CREATE TABLE IF NOT EXISTS notification_template (
CREATE TABLE IF NOT EXISTS notification_rule ( CREATE TABLE IF NOT EXISTS notification_rule (
id UUID NOT NULL CONSTRAINT notification_rule_pkey PRIMARY KEY, id UUID NOT NULL CONSTRAINT notification_rule_pkey PRIMARY KEY,
created_time BIGINT NOT NULL, created_time BIGINT NOT NULL,
tenant_id UUID NULL CONSTRAINT fk_notification_rule_tenant_id REFERENCES tenant(id) ON DELETE CASCADE, tenant_id UUID NOT NULL,
name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
template_id UUID NOT NULL CONSTRAINT fk_notification_rule_template_id REFERENCES notification_template(id), template_id UUID NOT NULL CONSTRAINT fk_notification_rule_template_id REFERENCES notification_template(id),
trigger_type VARCHAR(50) NOT NULL, trigger_type VARCHAR(50) NOT NULL,
@ -827,7 +827,7 @@ CREATE TABLE IF NOT EXISTS notification_rule (
CREATE TABLE IF NOT EXISTS notification_request ( CREATE TABLE IF NOT EXISTS notification_request (
id UUID NOT NULL CONSTRAINT notification_request_pkey PRIMARY KEY, id UUID NOT NULL CONSTRAINT notification_request_pkey PRIMARY KEY,
created_time BIGINT NOT NULL, created_time BIGINT NOT NULL,
tenant_id UUID NULL CONSTRAINT fk_notification_request_tenant_id REFERENCES tenant(id) ON DELETE CASCADE, tenant_id UUID NOT NULL,
targets VARCHAR(10000) NOT NULL, targets VARCHAR(10000) NOT NULL,
template_id UUID, template_id UUID,
template VARCHAR(10000), template VARCHAR(10000),

Loading…
Cancel
Save