Disabled bot creating activity feeds (#21773)

* - Disabled bot creating feeds

* - nit
This commit is contained in:
Mohit Yadav 2025-06-14 19:21:00 +05:30 committed by GitHub
parent da25cd1a39
commit 5b6e25999e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 173 additions and 45 deletions

View File

@ -0,0 +1,3 @@
-- remove activity feed alert
DELETE FROM event_subscription_entity where name = 'ActivityFeedAlert';

View File

@ -0,0 +1,2 @@
-- remove activity feed alert
DELETE FROM event_subscription_entity where name = 'ActivityFeedAlert';

View File

@ -3,6 +3,7 @@ package org.openmetadata.service.events.subscription;
import static org.openmetadata.common.utils.CommonUtil.listOrEmpty;
import static org.openmetadata.common.utils.CommonUtil.nullOrEmpty;
import static org.openmetadata.schema.type.Function.ParameterType.ALL_INDEX_ELASTIC_SEARCH;
import static org.openmetadata.schema.type.Function.ParameterType.NOT_REQUIRED;
import static org.openmetadata.schema.type.Function.ParameterType.READ_FROM_PARAM_CONTEXT;
import static org.openmetadata.schema.type.Function.ParameterType.READ_FROM_PARAM_CONTEXT_PER_ENTITY;
import static org.openmetadata.schema.type.Function.ParameterType.SPECIFIC_INDEX_ELASTIC_SEARCH;
@ -340,6 +341,21 @@ public class AlertsRuleEvaluator {
return false;
}
@Function(
name = "isBot",
input = "Check if the updating user is a bot",
description = "Returns true if the change event entity is updated by a bot",
examples = {"isBot()"},
paramInputType = NOT_REQUIRED)
public boolean isBot() {
if (changeEvent == null || changeEvent.getUserName() == null) {
return false;
}
String entityUpdatedBy = changeEvent.getUserName();
User user = Entity.getEntityByName(Entity.USER, entityUpdatedBy, "id", Include.NON_DELETED);
return user.getIsBot();
}
@Function(
name = "matchIngestionPipelineState",
input = "List of comma separated ingestion pipeline states",

View File

@ -627,7 +627,7 @@ public class EventSubscriptionResource
@PathParam("alertType")
CreateEventSubscription.AlertType alertType) {
OperationContext operationContext =
new OperationContext(entityType, MetadataOperation.VIEW_ALL);
new OperationContext(entityType, MetadataOperation.VIEW_BASIC);
authorizer.authorize(securityContext, operationContext, getResourceContext());
if (alertType.equals(NOTIFICATION)) {
return new ResultList<>(EventsSubscriptionRegistry.listEntityNotificationDescriptors());

View File

@ -51,11 +51,9 @@ public class ExpressionValidator {
Set<String> allowedFunctions = new HashSet<>();
try {
// Classes that provide functions for policy expressions
List<Class<?>> evaluatorClasses =
Arrays.asList(
RuleEvaluator.class,
Class.forName("org.openmetadata.service.events.subscription.AlertsRuleEvaluator"),
Class.forName("io.collate.service.apps.bundles.onboarding.CompletionEvaluator"));
List<Class<?>> evaluatorClasses = new ArrayList<>();
evaluatorClasses.add(RuleEvaluator.class);
evaluatorClasses.addAll(getClassesAlertAndCompletion());
for (Class<?> evaluatorClass : evaluatorClasses) {
scanClassForFunctions(evaluatorClass, allowedFunctions);
@ -89,12 +87,31 @@ public class ExpressionValidator {
"matchIngestionPipelineState",
"matchPipelineState",
"matchAnyDomain",
"matchConversationUser"));
"matchConversationUser",
"isBot"));
LOG.info("Using fallback list of {} allowed functions", allowedFunctions.size());
}
return allowedFunctions;
}
private static List<Class<?>> getClassesAlertAndCompletion() {
List<Class<?>> evaluatorClasses = new ArrayList<>();
List<String> classNames =
Arrays.asList(
"org.openmetadata.service.events.subscription.AlertsRuleEvaluator",
"io.collate.service.apps.bundles.onboarding.CompletionEvaluator");
for (String className : classNames) {
try {
Class<?> clazz = Class.forName(className);
evaluatorClasses.add(clazz);
} catch (ClassNotFoundException e) {
System.err.println("Warning: Class not found - " + className);
}
}
return evaluatorClasses;
}
private static void scanClassForFunctions(Class<?> clazz, Set<String> allowedFunctions) {
try {
for (Method method : clazz.getDeclaredMethods()) {

View File

@ -37,6 +37,15 @@
"ownerNameList"
],
"inputType": "runtime"
},
{
"name": "filterByUpdaterIsBot",
"fullyQualifiedName": "eventSubscription.filterByUpdaterIsBot",
"displayName": "Update is Bot",
"description" : "Event Filtering By Updater is Bot",
"effect" : "include",
"condition": "isBot()",
"inputType": "none"
}
],
"supportedActions" : [
@ -98,6 +107,15 @@
"ownerNameList"
],
"inputType": "runtime"
},
{
"name": "filterByUpdaterIsBot",
"fullyQualifiedName": "eventSubscription.filterByUpdaterIsBot",
"displayName": "Update is Bot",
"description" : "Event Filtering By Updater is Bot",
"effect" : "include",
"condition": "isBot()",
"inputType": "none"
}
],
"supportedActions" : [
@ -150,6 +168,15 @@
"ownerNameList"
],
"inputType": "runtime"
},
{
"name": "filterByUpdaterIsBot",
"fullyQualifiedName": "eventSubscription.filterByUpdaterIsBot",
"displayName": "Update is Bot",
"description" : "Event Filtering By Updater is Bot",
"effect" : "include",
"condition": "isBot()",
"inputType": "none"
}
],
"supportedActions" : [
@ -202,6 +229,15 @@
"ownerNameList"
],
"inputType": "runtime"
},
{
"name": "filterByUpdaterIsBot",
"fullyQualifiedName": "eventSubscription.filterByUpdaterIsBot",
"displayName": "Update is Bot",
"description" : "Event Filtering By Updater is Bot",
"effect" : "include",
"condition": "isBot()",
"inputType": "none"
}
],
"supportedActions" : [
@ -257,6 +293,15 @@
"ownerNameList"
],
"inputType": "runtime"
},
{
"name": "filterByUpdaterIsBot",
"fullyQualifiedName": "eventSubscription.filterByUpdaterIsBot",
"displayName": "Update is Bot",
"description" : "Event Filtering By Updater is Bot",
"effect" : "include",
"condition": "isBot()",
"inputType": "none"
}
],
"supportedActions" : [
@ -324,6 +369,15 @@
"tableNameList"
],
"inputType": "runtime"
},
{
"name": "filterByUpdaterIsBot",
"fullyQualifiedName": "eventSubscription.filterByUpdaterIsBot",
"displayName": "Update is Bot",
"description" : "Event Filtering By Updater is Bot",
"effect" : "include",
"condition": "isBot()",
"inputType": "none"
}
],
"supportedActions" : [
@ -392,6 +446,15 @@
"domainList"
],
"inputType": "runtime"
},
{
"name": "filterByUpdaterIsBot",
"fullyQualifiedName": "eventSubscription.filterByUpdaterIsBot",
"displayName": "Update is Bot",
"description" : "Event Filtering By Updater is Bot",
"effect" : "include",
"condition": "isBot()",
"inputType": "none"
}
],
"supportedActions" : [

View File

@ -8,7 +8,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -19,7 +20,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -30,7 +32,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -41,7 +44,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -52,7 +56,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -63,7 +68,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -74,7 +80,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -85,7 +92,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -96,7 +104,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -107,7 +116,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -118,7 +128,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -129,7 +140,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -140,7 +152,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -151,7 +164,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -162,7 +176,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -173,7 +188,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -184,7 +200,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -195,7 +212,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -206,7 +224,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -217,7 +236,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -228,7 +248,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -239,7 +260,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -250,7 +272,8 @@
"filterByEventType",
"filterByUpdaterName",
"filterByDomain",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
},
{
@ -276,7 +299,8 @@
"filterByFqn",
"filterByEventType",
"filterByUpdaterName",
"filterByDomain"
"filterByDomain",
"filterByUpdaterIsBot"
]
}
]

