fix #494: add delete impact confirmations
This commit is contained in:
@@ -42,6 +42,14 @@ public class GroupService {
|
||||
|
||||
@Transactional
|
||||
public void setActive(long groupId, boolean active) {
|
||||
setActive(groupId, active, true);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void setActive(long groupId, boolean active, boolean confirmImpact) {
|
||||
if (!active && !confirmImpact) {
|
||||
throw new AppException("그룹 비활성화 전 영향 확인이 필요합니다.");
|
||||
}
|
||||
int updated = groupMapper.updateActive(groupId, active ? "Y" : "N");
|
||||
if (updated == 0) {
|
||||
throw new AppException("그룹을 찾을 수 없습니다.");
|
||||
@@ -59,6 +67,14 @@ public class GroupService {
|
||||
|
||||
@Transactional
|
||||
public void removeUser(long groupId, long userId) {
|
||||
removeUser(groupId, userId, true);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void removeUser(long groupId, long userId, boolean confirmImpact) {
|
||||
if (!confirmImpact) {
|
||||
throw new AppException("그룹 사용자 해제 전 영향 확인이 필요합니다.");
|
||||
}
|
||||
int deleted = groupMapper.deleteGroupUser(groupId, userId);
|
||||
if (deleted == 0) {
|
||||
throw new AppException("삭제할 그룹 사용자 매핑을 찾을 수 없습니다.");
|
||||
@@ -76,6 +92,14 @@ public class GroupService {
|
||||
|
||||
@Transactional
|
||||
public void removeRole(long groupId, long roleId) {
|
||||
removeRole(groupId, roleId, true);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void removeRole(long groupId, long roleId, boolean confirmImpact) {
|
||||
if (!confirmImpact) {
|
||||
throw new AppException("그룹 역할 해제 전 영향 확인이 필요합니다.");
|
||||
}
|
||||
int deleted = groupMapper.deleteGroupRole(groupId, roleId);
|
||||
if (deleted == 0) {
|
||||
throw new AppException("삭제할 그룹 역할 매핑을 찾을 수 없습니다.");
|
||||
|
||||
@@ -76,6 +76,22 @@ public class PermissionService {
|
||||
|
||||
@Transactional
|
||||
public void deleteRole(long roleId) {
|
||||
deleteRole(roleId, true);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteRole(long roleId, boolean confirmImpact) {
|
||||
if (!confirmImpact) {
|
||||
throw new AppException("역할 삭제 전 영향 확인이 필요합니다.");
|
||||
}
|
||||
int userRoleCount = permissionMapper.countUserRolesByRoleId(roleId);
|
||||
int groupRoleCount = permissionMapper.countGroupRolesByRoleId(roleId);
|
||||
int permissionCount = permissionMapper.countPermissionsByRoleId(roleId);
|
||||
if (userRoleCount + groupRoleCount + permissionCount > 0) {
|
||||
throw new AppException("연결된 사용자/그룹/권한이 있는 역할은 삭제할 수 없습니다. 사용자 역할 "
|
||||
+ userRoleCount + "건, 그룹 역할 " + groupRoleCount + "건, 권한 " + permissionCount
|
||||
+ "건을 먼저 해제하세요.");
|
||||
}
|
||||
int deleted = permissionMapper.deleteRole(roleId);
|
||||
if (deleted == 0) {
|
||||
throw new AppException("삭제할 역할을 찾을 수 없습니다.");
|
||||
@@ -133,6 +149,14 @@ public class PermissionService {
|
||||
|
||||
@Transactional
|
||||
public void deletePermission(long permissionId) {
|
||||
deletePermission(permissionId, true);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deletePermission(long permissionId, boolean confirmImpact) {
|
||||
if (!confirmImpact) {
|
||||
throw new AppException("권한 삭제 전 영향 확인이 필요합니다.");
|
||||
}
|
||||
Long objectId = permissionMapper.findObjectIdByPermissionId(permissionId);
|
||||
permissionMapper.deleteRules(permissionId);
|
||||
permissionMapper.deleteVisibleColumns(permissionId);
|
||||
@@ -147,6 +171,10 @@ public class PermissionService {
|
||||
"permissionId=" + permissionId));
|
||||
}
|
||||
|
||||
public int countPermissionsByObjectId(long objectId) {
|
||||
return permissionMapper.countPermissionsByObjectId(objectId);
|
||||
}
|
||||
|
||||
private void validateRules(long objectId, List<RuleCommand> rules) {
|
||||
if (rules == null || rules.isEmpty()) {
|
||||
throw new AppException("행 규칙은 하나 이상 필요합니다.");
|
||||
|
||||
Reference in New Issue
Block a user