fix: [employee] 사용자-사원 삭제 동기화 수정
- destroy/bulkDelete 퇴직처리 시 user_tenants.is_active = false 추가 - update에서 employee_status 변경 시 is_active 자동 동기화 (퇴직/복직) - SwitchTenantRequest에 user_tenants.is_active 검증 추가 (비활성 테넌트 전환 차단) - tenant_access_denied i18n 메시지 추가 (ko/en)
This commit is contained in:
@@ -224,6 +224,15 @@ public function update(int $id, array $data): TenantUserProfile
|
||||
|
||||
if (! empty($profileUpdates)) {
|
||||
$profile->update($profileUpdates);
|
||||
|
||||
// 퇴직/복직 시 user_tenants.is_active 동기화
|
||||
if (isset($profileUpdates['employee_status'])) {
|
||||
$isActive = $profileUpdates['employee_status'] !== 'resigned';
|
||||
DB::table('user_tenants')
|
||||
->where('user_id', $profile->user_id)
|
||||
->where('tenant_id', $profile->tenant_id)
|
||||
->update(['is_active' => $isActive]);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. json_extra 사원 정보 업데이트
|
||||
@@ -275,6 +284,12 @@ public function destroy(int $id): array
|
||||
// 또는 employee_status를 resigned로 변경
|
||||
$profile->update(['employee_status' => 'resigned']);
|
||||
|
||||
// 해당 테넌트 접근 차단 (다른 테넌트는 영향 없음)
|
||||
DB::table('user_tenants')
|
||||
->where('user_id', $profile->user_id)
|
||||
->where('tenant_id', $tenantId)
|
||||
->update(['is_active' => false]);
|
||||
|
||||
return [
|
||||
'id' => $id,
|
||||
'deleted_at' => now()->toDateTimeString(),
|
||||
@@ -288,11 +303,25 @@ public function bulkDelete(array $ids): array
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
|
||||
// 퇴직 처리 대상의 user_id 추출
|
||||
$userIds = TenantUserProfile::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->whereIn('id', $ids)
|
||||
->pluck('user_id');
|
||||
|
||||
$updated = TenantUserProfile::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->whereIn('id', $ids)
|
||||
->update(['employee_status' => 'resigned']);
|
||||
|
||||
// 해당 테넌트 접근 일괄 차단
|
||||
if ($userIds->isNotEmpty()) {
|
||||
DB::table('user_tenants')
|
||||
->whereIn('user_id', $userIds)
|
||||
->where('tenant_id', $tenantId)
|
||||
->update(['is_active' => false]);
|
||||
}
|
||||
|
||||
return [
|
||||
'processed' => count($ids),
|
||||
'updated' => $updated,
|
||||
|
||||
Reference in New Issue
Block a user