Fix #16102 : Ensure adding reviewer also adds them as an assignee to the task (#16248)

This commit is contained in:
sonika-shah 2024-05-14 16:32:22 +05:30 committed by GitHub
parent e1bfdf5ae7
commit becdd38cae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 56 additions and 1 deletions

View File

@ -2461,7 +2461,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
updated.setExperts(updatedExperts);
}
private void updateReviewers() {
protected void updateReviewers() {
if (!supportsReviewers) {
return;
}

View File

@ -90,6 +90,7 @@ import org.openmetadata.service.util.EntityUtil;
import org.openmetadata.service.util.EntityUtil.Fields;
import org.openmetadata.service.util.FullyQualifiedName;
import org.openmetadata.service.util.JsonUtils;
import org.openmetadata.service.util.RestUtil;
import org.openmetadata.service.util.WebsocketNotificationHandler;
@Slf4j
@ -777,6 +778,33 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
super(original, updated, operation);
}
@Override
public void updateReviewers() {
super.updateReviewers();
// adding the reviewer should add the person as assignee to the task
if (updated.getStatus() == Status.DRAFT) {
EntityLink about = new EntityLink(GLOSSARY_TERM, updated.getFullyQualifiedName());
FeedRepository feedRepository = Entity.getFeedRepository();
Thread originalTask = feedRepository.getTask(about, TaskType.RequestApproval);
if (TaskStatus.Open.equals(originalTask.getTask().getStatus())) {
Thread updatedTask = JsonUtils.deepCopy(originalTask, Thread.class);
updatedTask.getTask().withAssignees(updated.getReviewers());
JsonPatch patch = JsonUtils.getJsonPatch(originalTask, updatedTask);
RestUtil.PatchResponse<Thread> thread =
feedRepository.patchThread(
null, originalTask.getId(), updatedTask.getUpdatedBy(), patch);
// Send WebSocket Notification
WebsocketNotificationHandler.handleTaskNotification(thread.entity());
}
}
}
@Transaction
@Override
public void entitySpecificUpdate() {

View File

@ -283,6 +283,7 @@ public abstract class EntityResourceTest<T extends EntityInterface, K extends Cr
public static Role DATA_STEWARD_ROLE;
public static EntityReference DATA_STEWARD_ROLE_REF;
public static User DATA_CONSUMER;
public static EntityReference DATA_CONSUMER_REF;
public static Role DATA_CONSUMER_ROLE;
public static EntityReference DATA_CONSUMER_ROLE_REF;
public static Role ROLE1;

View File

@ -436,6 +436,31 @@ public class GlossaryTermResourceTest extends EntityResourceTest<GlossaryTerm, C
GlossaryTerm g2t4Updated = patchEntity(g2t4.getId(), json2, g2t4, authHeaders(USER1.getName()));
assertEquals(Status.REJECTED, g2t4Updated.getStatus());
assertApprovalTask(g2t4, TaskStatus.Closed); // The Request Approval task is closed
// Creating a glossary term g2t5 should be in `Draft` mode (because glossary has reviewers)
// adding a new reviewer should add the person as assignee to the task
GlossaryTerm g2t5 = createTerm(glossary2, null, "g2t5");
assertEquals(Status.DRAFT, g2t5.getStatus());
assertApprovalTask(g2t5, TaskStatus.Open); // A Request Approval task is opened
String origJson = JsonUtils.pojoToJson(g2t5);
// Add reviewer DATA_CONSUMER in PATCH request
g2t5.withReviewers(List.of(DATA_CONSUMER_REF, USER1_REF, USER2_REF));
ChangeDescription change = getChangeDescription(g2t5, MINOR_UPDATE);
fieldAdded(change, "reviewers", List.of(DATA_CONSUMER_REF));
g2t5 = patchEntityUsingFqnAndCheck(g2t5, origJson, ADMIN_AUTH_HEADERS, MINOR_UPDATE, change);
Thread approvalTask1 =
assertApprovalTask(g2t5, TaskStatus.Open); // A Request Approval task is opened
// adding the reviewer should add the person as assignee to the task
assertTrue(
approvalTask1.getTask().getAssignees().stream()
.anyMatch(assignee -> assignee.getId().equals(DATA_CONSUMER_REF.getId())),
"The list of assignees does not contain the expected ID: " + DATA_CONSUMER_REF.getId());
}
@Test

View File

@ -170,6 +170,7 @@ public class UserResourceTest extends EntityResourceTest<User, CreateUser> {
createRequest("user-data-consumer", "", "", null)
.withRoles(List.of(DATA_CONSUMER_ROLE.getId()));
DATA_CONSUMER = createEntity(create, ADMIN_AUTH_HEADERS);
DATA_CONSUMER_REF = DATA_CONSUMER.getEntityReference();
// USER_TEAM21 is part of TEAM21
create = createRequest(test, 2).withTeams(List.of(TEAM21.getId()));