-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
bugfix: auto delete roles relate to cluster #5395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
ecc9f87
593e7eb
0216c6d
b05d0ab
a7fff0a
47bbd8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -348,4 +348,32 @@ public void deleteRolePermissionsByAppIdAndNamespace(String appId, String namesp | |
| consumerRoleRepository.batchDeleteByRoleIds(roleIds, operator); | ||
| } | ||
| } | ||
|
|
||
| @Transactional | ||
| @Override | ||
| public void deleteRolePermissionsByCluster(String appId, String env, String clusterName, String operator) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could move the Codex-generated test to this PR. |
||
| appId = EscapeCharacter.DEFAULT.escape(appId); | ||
| List<Long> permissionIds = permissionRepository.findPermissionIdsByAppIdAndEnvAndCluster(appId, env, clusterName); | ||
| if (!permissionIds.isEmpty()) { | ||
| // 1. delete Permission | ||
| permissionRepository.batchDelete(permissionIds, operator); | ||
|
|
||
| // 2. delete Role Permission | ||
| rolePermissionRepository.batchDeleteByPermissionIds(permissionIds, operator); | ||
| } | ||
|
|
||
| List<Long> roleIds = roleRepository.findRoleIdsByCluster(appId, env, clusterName); | ||
| if (!roleIds.isEmpty()) { | ||
| // 3. delete Role | ||
| roleRepository.batchDelete(roleIds, operator); | ||
|
|
||
| // 4. delete User Role | ||
| userRoleRepository.batchDeleteByRoleIds(roleIds, operator); | ||
|
|
||
| // 5. delete Consumer Role | ||
| consumerRoleRepository.batchDeleteByRoleIds(roleIds, operator); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Fix inconsistent testing framework imports. The test class uses JUnit 4 throughout (imports on lines 19-21, Use the JUnit 4 equivalent instead: -import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.Assert.assertNull;🤖 Prompt for AI Agents |
||
|
|
||
| import com.ctrip.framework.apollo.common.entity.BaseEntity; | ||
| import com.ctrip.framework.apollo.portal.AbstractIntegrationTest; | ||
|
|
@@ -32,6 +33,7 @@ | |
| import com.ctrip.framework.apollo.portal.repository.RoleRepository; | ||
| import com.ctrip.framework.apollo.portal.repository.UserRoleRepository; | ||
| import com.ctrip.framework.apollo.portal.service.RolePermissionService; | ||
| import com.ctrip.framework.apollo.portal.util.RoleUtils; | ||
| import com.google.common.collect.Sets; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
@@ -320,6 +322,23 @@ public void testUserHasPermission() throws Exception { | |
|
|
||
| } | ||
|
|
||
| @Test | ||
| @Sql(scripts = "/sql/permission/RolePermissionServiceTest.deleteRolePermissionsByAppIdWithClusterRoles.sql", | ||
| executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) | ||
| @Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) | ||
| public void testDeleteRolePermissionsByAppIdWithClusterRoles() { | ||
| String appId = "clusterApp"; | ||
| String operator = "test"; | ||
|
|
||
| rolePermissionService.deleteRolePermissionsByAppId(appId, operator); | ||
|
|
||
| String modifyRoleName = RoleUtils.buildModifyNamespacesInClusterRoleName(appId, "DEV", "default"); | ||
| String releaseRoleName = RoleUtils.buildReleaseNamespacesInClusterRoleName(appId, "DEV", "default"); | ||
|
|
||
| assertNull(roleRepository.findTopByRoleName(modifyRoleName)); | ||
| assertNull(roleRepository.findTopByRoleName(releaseRoleName)); | ||
| } | ||
|
|
||
| private Role assembleRole(String roleName) { | ||
| Role role = new Role(); | ||
| role.setRoleName(roleName); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| -- Copyright 2025 Apollo Authors | ||
| -- | ||
| -- Licensed under the Apache License, Version 2.0 (the "License"); | ||
| -- you may not use this file except in compliance with the License. | ||
| -- You may obtain a copy of the License at | ||
| -- | ||
| -- http://www.apache.org/licenses/LICENSE-2.0 | ||
| -- | ||
| -- Unless required by applicable law or agreed to in writing, software | ||
| -- distributed under the License is distributed on an "AS IS" BASIS, | ||
| -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| -- See the License for the specific language governing permissions and | ||
| -- limitations under the License. | ||
| INSERT INTO "Permission" (`Id`, `PermissionType`, `TargetId`, `DataChange_CreatedBy`, | ||
| `DataChange_LastModifiedBy`) | ||
| VALUES (1500, 'ModifyNamespacesInCluster', 'clusterApp+DEV+default', 'someOperator', | ||
| 'someOperator'), | ||
| (1501, 'ReleaseNamespacesInCluster', 'clusterApp+DEV+default', 'someOperator', | ||
| 'someOperator'); | ||
|
|
||
| INSERT INTO "Role" (`Id`, `RoleName`, `DataChange_CreatedBy`, `DataChange_LastModifiedBy`) | ||
| VALUES (1500, 'ModifyNamespacesInCluster+clusterApp+DEV+default', 'someOperator', 'someOperator'), | ||
| (1501, 'ReleaseNamespacesInCluster+clusterApp+DEV+default', 'someOperator', 'someOperator'); | ||
|
|
||
| INSERT INTO "RolePermission" (`Id`, `RoleId`, `PermissionId`) | ||
| VALUES (1500, 1500, 1500), | ||
| (1501, 1501, 1501); |
Uh oh!
There was an error while loading. Please reload this page.