diff --git a/app/Services/DepartmentPermissionService.php b/app/Services/DepartmentPermissionService.php index 6eb69983..45973e45 100644 --- a/app/Services/DepartmentPermissionService.php +++ b/app/Services/DepartmentPermissionService.php @@ -350,34 +350,30 @@ public function allowAllPermissions(int $departmentId, ?int $tenantId = null, st */ public function denyAllPermissions(int $departmentId, ?int $tenantId = null, string $guardName = 'api'): void { - $query = Menu::where('is_active', 1); + // menu: 접두사를 가진 해당 가드의 모든 권한 ID 조회 + $query = DB::table('permissions') + ->where('guard_name', $guardName) + ->where('name', 'like', 'menu:%'); + if ($tenantId) { $query->where('tenant_id', $tenantId); } - $menus = $query->get(); - foreach ($menus as $menu) { - foreach ($this->permissionTypes as $type) { - $permissionName = "menu:{$menu->id}.{$type}"; - $permission = Permission::where('name', $permissionName) - ->where('guard_name', $guardName) - ->first(); + $permissionIds = $query->pluck('id'); - if ($permission) { - // Soft delete all ALLOW overrides for this department - DB::table('permission_overrides') - ->where('model_type', Department::class) - ->where('model_id', $departmentId) - ->where('permission_id', $permission->id) - ->where('tenant_id', $tenantId) - ->where('effect', 1) - ->whereNull('deleted_at') - ->update([ - 'deleted_at' => now(), - 'deleted_by' => auth()->id(), - ]); - } - } + if ($permissionIds->isNotEmpty()) { + // Soft delete all ALLOW overrides for this department + DB::table('permission_overrides') + ->where('model_type', Department::class) + ->where('model_id', $departmentId) + ->whereIn('permission_id', $permissionIds) + ->where('tenant_id', $tenantId) + ->where('effect', 1) + ->whereNull('deleted_at') + ->update([ + 'deleted_at' => now(), + 'deleted_by' => auth()->id(), + ]); } } diff --git a/resources/views/department-permissions/index.blade.php b/resources/views/department-permissions/index.blade.php index 434f5489..e8237c14 100644 --- a/resources/views/department-permissions/index.blade.php +++ b/resources/views/department-permissions/index.blade.php @@ -53,7 +53,7 @@ class="department-button px-4 py-2 text-sm font-medium rounded-lg border transit - @@ -85,10 +76,21 @@ class="px-4 py-2 bg-gray-500 text-white text-sm font-medium rounded-lg hover:bg- -