[Developer] #424 hide orphan protected objects in permission picker
This commit is contained in:
@@ -29,6 +29,10 @@ public interface PermissionMapper {
|
||||
|
||||
Long findPermissionId(@Param("roleId") long roleId, @Param("objectId") long objectId);
|
||||
|
||||
Long findObjectIdByPermissionId(@Param("permissionId") long permissionId);
|
||||
|
||||
int countPermissionsByObjectId(@Param("objectId") long objectId);
|
||||
|
||||
void insertPermission(@Param("permissionId") long permissionId,
|
||||
@Param("roleId") long roleId,
|
||||
@Param("objectId") long objectId,
|
||||
|
||||
@@ -13,6 +13,8 @@ public interface ProtectedObjectMapper {
|
||||
|
||||
List<ProtectedObject> findEnabled();
|
||||
|
||||
List<ProtectedObject> findEnabledWithPermissions();
|
||||
|
||||
ProtectedObject findById(@Param("objectId") long objectId);
|
||||
|
||||
ProtectedObject findByOwnerAndName(@Param("owner") String owner, @Param("objectName") String objectName);
|
||||
|
||||
@@ -110,12 +110,16 @@ public class PermissionService {
|
||||
|
||||
@Transactional
|
||||
public void deletePermission(long permissionId) {
|
||||
Long objectId = permissionMapper.findObjectIdByPermissionId(permissionId);
|
||||
permissionMapper.deleteRules(permissionId);
|
||||
permissionMapper.deleteVisibleColumns(permissionId);
|
||||
int deleted = permissionMapper.deletePermission(permissionId);
|
||||
if (deleted == 0) {
|
||||
throw new AppException("삭제할 권한을 찾을 수 없습니다.");
|
||||
}
|
||||
if (objectId != null && permissionMapper.countPermissionsByObjectId(objectId) == 0) {
|
||||
protectedObjectService.disableObject(objectId);
|
||||
}
|
||||
auditService.record(new AuditEvent("PERMISSION_DELETED", null, null, "SUCCESS", null, null,
|
||||
"permissionId=" + permissionId));
|
||||
}
|
||||
|
||||
@@ -35,6 +35,10 @@ public class ProtectedObjectService {
|
||||
return mapper.findEnabled();
|
||||
}
|
||||
|
||||
public List<ProtectedObject> findEnabledWithPermissions() {
|
||||
return mapper.findEnabledWithPermissions();
|
||||
}
|
||||
|
||||
public List<DatabaseObjectOption> findDatabaseObjects() {
|
||||
CacheEntry<List<DatabaseObjectOption>> cached = databaseObjectsCache;
|
||||
if (cached != null && !cached.expired()) {
|
||||
@@ -83,6 +87,7 @@ public class ProtectedObjectService {
|
||||
for (String column : splitCsv(normalized.columns())) {
|
||||
mapper.insertColumn(mapper.nextColumnId(), objectId, column, sensitive.contains(column) ? "Y" : "N");
|
||||
}
|
||||
databaseObjectsCache = null;
|
||||
protectedColumnsCache.remove(objectId);
|
||||
auditService.record(new AuditEvent("PROTECTED_OBJECT_CREATED", null, objectId, "SUCCESS", null, null,
|
||||
normalized.objectName()));
|
||||
@@ -96,6 +101,8 @@ public class ProtectedObjectService {
|
||||
if (existing != null) {
|
||||
if (!existing.enabled()) {
|
||||
mapper.enableObject(existing.objectId());
|
||||
databaseObjectsCache = null;
|
||||
protectedColumnsCache.remove(existing.objectId());
|
||||
auditService.record(new AuditEvent("PROTECTED_OBJECT_RE_ENABLED", null, existing.objectId(), "SUCCESS", null,
|
||||
null, existing.displayName()));
|
||||
return mapper.findById(existing.objectId());
|
||||
@@ -119,6 +126,7 @@ public class ProtectedObjectService {
|
||||
for (String column : columns) {
|
||||
mapper.insertColumn(mapper.nextColumnId(), objectId, column, "N");
|
||||
}
|
||||
databaseObjectsCache = null;
|
||||
protectedColumnsCache.remove(objectId);
|
||||
auditService.record(new AuditEvent("PROTECTED_OBJECT_AUTO_CREATED", null, objectId, "SUCCESS", null, null,
|
||||
command.objectName()));
|
||||
@@ -162,6 +170,8 @@ public class ProtectedObjectService {
|
||||
if (updated == 0) {
|
||||
throw new AppException("보호 객체를 찾을 수 없습니다.");
|
||||
}
|
||||
databaseObjectsCache = null;
|
||||
protectedColumnsCache.remove(objectId);
|
||||
auditService.record(new AuditEvent("PROTECTED_OBJECT_DISABLED", null, objectId, "SUCCESS", null, null, null));
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ public class PermissionController {
|
||||
@GetMapping("/permissions")
|
||||
public String permissions(Model model) {
|
||||
long started = System.nanoTime();
|
||||
var objects = protectedObjectService.findEnabled();
|
||||
var objects = protectedObjectService.findEnabledWithPermissions();
|
||||
long objectsAt = System.nanoTime();
|
||||
var roles = permissionService.findRoles();
|
||||
long rolesAt = System.nanoTime();
|
||||
|
||||
Reference in New Issue
Block a user