fix:부서 권한 관리 전체 거부 버튼 제거 + 초기화 deny-all로 변경 + 로딩 오버레이 추가

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
김보곤
2026-02-20 09:47:00 +09:00
parent 55a0ac2a44
commit 14b4f5c98e
2 changed files with 46 additions and 36 deletions

View File

@@ -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(),
]);
}
}

View File

@@ -53,7 +53,7 @@ class="department-button px-4 py-2 text-sm font-medium rounded-lg border transit
<button
type="button"
class="px-4 py-2 bg-green-600 text-white text-sm font-medium rounded-lg hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-500"
class="bulk-action-btn px-4 py-2 bg-green-600 text-white text-sm font-medium rounded-lg hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-500"
hx-post="/api/admin/department-permissions/allow-all"
hx-target="#permission-matrix"
hx-include="[name='department_id'],[name='guard_name']"
@@ -62,20 +62,11 @@ class="px-4 py-2 bg-green-600 text-white text-sm font-medium rounded-lg hover:bg
</button>
<button
type="button"
class="px-4 py-2 bg-red-600 text-white text-sm font-medium rounded-lg hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-red-500"
class="bulk-action-btn px-4 py-2 bg-gray-500 text-white text-sm font-medium rounded-lg hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-gray-400"
hx-post="/api/admin/department-permissions/deny-all"
hx-target="#permission-matrix"
hx-include="[name='department_id'],[name='guard_name']"
>
전체 거부
</button>
<button
type="button"
class="px-4 py-2 bg-gray-500 text-white text-sm font-medium rounded-lg hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-gray-400"
hx-post="/api/admin/department-permissions/reset"
hx-target="#permission-matrix"
hx-include="[name='department_id'],[name='guard_name']"
title="모든 메뉴의 조회(view) 권한만 허용"
title="모든 권한 체크 해제"
>
초기화
</button>
@@ -85,10 +76,21 @@ class="px-4 py-2 bg-gray-500 text-white text-sm font-medium rounded-lg hover:bg-
</div>
<!-- 권한 매트릭스 테이블 -->
<div id="permission-matrix" class="bg-white rounded-lg shadow-sm">
<div id="permission-matrix" class="bg-white rounded-lg shadow-sm relative">
@include('department-permissions.partials.empty-state')
</div>
<!-- 로딩 오버레이 -->
<div id="permission-loading" class="hidden fixed inset-0 z-50 flex items-center justify-center bg-black/30">
<div class="bg-white rounded-xl shadow-lg px-8 py-6 flex items-center gap-4">
<svg class="animate-spin h-6 w-6 text-blue-600" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
<span class="text-gray-700 font-medium text-sm">권한을 변경하고 있습니다...</span>
</div>
</div>
<script>
function selectDepartment(button) {
// 모든 버튼의 활성 상태 제거
@@ -114,6 +116,18 @@ function selectDepartment(button) {
document.getElementById('action-buttons').style.display = 'block';
}
// 벌크 액션 버튼 로딩 오버레이
document.addEventListener('htmx:beforeRequest', function(e) {
if (e.detail.elt.classList.contains('bulk-action-btn')) {
document.getElementById('permission-loading').classList.remove('hidden');
}
});
document.addEventListener('htmx:afterRequest', function(e) {
if (e.detail.elt.classList.contains('bulk-action-btn')) {
document.getElementById('permission-loading').classList.add('hidden');
}
});
// 페이지 로드 시 첫 번째 부서 자동 선택 (특정 테넌트 선택 시에만)
document.addEventListener('DOMContentLoaded', function() {
const autoSelectButton = document.querySelector('.department-button[data-auto-select="true"]');