update rm deadcode

This commit is contained in:
baodev0
2026-09-27 11:42:40 +07:00
parent 82a71244ca
commit 3af59bd9c5
129 changed files with 5194 additions and 2698 deletions
@@ -92,6 +92,11 @@ class EmployeeController extends Controller
$request->validated();
$guardError = $this->guardEmployeeMutation($employee, $request->role);
if ($guardError) {
return $guardError;
}
try {
DB::beginTransaction();
@@ -138,6 +143,14 @@ class EmployeeController extends Controller
], 404);
}
$currentUser = auth('admin')->user();
if ($employee->hasRole('Full Administrator') && !$currentUser->hasRole('Full Administrator')) {
return response()->json([
'error' => true,
'message' => 'Bạn không có quyền xoá tài khoản Full Administrator.',
], 403);
}
try {
DB::beginTransaction();
$this->employeeRepository->delete($id);
@@ -156,6 +169,34 @@ class EmployeeController extends Controller
}
}
private function guardEmployeeMutation($employee, string $requestedRole): ?JsonResponse
{
$currentUser = auth('admin')->user();
if ($employee->hasRole('Full Administrator') && !$currentUser->hasRole('Full Administrator')) {
return response()->json([
'error' => true,
'message' => 'Bạn không có quyền sửa tài khoản Full Administrator.',
], 403);
}
if ($employee->id === $currentUser->id && !$currentUser->hasRole($requestedRole)) {
return response()->json([
'error' => true,
'message' => 'Bạn không thể tự đổi vai trò của chính mình.',
], 403);
}
if (in_array($requestedRole, ['Administrator', 'Full Administrator'], true) && !$currentUser->hasRole('Full Administrator')) {
return response()->json([
'error' => true,
'message' => 'Chỉ Full Administrator mới có quyền gán vai trò này.',
], 403);
}
return null;
}
public function roles(): JsonResponse
{
$roles = Role::where('guard_name', 'admin')->get(['id', 'name']);