Backend: Soft deleting a user is causing the page to not load (#6207)

This commit is contained in:
Vivek Ratnavel Subramanian 2022-07-19 22:21:31 -07:00 committed by GitHub
parent 4c8cce3dac
commit 4e268f0f0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 5 deletions

View File

@ -18,6 +18,7 @@ import static org.openmetadata.catalog.Entity.PIPELINE;
import static org.openmetadata.catalog.Entity.TABLE; import static org.openmetadata.catalog.Entity.TABLE;
import static org.openmetadata.catalog.Entity.TOPIC; import static org.openmetadata.catalog.Entity.TOPIC;
import static org.openmetadata.catalog.Entity.getEntityRepository; import static org.openmetadata.catalog.Entity.getEntityRepository;
import static org.openmetadata.catalog.type.Include.ALL;
import static org.openmetadata.catalog.type.Relationship.ADDRESSED_TO; import static org.openmetadata.catalog.type.Relationship.ADDRESSED_TO;
import static org.openmetadata.catalog.type.Relationship.CREATED; import static org.openmetadata.catalog.type.Relationship.CREATED;
import static org.openmetadata.catalog.type.Relationship.IS_ABOUT; import static org.openmetadata.catalog.type.Relationship.IS_ABOUT;
@ -25,6 +26,10 @@ import static org.openmetadata.catalog.type.Relationship.REPLIED_TO;
import static org.openmetadata.catalog.util.ChangeEventParser.getPlaintextDiff; import static org.openmetadata.catalog.util.ChangeEventParser.getPlaintextDiff;
import static org.openmetadata.catalog.util.EntityUtil.compareEntityReference; import static org.openmetadata.catalog.util.EntityUtil.compareEntityReference;
import static org.openmetadata.catalog.util.EntityUtil.populateEntityReferences; import static org.openmetadata.catalog.util.EntityUtil.populateEntityReferences;
import static org.openmetadata.catalog.util.RestUtil.DELETED_TEAM_DISPLAY;
import static org.openmetadata.catalog.util.RestUtil.DELETED_TEAM_NAME;
import static org.openmetadata.catalog.util.RestUtil.DELETED_USER_DISPLAY;
import static org.openmetadata.catalog.util.RestUtil.DELETED_USER_NAME;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import io.jsonwebtoken.lang.Collections; import io.jsonwebtoken.lang.Collections;
@ -885,12 +890,26 @@ public class FeedRepository {
private Thread populateAssignees(Thread thread) { private Thread populateAssignees(Thread thread) {
if (thread.getType().equals(ThreadType.Task)) { if (thread.getType().equals(ThreadType.Task)) {
List<EntityReference> assignees = thread.getTask().getAssignees(); List<EntityReference> assignees = thread.getTask().getAssignees();
try { for (EntityReference ref : assignees) {
assignees = EntityUtil.populateEntityReferences(assignees); try {
thread.getTask().setAssignees(assignees); EntityReference ref2 = Entity.getEntityReferenceById(ref.getType(), ref.getId(), ALL);
} catch (IOException e) { EntityUtil.copy(ref2, ref);
throw new RuntimeException(e); } catch (EntityNotFoundException exception) {
// mark the not found user as deleted user since
// user will not be found in case of permanent deletion of user or team
if (ref.getType().equals(Entity.TEAM)) {
ref.setName(DELETED_TEAM_NAME);
ref.setDisplayName(DELETED_TEAM_DISPLAY);
} else {
ref.setName(DELETED_USER_NAME);
ref.setDisplayName(DELETED_USER_DISPLAY);
}
} catch (IOException ioException) {
throw new RuntimeException(ioException);
}
} }
assignees.sort(compareEntityReference);
thread.getTask().setAssignees(assignees);
} }
return thread; return thread;
} }

View File

@ -38,6 +38,10 @@ public final class RestUtil {
public static final String ENTITY_NO_CHANGE = "entityNoChange"; public static final String ENTITY_NO_CHANGE = "entityNoChange";
public static final String ENTITY_SOFT_DELETED = "entitySoftDeleted"; public static final String ENTITY_SOFT_DELETED = "entitySoftDeleted";
public static final String ENTITY_DELETED = "entityDeleted"; public static final String ENTITY_DELETED = "entityDeleted";
public static final String DELETED_USER_NAME = "DeletedUser";
public static final String DELETED_USER_DISPLAY = "User was deleted";
public static final String DELETED_TEAM_NAME = "DeletedTeam";
public static final String DELETED_TEAM_DISPLAY = "Team was deleted";
public static final String SIGNATURE_HEADER = "X-OM-Signature"; public static final String SIGNATURE_HEADER = "X-OM-Signature";
public static final DateFormat DATE_TIME_FORMAT; public static final DateFormat DATE_TIME_FORMAT;