View File

@ -115,5 +115,14 @@
"effect" : "include",
"condition": "matchAnyFieldChange({'description', 'tags'})",
"inputType": "none"
},
{
"name": "filterByUpdaterIsBot",
"fullyQualifiedName": "eventSubscription.filterByUpdaterIsBot",
"displayName": "Filter By Updater Is Bot",
"description" : "Event Filtering when Updater is a Bot",
"effect" : "include",
"condition": "isBot()",
"inputType": "none"
}
]

View File

@ -10,7 +10,7 @@
{
"name": "matchAnyEventType",
"effect": "include",
"condition": "matchAnyEventType({'entityCreated', 'entityDeleted', 'entitySoftDeleted'}) && !matchUpdatedBy({'ingestion-bot'}) && !matchAnySource({'user', 'team', 'owners', 'databaseService', 'messagingService', 'dashboardService', 'pipelineService', 'storageService', 'mlmodelService', 'metadataService', 'searchService', 'apiService', 'ingestionPipeline', 'workflow', 'testCase', 'testSuite'})",
"condition": "matchAnyEventType({'entityCreated', 'entityDeleted', 'entitySoftDeleted'}) && !isBot() && !matchAnySource({'user', 'team', 'owners', 'databaseService', 'messagingService', 'dashboardService', 'pipelineService', 'storageService', 'mlmodelService', 'metadataService', 'searchService', 'apiService', 'ingestionPipeline', 'workflow', 'testCase', 'testSuite'})",
"prefixCondition": "AND"
},
{
@ -26,9 +26,9 @@
"condition": "matchAnySource({'chart','container','dashboard','dashboardDataModel','database','databaseSchema','glossary','glossaryTerm','mlmodel','pipeline','query','report','searchIndex','storedProcedure','table','topic', 'domain', 'dataProduct', 'metric'})"
},
{
"name": "matchUpdatedBy",
"name": "isBot",
"effect": "exclude",
"condition": "matchUpdatedBy({'ingestion-bot'})",
"condition": "isBot()",
"prefixCondition": "AND"
}
]
@ -107,17 +107,9 @@
]
},
{
"name": "filterByUpdaterName",
"name": "filterByUpdaterIsBot",
"effect" : "exclude",
"prefixCondition": "AND",
"arguments": [
{
"name": "updateByUserList",
"input": [
"ingestion-bot"
]
}
]
"prefixCondition": "AND"
}
]
},

View File

@ -20,7 +20,8 @@
"filterByFieldChange",
"filterByDomain",
"filterByMentionedName",
"filterByGeneralMetadataEvents"
"filterByGeneralMetadataEvents",
"filterByUpdaterIsBot"
]
}
},

View File

@ -39,5 +39,6 @@ export enum Operation {
FilterByMentionedName = "filterByMentionedName",
FilterByOwnerName = "filterByOwnerName",
FilterBySource = "filterBySource",
FilterByUpdaterIsBot = "filterByUpdaterIsBot",
FilterByUpdaterName = "filterByUpdaterName",
}