mirror of
				https://github.com/open-metadata/OpenMetadata.git
				synced 2025-10-31 18:48:35 +00:00 
			
		
		
		
	Fix upgrade issues with new bot role feature (#8895)
This commit is contained in:
		
							parent
							
								
									fb548fc577
								
							
						
					
					
						commit
						d758a542aa
					
				| @ -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; | ||||
|   } | ||||
|  | ||||
| @ -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: | ||||
|  | ||||
| @ -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); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Suresh Srinivas
						Suresh Srinivas