Skip to content
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

Fix the role permission deletion issue when appid contains '_' #5150

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
nobodyiam marked this conversation as resolved.
Show resolved Hide resolved

------------------
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
Loading