feat(mng): 사용자 역할/부서 매핑 및 부서관리 복구/영구삭제 기능 추가
사용자 관리: - 사용자 등록/수정 시 테넌트별 역할/부서 선택 기능 추가 - Department, UserRole, DepartmentUser 모델 추가 - User 모델에 역할/부서 관계 및 헬퍼 메서드 추가 - syncRoles/syncDepartments 메서드 (forceDelete로 유니크 키 충돌 방지) - 체크박스 UI로 다중 선택 지원 부서 관리: - Soft Delete 필터 (정상만/전체/삭제된 항목만) - 복구(restore) 및 영구삭제(forceDelete) 기능 추가 - Department 모델에 SoftDeletes 트레이트 추가 - 삭제된 항목 빨간 배경 + "삭제됨" 배지 표시
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
@@ -86,4 +87,44 @@ public function currentTenant()
|
||||
|
||||
return $this->tenants()->find($tenantId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 관계: 사용자-역할 (user_roles 테이블, 테넌트별)
|
||||
*/
|
||||
public function userRoles(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserRole::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 관계: 사용자-부서 (department_user 테이블, 테넌트별)
|
||||
*/
|
||||
public function departmentUsers(): HasMany
|
||||
{
|
||||
return $this->hasMany(DepartmentUser::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 테넌트의 역할 목록 조회
|
||||
*/
|
||||
public function getRolesForTenant(int $tenantId)
|
||||
{
|
||||
return $this->userRoles()
|
||||
->where('tenant_id', $tenantId)
|
||||
->with('role')
|
||||
->get()
|
||||
->pluck('role');
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 테넌트의 부서 목록 조회
|
||||
*/
|
||||
public function getDepartmentsForTenant(int $tenantId)
|
||||
{
|
||||
return $this->departmentUsers()
|
||||
->where('tenant_id', $tenantId)
|
||||
->with('department')
|
||||
->get()
|
||||
->pluck('department');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user