Fix owner notification (#16629)

* - Fix Task notification not getting sent to owners

* - Fix Task notification not getting sent to owners
This commit is contained in:
Mohit Yadav 2024-06-12 17:40:35 +05:30 committed by GitHub
parent b7ef13bc95
commit cc2d581eb0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -154,15 +154,19 @@ public class SubscriptionUtil {
}
private static Set<String> getTaskAssignees(
SubscriptionDestination.SubscriptionType type, ChangeEvent event) {
SubscriptionDestination.SubscriptionCategory category,
SubscriptionDestination.SubscriptionType type,
ChangeEvent event) {
Thread thread = AlertsRuleEvaluator.getThread(event);
List<EntityReference> assignees = thread.getTask().getAssignees();
Set<String> receiversList = new HashSet<>();
Map<UUID, Team> teams = new HashMap<>();
Map<UUID, User> users = new HashMap<>();
Team tempTeamVar = null;
User tempUserVar = null;
if (category.equals(SubscriptionDestination.SubscriptionCategory.ASSIGNEES)) {
List<EntityReference> assignees = thread.getTask().getAssignees();
if (!nullOrEmpty(assignees)) {
for (EntityReference reference : assignees) {
if (Entity.USER.equals(reference.getType())) {
@ -189,6 +193,17 @@ public class SubscriptionUtil {
}
}
}
}
if (category.equals(SubscriptionDestination.SubscriptionCategory.OWNERS)) {
try {
tempUserVar =
Entity.getEntityByName(USER, thread.getCreatedBy(), "profile", Include.NON_DELETED);
users.put(tempUserVar.getId(), tempUserVar);
} catch (Exception ex) {
LOG.warn("Thread created by unknown user: {}", thread.getCreatedBy());
}
}
// Users
receiversList.addAll(getEmailOrWebhookEndpointForUsers(users.values().stream().toList(), type));
@ -200,7 +215,9 @@ public class SubscriptionUtil {
}
public static Set<String> handleConversationNotification(
SubscriptionDestination.SubscriptionType type, ChangeEvent event) {
SubscriptionDestination.SubscriptionCategory category,
SubscriptionDestination.SubscriptionType type,
ChangeEvent event) {
Thread thread = AlertsRuleEvaluator.getThread(event);
Set<String> receiversList = new HashSet<>();
Map<UUID, Team> teams = new HashMap<>();
@ -208,9 +225,8 @@ public class SubscriptionUtil {
Team tempTeamVar = null;
User tempUserVar = null;
tempUserVar =
Entity.getEntityByName(USER, thread.getCreatedBy(), "profile", Include.NON_DELETED);
users.put(tempUserVar.getId(), tempUserVar);
if (category.equals(SubscriptionDestination.SubscriptionCategory.MENTIONS)) {
List<MessageParser.EntityLink> mentions = MessageParser.getEntityLinks(thread.getMessage());
for (MessageParser.EntityLink link : mentions) {
if (USER.equals(link.getEntityType())) {
@ -236,6 +252,17 @@ public class SubscriptionUtil {
}
}
}
}
if (category.equals(SubscriptionDestination.SubscriptionCategory.OWNERS)) {
try {
tempUserVar =
Entity.getEntityByName(USER, thread.getCreatedBy(), "profile", Include.NON_DELETED);
users.put(tempUserVar.getId(), tempUserVar);
} catch (Exception ex) {
LOG.warn("Thread created by unknown user: {}", thread.getCreatedBy());
}
}
// Users
receiversList.addAll(getEmailOrWebhookEndpointForUsers(users.values().stream().toList(), type));
@ -340,8 +367,9 @@ public class SubscriptionUtil {
if (event.getEntityType().equals(THREAD)) {
Thread thread = AlertsRuleEvaluator.getThread(event);
switch (thread.getType()) {
case Task -> receiverUrls.addAll(getTaskAssignees(type, event));
case Conversation -> receiverUrls.addAll(handleConversationNotification(type, event));
case Task -> receiverUrls.addAll(getTaskAssignees(category, type, event));
case Conversation -> receiverUrls.addAll(
handleConversationNotification(category, type, event));
// TODO: For Announcement, Immediate Consumer needs to be Notified (find information from
// Lineage)
}