refactor: fix 7 CRUD system inconsistencies for robustness and maintainability
- Add user-assignment dependency check to DepartmentService.deleteByUuid (409 when users assigned)
- Standardize POST detection to isMethod('POST') in 10 create/edit actions
- Align RoleService code uniqueness to warning pattern (matching departments)
- Normalize repository create() return types from mixed to int|false (3 repos + 3 interfaces)
- Add JSON response branches to 4 non-user delete actions
- Document delete authorization ordering pattern
- Decompose AdminSettingsService.updateFromAdmin into domain-scoped private methods
Workflow: .agents/runs/CRUD-CONSISTENCY-001/
Reviewed by: Code Reviewer (pass), Security Reviewer (pass), Acceptance Tester (pass)
Quality gates: QG-001 PHPUnit pass, QG-002 PHPStan pass, QG-003 Architecture pass
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -26,6 +26,7 @@ if (!$decision->isAllowed()) {
|
||||
|
||||
$errorBag = formErrors();
|
||||
$errors = [];
|
||||
$warnings = [];
|
||||
$form = [
|
||||
'description' => '',
|
||||
'code' => '',
|
||||
@@ -42,7 +43,7 @@ if ($request->isMethod('POST') && !Session::checkCsrfToken()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($request->hasBody('description')) {
|
||||
if ($request->isMethod('POST')) {
|
||||
$dbSession = app(\MintyPHP\Repository\Support\DatabaseSessionRepository::class);
|
||||
$transactionStarted = false;
|
||||
|
||||
@@ -52,6 +53,7 @@ if ($request->hasBody('description')) {
|
||||
|
||||
$result = app(\MintyPHP\Service\Access\RoleService::class)->createFromAdmin($request->bodyAll(), $currentUserId);
|
||||
$form = $result['form'] ?? $form;
|
||||
$warnings = $result['warnings'] ?? [];
|
||||
$errorBag->merge($result['errors'] ?? []);
|
||||
$selectedPermissionIds = $request->body('permission_ids', $selectedPermissionIds);
|
||||
if (!is_array($selectedPermissionIds)) {
|
||||
@@ -75,15 +77,24 @@ if ($request->hasBody('description')) {
|
||||
|
||||
$action = (string) $request->body('action', 'create');
|
||||
if ($action === 'create_close') {
|
||||
if ($warnings) {
|
||||
Flash::info(implode(' ', $warnings), $closeTarget, 'role_warning');
|
||||
}
|
||||
Flash::success('Role created', $closeTarget, 'role_created');
|
||||
Router::redirect($closeTarget);
|
||||
} else {
|
||||
$uuid = (string) ($result['uuid'] ?? '');
|
||||
if ($uuid !== '') {
|
||||
$target = requestPathWithReturnTarget("admin/roles/edit/{$uuid}", $returnTarget);
|
||||
if ($warnings) {
|
||||
Flash::info(implode(' ', $warnings), $target, 'role_warning');
|
||||
}
|
||||
Flash::success('Role created', $target, 'role_created');
|
||||
Router::redirect($target);
|
||||
} else {
|
||||
if ($warnings) {
|
||||
Flash::info(implode(' ', $warnings), $closeTarget, 'role_warning');
|
||||
}
|
||||
Flash::success('Role created', $closeTarget, 'role_created');
|
||||
Router::redirect($closeTarget);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user