Files
sam-manage/app/Models/Admin/AdminApiFlow.php
kent 1cbaf1b873 refactor(dev-tools): 인증 시스템 통합 및 테넌트 사용자 조회 개선
## 인증 모달 통합
- api-explorer, flow-tester, api-logs 3개 페이지의 인증 UI 통합
- 공유 컴포넌트 생성: auth-modal.blade.php, auth-scripts.blade.php
- sessionStorage 기반으로 페이지 간 인증 상태 공유
- DevToolsAuth 글로벌 JavaScript API 제공

## 테넌트 사용자 조회 개선
- 시스템 헤더에서 선택한 테넌트의 사용자 목록 표시
- 관리자가 모든 테넌트의 사용자 조회 가능 (소속 무관)
- session('selected_tenant_id')로 Tenant 모델 직접 조회
- 테넌트 미선택 시 안내 메시지 표시

## 버그 수정
- /users 페이지 HTMX swap 오류 수정 (JSON→HTML 직접 반환)
- 사용자 이름 JavaScript 이스케이프 처리 (@js() 사용)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-21 15:13:01 +09:00

115 lines
2.6 KiB
PHP

<?php
namespace App\Models\Admin;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
/**
* API Flow Tester - 플로우 정의 모델
*
* @property int $id
* @property string $name
* @property string|null $description
* @property string|null $category
* @property array $flow_definition
* @property bool $is_active
* @property int|null $created_by
* @property int|null $updated_by
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
*/
class AdminApiFlow extends Model
{
protected $table = 'admin_api_flows';
protected $fillable = [
'name',
'description',
'category',
'flow_definition',
'is_active',
'created_by',
'updated_by',
];
protected $casts = [
'flow_definition' => 'array',
'is_active' => 'boolean',
'created_by' => 'integer',
'updated_by' => 'integer',
];
/**
* 활성화된 플로우만 조회
*/
public function scopeActive($query)
{
return $query->where('is_active', true);
}
/**
* 카테고리로 필터링
*/
public function scopeCategory($query, string $category)
{
return $query->where('category', $category);
}
/**
* 관계: 실행 이력
*/
public function runs(): HasMany
{
return $this->hasMany(AdminApiFlowRun::class, 'flow_id');
}
/**
* 관계: 생성자
*/
public function creator(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by');
}
/**
* 관계: 수정자
*/
public function updater(): BelongsTo
{
return $this->belongsTo(User::class, 'updated_by');
}
/**
* 관계: 최신 실행 기록 (서브쿼리 방식 - window function 회피)
*/
public function latestRun(): HasOne
{
return $this->hasOne(AdminApiFlowRun::class, 'flow_id')
->whereIn('id', function ($query) {
$query->selectRaw('MAX(id)')
->from('admin_api_flow_runs')
->groupBy('flow_id');
});
}
/**
* 최근 실행 결과 조회 (단일 조회용)
*/
public function getLatestRunResult(): ?AdminApiFlowRun
{
return $this->runs()->latest('created_at')->first();
}
/**
* 플로우 정의에서 스텝 수 반환
*/
public function getStepCountAttribute(): int
{
return count($this->flow_definition['steps'] ?? []);
}
}