Commit 0fff85121052c4b38fe1d01cc3b0d850062b87b9
1 parent
986cfe5c
Alarm Query fix for propagated alarms with entities assigned to customer
Showing
3 changed files
with
27 additions
and
23 deletions
... | ... | @@ -130,7 +130,6 @@ public class DefaultAlarmQueryRepository implements AlarmQueryRepository { |
130 | 130 | AlarmDataPageLink pageLink = query.getPageLink(); |
131 | 131 | QueryContext ctx = new QueryContext(new QuerySecurityContext(tenantId, customerId, EntityType.ALARM)); |
132 | 132 | ctx.addUuidListParameter("entity_ids", orderedEntityIds.stream().map(EntityId::getId).collect(Collectors.toList())); |
133 | - | |
134 | 133 | StringBuilder selectPart = new StringBuilder(FIELDS_SELECTION); |
135 | 134 | StringBuilder fromPart = new StringBuilder(" from alarm a "); |
136 | 135 | StringBuilder wherePart = new StringBuilder(" where "); |
... | ... | @@ -282,24 +281,27 @@ public class DefaultAlarmQueryRepository implements AlarmQueryRepository { |
282 | 281 | StringBuilder permissionsQuery = new StringBuilder(); |
283 | 282 | ctx.addUuidParameter("permissions_tenant_id", tenantId.getId()); |
284 | 283 | permissionsQuery.append(" a.tenant_id = :permissions_tenant_id "); |
285 | - if (customerId != null && !customerId.isNullUid()) { | |
286 | - ctx.addUuidParameter("permissions_customer_id", customerId.getId()); | |
287 | - ctx.addUuidParameter("permissions_device_customer_id", customerId.getId()); | |
288 | - ctx.addUuidParameter("permissions_asset_customer_id", customerId.getId()); | |
289 | - ctx.addUuidParameter("permissions_user_customer_id", customerId.getId()); | |
290 | - ctx.addUuidParameter("permissions_entity_view_customer_id", customerId.getId()); | |
291 | - permissionsQuery.append(" and ("); | |
292 | - permissionsQuery.append("(a.originator_type = '").append(EntityType.DEVICE.ordinal()).append("' and exists (select 1 from device cd where cd.id = a.originator_id and cd.customer_id = :permissions_device_customer_id))"); | |
293 | - permissionsQuery.append(" or "); | |
294 | - permissionsQuery.append("(a.originator_type = '").append(EntityType.ASSET.ordinal()).append("' and exists (select 1 from asset ca where ca.id = a.originator_id and ca.customer_id = :permissions_device_customer_id))"); | |
295 | - permissionsQuery.append(" or "); | |
296 | - permissionsQuery.append("(a.originator_type = '").append(EntityType.CUSTOMER.ordinal()).append("' and exists (select 1 from customer cc where cc.id = a.originator_id and cc.id = :permissions_customer_id))"); | |
297 | - permissionsQuery.append(" or "); | |
298 | - permissionsQuery.append("(a.originator_type = '").append(EntityType.USER.ordinal()).append("' and exists (select 1 from tb_user cu where cu.id = a.originator_id and cu.customer_id = :permissions_user_customer_id))"); | |
299 | - permissionsQuery.append(" or "); | |
300 | - permissionsQuery.append("(a.originator_type = '").append(EntityType.ENTITY_VIEW.ordinal()).append("' and exists (select 1 from entity_view cv where cv.id = a.originator_id and cv.customer_id = :permissions_entity_view_customer_id))"); | |
301 | - permissionsQuery.append(")"); | |
302 | - } | |
284 | +/* | |
285 | + No need to check the customer id, because we already use entity id list that passed security check when we were evaluating the data query. | |
286 | + */ | |
287 | +// if (customerId != null && !customerId.isNullUid()) { | |
288 | +// ctx.addUuidParameter("permissions_customer_id", customerId.getId()); | |
289 | +// ctx.addUuidParameter("permissions_device_customer_id", customerId.getId()); | |
290 | +// ctx.addUuidParameter("permissions_asset_customer_id", customerId.getId()); | |
291 | +// ctx.addUuidParameter("permissions_user_customer_id", customerId.getId()); | |
292 | +// ctx.addUuidParameter("permissions_entity_view_customer_id", customerId.getId()); | |
293 | +// permissionsQuery.append(" and ("); | |
294 | +// permissionsQuery.append("(a.originator_type = '").append(EntityType.DEVICE.ordinal()).append("' and exists (select 1 from device cd where cd.id = a.originator_id and cd.customer_id = :permissions_device_customer_id))"); | |
295 | +// permissionsQuery.append(" or "); | |
296 | +// permissionsQuery.append("(a.originator_type = '").append(EntityType.ASSET.ordinal()).append("' and exists (select 1 from asset ca where ca.id = a.originator_id and ca.customer_id = :permissions_device_customer_id))"); | |
297 | +// permissionsQuery.append(" or "); | |
298 | +// permissionsQuery.append("(a.originator_type = '").append(EntityType.CUSTOMER.ordinal()).append("' and exists (select 1 from customer cc where cc.id = a.originator_id and cc.id = :permissions_customer_id))"); | |
299 | +// permissionsQuery.append(" or "); | |
300 | +// permissionsQuery.append("(a.originator_type = '").append(EntityType.USER.ordinal()).append("' and exists (select 1 from tb_user cu where cu.id = a.originator_id and cu.customer_id = :permissions_user_customer_id))"); | |
301 | +// permissionsQuery.append(" or "); | |
302 | +// permissionsQuery.append("(a.originator_type = '").append(EntityType.ENTITY_VIEW.ordinal()).append("' and exists (select 1 from entity_view cv where cv.id = a.originator_id and cv.customer_id = :permissions_entity_view_customer_id))"); | |
303 | +// permissionsQuery.append(")"); | |
304 | +// } | |
303 | 305 | return permissionsQuery.toString(); |
304 | 306 | } |
305 | 307 | ... | ... |
... | ... | @@ -32,9 +32,9 @@ public class DefaultQueryLogComponent implements QueryLogComponent { |
32 | 32 | |
33 | 33 | @Override |
34 | 34 | public void logQuery(QueryContext ctx, String query, long duration) { |
35 | - if (logSqlQueries && duration > logQueriesThreshold) { | |
35 | +// if (logSqlQueries && duration > logQueriesThreshold) { | |
36 | 36 | log.info("QUERY: {} took {}ms", query, duration); |
37 | 37 | Arrays.asList(ctx.getParameterNames()).forEach(param -> log.info("QUERY PARAM: {} -> {}", param, ctx.getValue(param))); |
38 | - } | |
38 | +// } | |
39 | 39 | } |
40 | 40 | } | ... | ... |
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/profile/AlarmState.java
... | ... | @@ -123,8 +123,10 @@ class AlarmState { |
123 | 123 | } |
124 | 124 | |
125 | 125 | public boolean clearAlarmState(boolean stateUpdate, AlarmRuleState state) { |
126 | - state.clear(); | |
127 | - stateUpdate |= state.checkUpdate(); | |
126 | + if (state != null) { | |
127 | + state.clear(); | |
128 | + stateUpdate |= state.checkUpdate(); | |
129 | + } | |
128 | 130 | return stateUpdate; |
129 | 131 | } |
130 | 132 | ... | ... |