[Operator] Pembaruan Laman Operator
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Support\Legacy\PortalException;
|
||||
use App\Support\Legacy\ReferenceData;
|
||||
use App\Support\Legacy\ReferenceWriter;
|
||||
use App\Support\Legacy\ReferenceWriters;
|
||||
use App\Support\Legacy\UnitScope;
|
||||
use App\Support\Prototype\Satu\Catalog;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -23,11 +24,12 @@ class DataPelengkapController extends Controller
|
||||
{
|
||||
use ServesLegacyList;
|
||||
|
||||
public function __construct(private readonly ReferenceData $reference) {}
|
||||
public function __construct(private readonly ReferenceData $reference, private readonly UnitScope $scope) {}
|
||||
|
||||
public function __invoke(string $slug): View
|
||||
{
|
||||
$page = Catalog::page($slug) ?? abort(404);
|
||||
$this->scopeReference();
|
||||
|
||||
if ($slug === ReferenceData::UNIVERSITY) {
|
||||
return view('operator.satu.reference-detail', [
|
||||
@@ -41,6 +43,7 @@ class DataPelengkapController extends Controller
|
||||
abort_unless(ReferenceData::isList($slug), 404);
|
||||
$definition = $this->reference->definition($slug);
|
||||
$writer = ReferenceWriters::for($slug);
|
||||
$writer?->scopeTo($this->scope->units((int) auth()->id()));
|
||||
$abilities = $writer?->abilities($slug);
|
||||
$form = $writer && ($abilities['create'] || $abilities['update']) ? $writer->form($slug) : null;
|
||||
|
||||
@@ -52,6 +55,7 @@ class DataPelengkapController extends Controller
|
||||
'url' => route('operator.pelengkap.data', $slug),
|
||||
'filters' => $definition['filters'],
|
||||
'columns' => $definition['columns'],
|
||||
'detailColumns' => $definition['detailColumns'],
|
||||
'perPage' => ReferenceData::PER_PAGE,
|
||||
'data' => $this->payload($this->decorate($writer, $slug, $this->reference->list($slug, [], ReferenceData::PER_PAGE[0]))),
|
||||
'strict' => true,
|
||||
@@ -71,6 +75,7 @@ class DataPelengkapController extends Controller
|
||||
{
|
||||
$this->legacyOnly($request);
|
||||
abort_unless(ReferenceData::isList($slug), 404);
|
||||
$this->scopeReference();
|
||||
|
||||
$filter = ['q' => $this->query($request)];
|
||||
foreach ($this->reference->definition($slug)['filters'] as $f) {
|
||||
@@ -105,6 +110,8 @@ class DataPelengkapController extends Controller
|
||||
public function update(Request $request, string $slug, int $id): JsonResponse
|
||||
{
|
||||
$writer = $this->writer($request, $slug, 'update');
|
||||
$this->scopeReference();
|
||||
abort_unless($this->reference->inScope($slug, $id), 404);
|
||||
$input = $this->input($request, $writer, $slug);
|
||||
|
||||
try {
|
||||
@@ -121,6 +128,12 @@ class DataPelengkapController extends Controller
|
||||
{
|
||||
$writer = $this->writer($request, $slug, 'delete');
|
||||
$ids = $request->validate(['ids' => ['required', 'array', 'min:1', 'max:100'], 'ids.*' => ['integer', 'distinct']], [], ['ids' => 'data'])['ids'];
|
||||
// Baris di luar unit akun (halaman bybagian) tidak boleh dihapus.
|
||||
$this->scopeReference();
|
||||
$ids = array_values(array_filter($ids, fn ($id): bool => $this->reference->inScope($slug, (int) $id)));
|
||||
if ($ids === []) {
|
||||
return response()->json(['message' => 'Data berada di luar unit Anda.'], 422);
|
||||
}
|
||||
|
||||
try {
|
||||
$deleted = $writer->delete($slug, $ids);
|
||||
@@ -132,11 +145,19 @@ class DataPelengkapController extends Controller
|
||||
}
|
||||
|
||||
/** Penulis slug ini bila akun DB lama dan kemampuan yang diminta tersedia; selain itu 404. */
|
||||
/** Batasi halaman unit (Fakultas, Prodi, Jurusan, Ruang, Gedung) ke unit akun seperti menu lama bybagian; akun pusat tanpa unit = semua. */
|
||||
private function scopeReference(): void
|
||||
{
|
||||
$this->reference->scopeTo($this->scope->units((int) auth()->id()));
|
||||
}
|
||||
|
||||
private function writer(Request $request, string $slug, string $ability): ReferenceWriter
|
||||
{
|
||||
$this->legacyOnly($request);
|
||||
$writer = ReferenceWriters::for($slug) ?? abort(404);
|
||||
abort_unless($writer->abilities($slug)[$ability], 404);
|
||||
// Pilihan dan nilai unit/gedung/fakultas/jurusan dibatasi ke unit akun (menu lama bybagian).
|
||||
$writer->scopeTo($this->scope->units((int) auth()->id()));
|
||||
|
||||
return $writer;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user