66 lines
2.5 KiB
PHP
66 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Actions\TransferOwnershipAction;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Admin\TransferOwnershipRequest;
|
|
use App\Models\TranscriptionProject;
|
|
use App\Models\User;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
|
|
class ProjectMetadataController extends Controller
|
|
{
|
|
public function index(Request $request): View
|
|
{
|
|
// Admin hanya mendapat metadata — tiada transcript_text, tiada stored_audio_path
|
|
$projects = TranscriptionProject::withTrashed()
|
|
->with(['owner:id,name,email', 'projectCollaborators'])
|
|
->select([
|
|
'id', 'uuid', 'title', 'owner_user_id',
|
|
'transcription_status', 'transcription_engine',
|
|
'file_size', 'duration_seconds',
|
|
'language',
|
|
'created_at', 'deleted_at',
|
|
// Sengaja TIDAK ambil: transcript_text, stored_audio_path
|
|
])
|
|
->when($request->status, fn ($q, $s) => $q->where('transcription_status', $s))
|
|
->when($request->search, fn ($q, $s) =>
|
|
$q->where('title', 'like', "%{$s}%")
|
|
)
|
|
->when($request->owner_id, fn ($q, $id) => $q->where('owner_user_id', $id))
|
|
->orderByDesc('created_at')
|
|
->paginate(25)
|
|
->withQueryString();
|
|
|
|
$owners = User::where('role', 'user')
|
|
->where('is_active', true)
|
|
->orderBy('name')
|
|
->get(['id', 'name']);
|
|
|
|
return view('admin.projects.index', compact('projects', 'owners'));
|
|
}
|
|
|
|
public function transferOwner(
|
|
TransferOwnershipRequest $request,
|
|
TranscriptionProject $project,
|
|
TransferOwnershipAction $action
|
|
): RedirectResponse {
|
|
$this->authorize('transferOwner', $project);
|
|
|
|
$newOwner = User::findOrFail($request->new_owner_id);
|
|
|
|
// Pastikan pemilik baru adalah pengguna aktif (bukan admin)
|
|
abort_if($newOwner->isAdmin(), 403, 'Admin tidak boleh menjadi pemilik projek.');
|
|
abort_if(! $newOwner->isActive(), 422, 'Pengguna tidak aktif tidak boleh menerima pemindahan projek.');
|
|
abort_if($project->owner_user_id === $newOwner->id, 422, 'Projek sudah dimiliki oleh pengguna ini.');
|
|
|
|
$action->execute($project, $newOwner, $request->justification);
|
|
|
|
return redirect()->route('admin.projects.index')
|
|
->with('success', "Pemilikan projek \"{$project->title}\" berjaya dipindahkan kepada {$newOwner->name}.");
|
|
}
|
|
}
|