diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/exception/CatalogExceptionMessage.java b/openmetadata-service/src/main/java/org/openmetadata/service/exception/CatalogExceptionMessage.java index 757dea0eb26..66fda534714 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/exception/CatalogExceptionMessage.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/exception/CatalogExceptionMessage.java @@ -188,6 +188,10 @@ public final class CatalogExceptionMessage { return String.format("Team of type %s can't own entities. Only Team of type Group can own entities.", teamType); } + public static String invalidOwnerType(String entityType) { + return String.format("Entity of type %s can't be the owner. Only Team of type Group or a User can own entities.", entityType); + } + public static String failedToParse(String message) { return String.format("Failed to parse - %s", message); } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java index c212698e130..f6d2a466aa8 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java @@ -639,6 +639,7 @@ public abstract class EntityRepository { prepare(entity, update); setFullyQualifiedName(entity); validateExtension(entity); + validateOwner(entity.getOwner()); // Domain is already validated } @@ -1579,6 +1580,7 @@ public abstract class EntityRepository { public void updateOwner(T ownedEntity, EntityReference originalOwner, EntityReference newOwner) { // TODO inefficient use replace instead of delete and add and check for orig and new owners being the same + validateOwner(newOwner); removeOwner(ownedEntity, originalOwner); storeOwner(ownedEntity, newOwner); } @@ -1638,8 +1640,9 @@ public abstract class EntityRepository { if (owner == null) { return null; } - // Entities can be only owned by team of type 'group' - if (owner.getType().equals(Entity.TEAM)) { + if (!owner.getType().equals(Entity.TEAM) && !owner.getType().equals(USER)) { + throw new IllegalArgumentException(CatalogExceptionMessage.invalidOwnerType(owner.getType())); + } else if (owner.getType().equals(Entity.TEAM)) { // Entities can be only owned by team of type 'group' Team team = Entity.getEntity(Entity.TEAM, owner.getId(), "", ALL); if (!team.getTeamType().equals(CreateTeam.TeamType.GROUP)) { throw new IllegalArgumentException(CatalogExceptionMessage.invalidTeamOwner(team.getTeamType())); diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/EntityResourceTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/EntityResourceTest.java index 3ceba7a059a..a2ff1c1c129 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/EntityResourceTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/EntityResourceTest.java @@ -1164,6 +1164,16 @@ public abstract class EntityResourceTest patchEntity(newEntity.getId(), newJson, newEntity, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "Entity of type testDefinition can't be the owner. Only Team of type Group or a User can own entities."); } @Test