Fix upgrade issues with new bot role feature (#8895)

This commit is contained in:
Suresh Srinivas 2022-11-18 11:32:26 -08:00 committed by GitHub
parent fb548fc577
commit d758a542aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View File

@ -89,6 +89,9 @@ public class UserRepository extends EntityRepository<User> {
}
private List<EntityReference> getInheritedRoles(User user) throws IOException {
if (Boolean.TRUE.equals(user.getIsBot())) {
return null; // No inherited roles for bots
}
getTeams(user);
return SubjectCache.getInstance() != null ? SubjectCache.getInstance().getRolesForTeams(getTeams(user)) : null;
}

View File

@ -53,6 +53,7 @@ import org.openmetadata.schema.api.data.RestoreEntity;
import org.openmetadata.schema.entity.Bot;
import org.openmetadata.schema.entity.teams.User;
import org.openmetadata.schema.type.EntityHistory;
import org.openmetadata.schema.type.EntityReference;
import org.openmetadata.schema.type.Include;
import org.openmetadata.schema.type.Relationship;
import org.openmetadata.service.Entity;
@ -68,6 +69,7 @@ import org.openmetadata.service.security.Authorizer;
import org.openmetadata.service.security.DefaultAuthorizer;
import org.openmetadata.service.security.SecurityUtil;
import org.openmetadata.service.util.EntityUtil;
import org.openmetadata.service.util.EntityUtil.Fields;
import org.openmetadata.service.util.ResultList;
@Slf4j
@ -104,6 +106,21 @@ public class BotResource extends EntityResource<Bot, BotRepository> {
}
}
@Override
protected void upgrade() throws IOException {
// This should be deleted once 0.13 is deprecated
// For all the existing bots, add ingestion bot role
ResultList<Bot> bots = dao.listAfter(null, Fields.EMPTY_FIELDS, new ListFilter(Include.NON_DELETED), 1000, null);
EntityReference ingestionBotRole = RoleResource.getRole(Entity.INGESTION_BOT_ROLE);
for (Bot bot : bots.getData()) {
User botUser = Entity.getEntity(bot.getBotUser(), "roles", Include.NON_DELETED);
if (botUser.getRoles() == null) {
botUser.setRoles(List.of(ingestionBotRole));
dao.addRelationship(botUser.getId(), ingestionBotRole.getId(), Entity.USER, Entity.ROLE, Relationship.HAS);
}
}
}
private static String getRoleForBot(String botName) {
switch (botName) {
case Entity.INGESTION_BOT_NAME:

View File

@ -94,6 +94,7 @@ public class RoleResource extends EntityResource<Role, RoleRepository> {
public void initialize(OpenMetadataApplicationConfig config) throws IOException {
List<Role> roles = dao.getEntitiesFromSeedData();
for (Role role : roles) {
role.setFullyQualifiedName(role.getName());
List<EntityReference> policies = role.getPolicies();
for (EntityReference policy : policies) {
EntityReference ref = Entity.getEntityReferenceByName(Entity.POLICY, policy.getName(), Include.NON_DELETED);