Clean up lingering code related to defaultRole field in Role entity (#7064)

This commit is contained in:
Suresh Srinivas 2022-08-30 11:25:22 -07:00 committed by GitHub
parent 704385da0a
commit 1dfcb45e86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 35 deletions

View File

@ -1826,12 +1826,6 @@ public interface CollectionDAO {
default String getNameColumn() {
return "name";
}
@SqlQuery("SELECT id FROM role_entity WHERE defaultRole = TRUE")
List<String> getDefaultRolesIds();
@SqlQuery("SELECT json FROM role_entity WHERE defaultRole = TRUE")
List<String> getDefaultRoles();
}
interface TeamDAO extends EntityDAO<Team> {
@ -1858,7 +1852,7 @@ public interface CollectionDAO {
// validate parent team
Team team = findEntityByName(parentTeam);
if (ORGANIZATION_NAME.equals(team.getName())) {
// All the parentless teams should come under "organization" team
// All the teams without parents should come under "organization" team
condition =
String.format(
"%s AND id NOT IN ( (SELECT '%s') UNION (SELECT toId FROM entity_relationship WHERE fromId!='%s' AND fromEntity='team' AND toEntity='team' AND relation=%d) )",

View File

@ -21,8 +21,6 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javax.ws.rs.core.UriInfo;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.jdbi.v3.sqlobject.transaction.Transaction;
@ -35,8 +33,6 @@ import org.openmetadata.catalog.type.EntityReference;
import org.openmetadata.catalog.type.Relationship;
import org.openmetadata.catalog.util.EntityUtil;
import org.openmetadata.catalog.util.EntityUtil.Fields;
import org.openmetadata.catalog.util.JsonUtils;
import org.openmetadata.catalog.util.ResultList;
@Slf4j
public class RoleRepository extends EntityRepository<Role> {
@ -109,25 +105,6 @@ public class RoleRepository extends EntityRepository<Role> {
}
}
public ResultList<Role> getDefaultRolesResultList(UriInfo uriInfo, Fields fields) throws IOException {
List<Role> roles = getDefaultRoles(uriInfo, fields);
return new ResultList<>(roles, null, null, roles.size());
}
private List<Role> getDefaultRoles(UriInfo uriInfo, Fields fields) throws IOException {
List<Role> roles = new ArrayList<>();
for (String roleJson : daoCollection.roleDAO().getDefaultRoles()) {
roles.add(withHref(uriInfo, setFields(JsonUtils.readValue(roleJson, Role.class), fields)));
}
if (roles.size() > 1) {
LOG.warn(
"{} roles {}, are registered as default. There SHOULD be only one role marked as default.",
roles.size(),
roles.stream().map(Role::getName).collect(Collectors.toList()));
}
return roles;
}
@Override
public RoleUpdater getUpdater(Role original, Role updated, Operation operation) {
return new RoleUpdater(original, updated, operation);

View File

@ -172,10 +172,7 @@ public class RoleResource extends EntityResource<Role, RoleRepository> {
ListFilter filter = new ListFilter(include);
ResultList<Role> roles;
if (defaultParam) {
// The number of default roles is 1, and hence does not require pagination.
roles = dao.getDefaultRolesResultList(uriInfo, fields);
} else if (before != null) { // Reverse paging
if (before != null) { // Reverse paging
roles = dao.listBefore(uriInfo, fields, filter, limitParam, before); // Ask for one extra entry
} else { // Forward paging or first page
roles = dao.listAfter(uriInfo, fields, filter, limitParam, after);

View File

@ -132,6 +132,11 @@ public class TeamResourceTest extends EntityResourceTest<Team, CreateTeam> {
CreateTeam create = createRequest("org_test").withTeamType(ORGANIZATION);
assertResponse(
() -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, CatalogExceptionMessage.createOrganization());
// Organization by default has DataConsumer Role. Ensure Role lists organization as one of the teams
RoleResourceTest roleResourceTest = new RoleResourceTest();
Role role = roleResourceTest.getEntityByName("DataConsumer", "teams", ADMIN_AUTH_HEADERS);
assertEntityReferencesContain(role.getTeams(), org.getEntityReference());
}
@Test
@ -475,7 +480,7 @@ public class TeamResourceTest extends EntityResourceTest<Team, CreateTeam> {
}
@Test
void patch_deleteUserAndDefaultRoleFromTeam_200(TestInfo test) throws IOException {
void patch_deleteUserAndDefaultRolesFromTeam_200(TestInfo test) throws IOException {
UserResourceTest userResourceTest = new UserResourceTest();
final int totalUsers = 20;
ArrayList<UUID> users = new ArrayList<>();