Skip to content

Commit

Permalink
Fix the role permission deletion issue when appid contains '_'
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodyiam committed Jun 6, 2024
1 parent 39cd381 commit 1e18d54
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Apollo 2.3.0
* [apollo assembly optimization](https://github.com/apolloconfig/apollo/pull/5035)
* [update the config item table column width](https://github.com/apolloconfig/apollo/pull/5131)
* [sync apollo portal server config to apollo quick start server](https://github.com/apolloconfig/apollo/pull/5134)
* [Fix the role permission deletion issue when appid contains '_'](https://github.com/apolloconfig/apollo/pull/5150)

------------------
All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/14?closed=1)
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ public interface PermissionRepository extends PagingAndSortingRepository<Permiss
List<Permission> findByPermissionTypeInAndTargetId(Collection<String> permissionTypes,
String targetId);

@Query("SELECT p.id from Permission p where p.targetId = ?1 or p.targetId like CONCAT(?1, '+%')")
@Query("SELECT p.id from Permission p where p.targetId like ?1 or p.targetId like CONCAT(?1, '+%')")
List<Long> findPermissionIdsByAppId(String appId);

@Query("SELECT p.id from Permission p where p.targetId = CONCAT(?1, '+', ?2)")
@Query("SELECT p.id from Permission p where p.targetId like CONCAT(?1, '+', ?2) "
+ "OR p.targetId like CONCAT(?1, '+', ?2, '+%')")
List<Long> findPermissionIdsByAppIdAndNamespace(String appId, String namespaceName);

@Modifying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ public interface RoleRepository extends PagingAndSortingRepository<Role, Long> {
*/
Role findTopByRoleName(String roleName);

@Query("SELECT r.id from Role r where (r.roleName = CONCAT('Master+', ?1) "
@Query("SELECT r.id from Role r where r.roleName like CONCAT('Master+', ?1) "
+ "OR r.roleName like CONCAT('ModifyNamespace+', ?1, '+%') "
+ "OR r.roleName like CONCAT('ReleaseNamespace+', ?1, '+%') "
+ "OR r.roleName = CONCAT('ManageAppMaster+', ?1))")
+ "OR r.roleName like CONCAT('ManageAppMaster+', ?1)")
List<Long> findRoleIdsByAppId(String appId);

@Query("SELECT r.id from Role r where (r.roleName = CONCAT('ModifyNamespace+', ?1, '+', ?2) "
+ "OR r.roleName = CONCAT('ReleaseNamespace+', ?1, '+', ?2))")
@Query("SELECT r.id from Role r where r.roleName like CONCAT('ModifyNamespace+', ?1, '+', ?2) "
+ "OR r.roleName like CONCAT('ModifyNamespace+', ?1, '+', ?2, '+%') "
+ "OR r.roleName like CONCAT('ReleaseNamespace+', ?1, '+', ?2) "
+ "OR r.roleName like CONCAT('ReleaseNamespace+', ?1, '+', ?2, '+%')")
List<Long> findRoleIdsByAppIdAndNamespace(String appId, String namespaceName);

@Modifying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.google.common.collect.Sets;
import java.util.Comparator;
import java.util.LinkedHashSet;
import org.springframework.data.jpa.repository.query.EscapeCharacter;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

Expand Down Expand Up @@ -286,6 +287,7 @@ public Set<Permission> createPermissions(Set<Permission> permissions) {
@Transactional
@Override
public void deleteRolePermissionsByAppId(String appId, String operator) {
appId = EscapeCharacter.DEFAULT.escape(appId);
List<Long> permissionIds = permissionRepository.findPermissionIdsByAppId(appId);

if (!permissionIds.isEmpty()) {
Expand Down Expand Up @@ -313,6 +315,7 @@ public void deleteRolePermissionsByAppId(String appId, String operator) {
@Transactional
@Override
public void deleteRolePermissionsByAppIdAndNamespace(String appId, String namespaceName, String operator) {
appId = EscapeCharacter.DEFAULT.escape(appId);
List<Long> permissionIds = permissionRepository.findPermissionIdsByAppIdAndNamespace(appId, namespaceName);

if (!permissionIds.isEmpty()) {
Expand Down

0 comments on commit 1e18d54

Please sign in to comment.