[Superuser] Integrasi Pertama ke Database
This commit is contained in:
@@ -4,6 +4,9 @@ namespace App\Http\Controllers\Superuser;
|
||||
|
||||
use App\Enums\Role;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Legacy\Account;
|
||||
use App\Support\Legacy\LoginHistory;
|
||||
use App\Support\Legacy\SystemOverview;
|
||||
use App\Support\Prototype\Sample;
|
||||
use App\Support\Prototype\SuperuserData;
|
||||
use Illuminate\Contracts\View\View;
|
||||
@@ -12,7 +15,7 @@ use Illuminate\Support\Carbon;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request): View
|
||||
public function __invoke(Request $request, SystemOverview $overview, LoginHistory $history): View
|
||||
{
|
||||
$role = Role::Superuser;
|
||||
$user = $request->user()->loadMissing($role->profileRelation());
|
||||
@@ -26,6 +29,24 @@ class DashboardController extends Controller
|
||||
'Unit kerja' => $profile?->unit_kerja,
|
||||
], fn (mixed $value): bool => $value !== null));
|
||||
|
||||
// Akun DB lama: ringkasan asli akun, otoritas, dan riwayat masuk dari t_account, t_otoritasuser, dan t_historilogin.
|
||||
if ($user instanceof Account) {
|
||||
$authorities = $overview->authorities();
|
||||
$logins = $overview->logins();
|
||||
|
||||
return view('superuser.dashboard-legacy', [
|
||||
'user' => $user,
|
||||
'details' => $details,
|
||||
'accounts' => $overview->accounts(),
|
||||
'authorityLabels' => array_keys($authorities),
|
||||
'authorityData' => array_values($authorities),
|
||||
'loginLabels' => array_map(strval(...), array_keys($logins['tahun'])),
|
||||
'loginData' => array_values($logins['tahun']),
|
||||
'lastLogin' => $logins['terakhir'],
|
||||
'latest' => $history->latest(),
|
||||
]);
|
||||
}
|
||||
|
||||
$pengguna = SuperuserData::pengguna();
|
||||
$aktivitas = SuperuserData::aktivitas();
|
||||
$cadangan = SuperuserData::cadangan();
|
||||
|
||||
@@ -3,17 +3,36 @@
|
||||
namespace App\Http\Controllers\Superuser;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Legacy\Account;
|
||||
use App\Support\Legacy\AuthorityDirectory;
|
||||
use App\Support\Prototype\SuperuserData;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/** Hak akses. Akun DB lama: otoritas asli beserta menunya; akun demo: matriks prototipe. */
|
||||
class HakAksesController extends Controller
|
||||
{
|
||||
public function __invoke(): View
|
||||
public function __construct(private readonly AuthorityDirectory $authorities) {}
|
||||
|
||||
public function __invoke(Request $request): View
|
||||
{
|
||||
if ($request->user() instanceof Account) {
|
||||
return view('superuser.hak-akses.legacy', ['authorities' => $this->authorities->all()]);
|
||||
}
|
||||
|
||||
return view('superuser.hak-akses.index', [
|
||||
'roles' => SuperuserData::ROLES,
|
||||
'groups' => SuperuserData::hakAkses(),
|
||||
'kode' => SuperuserData::kodeAkses(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Request $request, int $id): View
|
||||
{
|
||||
abort_unless($request->user() instanceof Account, 404);
|
||||
$authority = $this->authorities->find($id);
|
||||
abort_if($authority === null, 404);
|
||||
|
||||
return view('superuser.hak-akses.show', ['authority' => $authority]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,15 @@
|
||||
namespace App\Http\Controllers\Superuser;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Legacy\Account;
|
||||
use App\Support\Legacy\SystemOverview;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/** Ringkasan kondisi sistem dari konfigurasi dan pemeriksaan sederhana pada server ini. */
|
||||
class KesehatanSistemController extends Controller
|
||||
{
|
||||
public function __invoke(): View
|
||||
public function __invoke(Request $request, SystemOverview $overview): View
|
||||
{
|
||||
$total = @disk_total_space(storage_path());
|
||||
$bebas = @disk_free_space(storage_path());
|
||||
@@ -31,7 +34,15 @@ class KesehatanSistemController extends Controller
|
||||
['nama' => 'Lingkungan produksi', 'ok' => app()->isProduction(), 'catatan' => 'Lingkungan saat ini: '.app()->environment().'.'],
|
||||
];
|
||||
|
||||
// Akun DB lama: koneksi ke basis data SIAKAD diperiksa langsung dan masuk hitungan kesiapan.
|
||||
$database = null;
|
||||
if ($request->user() instanceof Account) {
|
||||
$database = $overview->database();
|
||||
array_unshift($periksa, ['nama' => 'Koneksi basis data SIAKAD', 'ok' => $database['ok'], 'catatan' => $database['catatan']]);
|
||||
}
|
||||
|
||||
return view('superuser.kesehatan-sistem.index', [
|
||||
'database' => $database,
|
||||
'versi' => [
|
||||
'Laravel' => app()->version(),
|
||||
'PHP' => PHP_VERSION,
|
||||
|
||||
@@ -3,12 +3,50 @@
|
||||
namespace App\Http\Controllers\Superuser;
|
||||
|
||||
use App\Http\Controllers\Prototype\ResourceController;
|
||||
use App\Models\Legacy\Account;
|
||||
use App\Support\Legacy\LoginHistory;
|
||||
use App\Support\Prototype\SuperuserData;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/** Log aktivitas: hanya baca. */
|
||||
/**
|
||||
* Log aktivitas: hanya baca. Akun DB lama: riwayat masuk asli (t_historilogin), dicari dan disaring di server;
|
||||
* akun demo: contoh dari SuperuserData.
|
||||
*/
|
||||
class LogAktivitasController extends ResourceController
|
||||
{
|
||||
public function __construct(private readonly LoginHistory $history) {}
|
||||
|
||||
public function index(Request $request): View
|
||||
{
|
||||
if (! $this->legacy()) {
|
||||
return parent::index($request);
|
||||
}
|
||||
|
||||
$per = in_array($request->integer('per'), LoginHistory::PER_PAGE, true) ? $request->integer('per') : LoginHistory::PER_PAGE[0];
|
||||
$filter = $request->only(['q', 'dari', 'sampai']) + ['pengguna' => $request->filled('pengguna') ? $request->integer('pengguna') : null];
|
||||
|
||||
return view('crud.index', $this->share([
|
||||
'rows' => $this->history->search($filter, $per)->withQueryString(),
|
||||
'columns' => $this->columns(),
|
||||
'filters' => [
|
||||
['name' => 'dari', 'label' => 'Dari tanggal', 'type' => 'date'],
|
||||
['name' => 'sampai', 'label' => 'Sampai tanggal', 'type' => 'date'],
|
||||
// Saringan satu akun (dari detail Pengguna) tetap terbawa saat filter lain diubah.
|
||||
...($filter['pengguna'] === null ? [] : [['name' => 'pengguna', 'type' => 'hidden']]),
|
||||
],
|
||||
'searchable' => true,
|
||||
'searchPlaceholder' => 'Cari nama, NIP, atau NIM pemilik akun',
|
||||
'rowActions' => fn (array $row): array => [],
|
||||
]));
|
||||
}
|
||||
|
||||
private function legacy(): bool
|
||||
{
|
||||
return request()->user() instanceof Account;
|
||||
}
|
||||
|
||||
protected function rows(): Collection
|
||||
{
|
||||
return SuperuserData::aktivitas();
|
||||
@@ -24,7 +62,9 @@ class LogAktivitasController extends ResourceController
|
||||
return [
|
||||
'singular' => 'Aktivitas',
|
||||
'plural' => 'Log aktivitas',
|
||||
'description' => 'Jejak audit tindakan penting pengguna pada sistem, dari yang terbaru.',
|
||||
'description' => $this->legacy()
|
||||
? 'Riwayat masuk asli ke SIAKAD (waktu, komputer, alamat IP), dari yang terbaru. Sumber data hanya mencatat aktivitas masuk.'
|
||||
: 'Jejak audit tindakan penting pengguna pada sistem, dari yang terbaru.',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -55,6 +95,17 @@ class LogAktivitasController extends ResourceController
|
||||
|
||||
protected function columns(): array
|
||||
{
|
||||
if ($this->legacy()) {
|
||||
return [
|
||||
['label' => 'Waktu', 'key' => 'waktu'],
|
||||
['label' => 'Pengguna', 'key' => 'pengguna'],
|
||||
['label' => 'NIP/NIM', 'key' => 'username'],
|
||||
['label' => 'Aksi', 'key' => 'aksi', 'badge' => fn (array $r): string => 'success'],
|
||||
['label' => 'Komputer', 'key' => 'komputer'],
|
||||
['label' => 'Alamat IP', 'key' => 'ip'],
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
['label' => 'Waktu', 'key' => 'waktu'],
|
||||
['label' => 'Pengguna', 'key' => 'pengguna'],
|
||||
|
||||
@@ -3,11 +3,117 @@
|
||||
namespace App\Http\Controllers\Superuser;
|
||||
|
||||
use App\Http\Controllers\Prototype\ResourceController;
|
||||
use App\Models\Legacy\Account;
|
||||
use App\Support\Legacy\AccountDirectory;
|
||||
use App\Support\Legacy\PortalException;
|
||||
use App\Support\Prototype\SuperuserData;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Pengguna. Akun DB lama: daftar dan detail asli t_account (dicari, disaring, dipaginasi di server); yang bisa diubah hanya
|
||||
* status akun dan otoritas pegawai, tanpa menyentuh akun sendiri. Akun demo: CRUD prototipe dari SuperuserData.
|
||||
*/
|
||||
class PenggunaController extends ResourceController
|
||||
{
|
||||
public function __construct(private readonly AccountDirectory $accounts) {}
|
||||
|
||||
public function index(Request $request): View
|
||||
{
|
||||
if (! $this->legacy()) {
|
||||
return parent::index($request);
|
||||
}
|
||||
|
||||
$filter = $request->only(['q', 'jenis', 'status', 'otoritas']);
|
||||
$per = in_array($request->integer('per'), AccountDirectory::PER_PAGE, true) ? $request->integer('per') : AccountDirectory::PER_PAGE[0];
|
||||
$rows = $this->accounts->search($filter, $per)->withQueryString();
|
||||
|
||||
return view('crud.index', $this->share([
|
||||
'rows' => $rows,
|
||||
'columns' => $this->columns(),
|
||||
'filters' => [
|
||||
['name' => 'jenis', 'label' => 'Jenis akun', 'options' => AccountDirectory::JENIS],
|
||||
['name' => 'status', 'label' => 'Status', 'options' => ['aktif' => 'Aktif', 'beku' => 'Dibekukan']],
|
||||
['name' => 'otoritas', 'label' => 'Otoritas', 'options' => $this->accounts->authorities()->all()],
|
||||
],
|
||||
'searchable' => true,
|
||||
'searchPlaceholder' => 'Cari nama, NIP, atau NIM',
|
||||
'rowActions' => fn (array $row): array => $this->rowActions($row),
|
||||
]));
|
||||
}
|
||||
|
||||
public function show(string $record): View
|
||||
{
|
||||
abort_unless($this->legacy(), 404);
|
||||
$account = $this->accounts->find((int) $record);
|
||||
abort_if($account === null, 404);
|
||||
|
||||
$own = (int) request()->user()->getKey() === $account['id'];
|
||||
|
||||
return view('superuser.pengguna.show', [
|
||||
'account' => $account,
|
||||
'own' => $own,
|
||||
'authorities' => $this->accounts->authorities()->except(array_keys($account['granted']))->all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/** Bekukan atau aktifkan akun. */
|
||||
public function status(Request $request, string $record): RedirectResponse
|
||||
{
|
||||
abort_unless($this->legacy(), 404);
|
||||
$active = $request->validate(['aktif' => ['required', 'boolean']], [], ['aktif' => 'status'])['aktif'];
|
||||
|
||||
return $this->change($request, (int) $record, fn (int $id) => $this->accounts->setActive($id, (bool) $active, (string) $request->user()->username, $request->ip()), $active ? 'Akun diaktifkan kembali.' : 'Akun dibekukan.');
|
||||
}
|
||||
|
||||
public function grant(Request $request, string $record): RedirectResponse
|
||||
{
|
||||
abort_unless($this->legacy(), 404);
|
||||
$authority = $request->validate(['otoritas' => ['required', 'integer']], [], ['otoritas' => 'otoritas'])['otoritas'];
|
||||
|
||||
return $this->change($request, (int) $record, fn (int $id) => $this->accounts->grant($id, (int) $authority, (string) $request->user()->username, $request->ip()), 'Otoritas ditambahkan.');
|
||||
}
|
||||
|
||||
public function revoke(Request $request, string $record, string $otoritas): RedirectResponse
|
||||
{
|
||||
abort_unless($this->legacy(), 404);
|
||||
|
||||
return $this->change($request, (int) $record, fn (int $id) => $this->accounts->revoke($id, (int) $otoritas), 'Otoritas dicabut.');
|
||||
}
|
||||
|
||||
/** Akun sendiri tidak boleh dibekukan atau diubah otoritasnya agar Superuser tidak mengunci diri. */
|
||||
private function change(Request $request, int $id, \Closure $action, string $done): RedirectResponse
|
||||
{
|
||||
$back = redirect()->route('superuser.pengguna.show', $id);
|
||||
|
||||
if ((int) $request->user()->getKey() === $id) {
|
||||
return $back->with('error', 'Akun Anda sendiri tidak dapat diubah dari sini.');
|
||||
}
|
||||
|
||||
try {
|
||||
$action($id);
|
||||
} catch (PortalException $e) {
|
||||
return $back->with('error', $e->getMessage());
|
||||
}
|
||||
|
||||
return $back->with('status', $done);
|
||||
}
|
||||
|
||||
private function legacy(): bool
|
||||
{
|
||||
return request()->user() instanceof Account;
|
||||
}
|
||||
|
||||
/** Akun DB lama hanya bisa dilihat; pengelolaan lewat halaman detail. */
|
||||
protected function abilities(): array
|
||||
{
|
||||
return $this->legacy()
|
||||
? ['create' => false, 'show' => true, 'edit' => false, 'delete' => false]
|
||||
: parent::abilities();
|
||||
}
|
||||
|
||||
protected function rows(): Collection
|
||||
{
|
||||
return SuperuserData::pengguna();
|
||||
@@ -20,7 +126,7 @@ class PenggunaController extends ResourceController
|
||||
|
||||
protected function keyName(): string
|
||||
{
|
||||
return 'username';
|
||||
return $this->legacy() ? 'id' : 'username';
|
||||
}
|
||||
|
||||
protected function names(): array
|
||||
@@ -28,7 +134,9 @@ class PenggunaController extends ResourceController
|
||||
return [
|
||||
'singular' => 'Pengguna',
|
||||
'plural' => 'Pengguna',
|
||||
'description' => 'Kelola akun semua peran: tambah, ubah data, aktifkan atau nonaktifkan, dan atur ulang kata sandi.',
|
||||
'description' => $this->legacy()
|
||||
? 'Akun asli SIAKAD: pegawai dan mahasiswa beserta otoritasnya. Buka sebuah akun untuk membekukan atau mengaktifkannya dan mengatur otoritas pegawai; kata sandi diatur ulang lewat Atur ulang kata sandi.'
|
||||
: 'Kelola akun semua peran: tambah, ubah data, aktifkan atau nonaktifkan, dan atur ulang kata sandi.',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -47,6 +155,18 @@ class PenggunaController extends ResourceController
|
||||
|
||||
protected function columns(): array
|
||||
{
|
||||
if ($this->legacy()) {
|
||||
return [
|
||||
['label' => 'Nama', 'key' => 'nama'],
|
||||
['label' => 'NIP/NIM', 'key' => 'username'],
|
||||
['label' => 'Jenis', 'key' => 'jenis'],
|
||||
['label' => 'Otoritas', 'key' => 'otoritas'],
|
||||
['label' => 'Peran', 'key' => 'peran', 'badge' => fn (array $r): string => SuperuserData::ROLE_TONE[$r['peran']] ?? 'neutral'],
|
||||
['label' => 'Status', 'key' => 'status', 'badge' => fn (array $r): string => $r['aktif'] ? 'success' : 'danger'],
|
||||
['label' => 'Masuk terakhir', 'key' => 'terakhir'],
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
['label' => 'Nama', 'key' => 'nama'],
|
||||
['label' => 'Username', 'key' => 'username'],
|
||||
@@ -73,6 +193,10 @@ class PenggunaController extends ResourceController
|
||||
|
||||
protected function rowActions(array $row): array
|
||||
{
|
||||
return [['label' => 'Kata sandi', 'href' => route('superuser.pengguna.password', $row['username']), 'icon' => 'key']];
|
||||
$href = $this->legacy()
|
||||
? route('superuser.reset-password', ['username' => $row['username']])
|
||||
: route('superuser.pengguna.password', $row['username']);
|
||||
|
||||
return [['label' => 'Kata sandi', 'href' => $href, 'icon' => 'key']];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user