From f463cf48c048785c5d5a12ff9465b11d73617baa Mon Sep 17 00:00:00 2001 From: Vivek Ratnavel Subramanian Date: Mon, 5 Sep 2022 21:12:08 -0700 Subject: [PATCH] Fix #7187 Backend: Patching teams API for team type is not working properly (#7236) --- .../catalog/jdbi3/TeamRepository.java | 5 +++-- .../resources/teams/TeamResourceTest.java | 20 ++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TeamRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TeamRepository.java index e20943df4fa..06e47106c56 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TeamRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TeamRepository.java @@ -50,8 +50,8 @@ import org.openmetadata.catalog.util.JsonUtils; @Slf4j public class TeamRepository extends EntityRepository { - static final String TEAM_UPDATE_FIELDS = "owner,profile,users,defaultRoles,parents,children,policies"; - static final String TEAM_PATCH_FIELDS = "owner,profile,users,defaultRoles,parents,children,policies"; + static final String TEAM_UPDATE_FIELDS = "owner,profile,users,defaultRoles,parents,children,policies,teamType"; + static final String TEAM_PATCH_FIELDS = "owner,profile,users,defaultRoles,parents,children,policies,teamType"; private Team organization = null; public TeamRepository(CollectionDAO dao) { @@ -365,6 +365,7 @@ public class TeamRepository extends EntityRepository { public void entitySpecificUpdate() throws IOException { recordChange("profile", original.getProfile(), updated.getProfile()); recordChange("isJoinable", original.getIsJoinable(), updated.getIsJoinable()); + recordChange("teamType", original.getTeamType(), updated.getTeamType()); updateUsers(original, updated); updateDefaultRoles(original, updated); updateParents(original, updated); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/TeamResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/TeamResourceTest.java index 2541bba8447..0e333ae5116 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/TeamResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/TeamResourceTest.java @@ -219,9 +219,9 @@ public class TeamResourceTest extends EntityResourceTest { @Test void patch_teamAttributes_as_non_admin_403(TestInfo test) throws HttpResponseException, JsonProcessingException { - // Create table without any attributes + // Create team without any attributes Team team = createEntity(createRequest(test), ADMIN_AUTH_HEADERS); - // Patching as a non-admin should is disallowed + // Patching as a non-admin should be disallowed String originalJson = JsonUtils.pojoToJson(team); team.setDisplayName("newDisplayName"); assertResponse( @@ -230,6 +230,20 @@ public class TeamResourceTest extends EntityResourceTest { permissionNotAllowed(TEST_USER_NAME, List.of(MetadataOperation.EDIT_DISPLAY_NAME))); } + @Test + void patch_teamType_as_user_with_UpdateTeam_permission(TestInfo test) throws IOException { + Team team = createEntity(createRequest(test).withTeamType(BUSINESS_UNIT), ADMIN_AUTH_HEADERS); + String originalJson = JsonUtils.pojoToJson(team); + team.setTeamType(DIVISION); + + ChangeDescription change = getChangeDescription(team.getVersion()); + fieldUpdated(change, "teamType", BUSINESS_UNIT.toString(), DIVISION.toString()); + patchEntityAndCheck(team, originalJson, ADMIN_AUTH_HEADERS, MINOR_UPDATE, change); + + team = getEntity(team.getId(), ADMIN_AUTH_HEADERS); + assertEquals(DIVISION, team.getTeamType()); + } + @Test void patch_teamUsers_as_user_with_UpdateTeam_permission(TestInfo test) throws IOException { UserResourceTest userResourceTest = new UserResourceTest(); @@ -623,7 +637,7 @@ public class TeamResourceTest extends EntityResourceTest { @Override public CreateTeam createRequest(String name) { - return new CreateTeam().withName(name).withProfile(PROFILE); + return new CreateTeam().withName(name).withProfile(PROFILE).withTeamType(GROUP); } @Override