Skip to content

Commit

Permalink
fix lost permission when import namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
lepdou committed Sep 11, 2021
1 parent f56edfe commit b9b76fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class ConfigsImportService {
private final AppNamespaceService appNamespaceService;
private final ApplicationEventPublisher publisher;
private final UserInfoHolder userInfoHolder;
private final RoleInitializationService roleInitializationService;
private String currentUser;


Expand All @@ -78,14 +79,16 @@ public ConfigsImportService(
final @Lazy NamespaceService namespaceService,
final AppNamespaceService appNamespaceService,
final ApplicationEventPublisher publisher,
final UserInfoHolder userInfoHolder) {
final UserInfoHolder userInfoHolder,
final RoleInitializationService roleInitializationService) {
this.itemService = itemService;
this.appService = appService;
this.clusterService = clusterService;
this.namespaceService = namespaceService;
this.appNamespaceService = appNamespaceService;
this.publisher = publisher;
this.userInfoHolder = userInfoHolder;
this.roleInitializationService = roleInitializationService;
}

/**
Expand Down Expand Up @@ -360,6 +363,9 @@ private void importNamespace(final String appId, final Env env,
namespaceDTO.setDataChangeCreatedBy(currentUser);
namespaceDTO.setDataChangeLastModifiedBy(currentUser);
namespaceDTO = namespaceService.createNamespace(env, namespaceDTO);

roleInitializationService.initNamespaceRoles(appId, namespaceName, currentUser);
roleInitializationService.initNamespaceEnvRoles(appId, namespaceName, currentUser);
}

List<ItemDTO> itemDTOS = itemService.findItems(appId, env, clusterName, namespaceName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public class ConfigsExportServiceTest extends AbstractUnitTest {
private ItemService itemService;
@Mock
private ApplicationEventPublisher applicationEventPublisher;
@Mock
private RoleInitializationService roleInitializationService;
@InjectMocks
private ConfigsImportService configsImportService;

Expand All @@ -86,7 +88,7 @@ public void testNamespaceExportImport() throws FileNotFoundException {
//export config
UserInfo userInfo = genUser();
when(userInfoHolder.getUser()).thenReturn(userInfo);

Env env = Env.DEV;
String appId1 = "app1";
String appId2 = "app2";
Expand Down Expand Up @@ -182,6 +184,8 @@ public void testNamespaceExportImport() throws FileNotFoundException {
verify(clusterService, times(4)).createCluster(any(), any());

verify(namespaceService, times(6)).createNamespace(any(), any());
verify(roleInitializationService,times(6)).initNamespaceRoles(any(), any(), anyString());
verify(roleInitializationService,times(6)).initNamespaceEnvRoles(any(), any(), anyString());
verify(itemService, times(12)).createItem(any(), any(), any(), any(), any());
}

Expand Down

0 comments on commit b9b76fd

Please sign in to comment.