DONE: feature flags by branches
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class AdminFeatureController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware(['auth', 'admin']);
|
||||
}
|
||||
|
||||
protected function api()
|
||||
{
|
||||
return Http::withOptions(['verify' => config('app.api_verify')]);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$api_url = config('api.url');
|
||||
|
||||
$metaRes = $this->api()->get($api_url . '/api/features');
|
||||
$meta = $metaRes->successful() ? $metaRes->json() : [];
|
||||
$keys = is_array($meta) && !empty($meta['keys']) ? $meta['keys'] : ['pembiayaan_online'];
|
||||
$labels = is_array($meta) && !empty($meta['labels']) ? $meta['labels'] : [
|
||||
'pembiayaan_online' => 'Pembiayaan Online',
|
||||
];
|
||||
|
||||
$listRes = $this->api()->get($api_url . '/api/features/cawangan');
|
||||
$cawangan = ($listRes->successful() && is_array($listRes->json())) ? $listRes->json() : [];
|
||||
|
||||
if (!$listRes->successful()) {
|
||||
session()->now('error', 'Gagal muat senarai ciri cawangan.');
|
||||
}
|
||||
|
||||
return view('admin.features', compact('api_url', 'keys', 'labels', 'cawangan'));
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
$kodcaw = trim((string) $request->input('kodcaw', ''));
|
||||
$feature = trim((string) $request->input('feature', ''));
|
||||
$enabled = (int) $request->input('enabled') ? 1 : 0;
|
||||
|
||||
if ($kodcaw === '' || $feature === '') {
|
||||
return redirect()->route('admin.features')->with('error', 'Kod cawangan dan ciri diperlukan.');
|
||||
}
|
||||
|
||||
$res = $this->api()
|
||||
->put(config('api.url') . '/api/features/' . $kodcaw . '/' . $feature, [
|
||||
'enabled' => $enabled,
|
||||
]);
|
||||
|
||||
if (!$res->successful()) {
|
||||
$body = $res->json();
|
||||
$msg = is_array($body) && isset($body['message'])
|
||||
? $body['message']
|
||||
: 'Gagal kemaskini ciri cawangan.';
|
||||
return redirect()->route('admin.features')->with('error', $msg);
|
||||
}
|
||||
|
||||
$label = $enabled ? 'diaktifkan' : 'dinyahaktifkan';
|
||||
return redirect()
|
||||
->route('admin.features')
|
||||
->with('message', $feature . ' ' . $label . ' untuk ' . $kodcaw . '.');
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,16 @@ class GadaianController extends Controller
|
||||
$this->AliranTunaiController = new AliranTunaiController();
|
||||
}
|
||||
|
||||
protected function isPembiayaanOnlineEnabled($kodcaw)
|
||||
{
|
||||
$cawangan_info = Http::withOptions(['verify' => config('app.api_verify')])
|
||||
->get(config('api.url') . '/api/cawangan/' . $kodcaw)
|
||||
->json();
|
||||
$features = is_array($cawangan_info) ? ($cawangan_info['features'] ?? []) : [];
|
||||
|
||||
return !empty($features['pembiayaan_online']);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
|
||||
@@ -219,6 +229,10 @@ class GadaianController extends Controller
|
||||
$caraTerima = 'TUNAI';
|
||||
}
|
||||
|
||||
if ($caraTerima === 'ONLINE' && !$this->isPembiayaanOnlineEnabled($auth_user['cawangan'])) {
|
||||
$caraTerima = 'TUNAI';
|
||||
}
|
||||
|
||||
if ($caraTerima === 'ONLINE') {
|
||||
$online = Http::withOptions(['verify' => config('app.api_verify')])
|
||||
->asForm()
|
||||
|
||||
@@ -24,6 +24,30 @@ class PembiayaanOnlineController extends Controller
|
||||
return Auth::user()->cawangan;
|
||||
}
|
||||
|
||||
protected function cawanganInfo()
|
||||
{
|
||||
return $this->api()
|
||||
->get(config('api.url') . '/api/cawangan/' . $this->kodcaw())
|
||||
->json();
|
||||
}
|
||||
|
||||
protected function isPembiayaanOnlineEnabled($cawangan_info = null)
|
||||
{
|
||||
if (!is_array($cawangan_info)) {
|
||||
$cawangan_info = $this->cawanganInfo();
|
||||
}
|
||||
$features = $cawangan_info['features'] ?? [];
|
||||
|
||||
return !empty($features['pembiayaan_online']);
|
||||
}
|
||||
|
||||
protected function abortUnlessPembiayaanOnline($cawangan_info = null)
|
||||
{
|
||||
if (!$this->isPembiayaanOnlineEnabled($cawangan_info)) {
|
||||
abort(403, 'Pembiayaan online tidak diaktifkan untuk cawangan ini.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PC senarai queue + batch history.
|
||||
*/
|
||||
@@ -33,9 +57,8 @@ class PembiayaanOnlineController extends Controller
|
||||
$kodcaw = $this->kodcaw();
|
||||
$api_url = config('api.url');
|
||||
|
||||
$cawangan_info = $this->api()
|
||||
->get($api_url . '/api/cawangan/' . $kodcaw)
|
||||
->json();
|
||||
$cawangan_info = $this->cawanganInfo();
|
||||
$this->abortUnlessPembiayaanOnline($cawangan_info);
|
||||
|
||||
$queue = $this->api()
|
||||
->get($api_url . '/api/pembiayaan-online/' . $kodcaw . '/queue')
|
||||
@@ -79,6 +102,7 @@ class PembiayaanOnlineController extends Controller
|
||||
*/
|
||||
public function updateLine(Request $request, $id)
|
||||
{
|
||||
$this->abortUnlessPembiayaanOnline();
|
||||
$kodcaw = $this->kodcaw();
|
||||
$api_url = config('api.url');
|
||||
|
||||
@@ -109,6 +133,7 @@ class PembiayaanOnlineController extends Controller
|
||||
*/
|
||||
public function submitBatch(Request $request)
|
||||
{
|
||||
$this->abortUnlessPembiayaanOnline();
|
||||
$kodcaw = $this->kodcaw();
|
||||
$api_url = config('api.url');
|
||||
$auth_user = Auth::user();
|
||||
@@ -150,9 +175,8 @@ class PembiayaanOnlineController extends Controller
|
||||
$kodcaw = $this->kodcaw();
|
||||
$api_url = config('api.url');
|
||||
|
||||
$cawangan_info = $this->api()
|
||||
->get($api_url . '/api/cawangan/' . $kodcaw)
|
||||
->json();
|
||||
$cawangan_info = $this->cawanganInfo();
|
||||
$this->abortUnlessPembiayaanOnline($cawangan_info);
|
||||
|
||||
$detail = $this->api()
|
||||
->get($api_url . '/api/pembiayaan-online/' . $kodcaw . '/batches/' . $batchId)
|
||||
@@ -181,9 +205,8 @@ class PembiayaanOnlineController extends Controller
|
||||
$api_url = config('api.url');
|
||||
$blastFilter = $request->input('blast_sent', '0');
|
||||
|
||||
$cawangan_info = $this->api()
|
||||
->get($api_url . '/api/cawangan/' . $kodcaw)
|
||||
->json();
|
||||
$cawangan_info = $this->cawanganInfo();
|
||||
$this->abortUnlessPembiayaanOnline($cawangan_info);
|
||||
|
||||
$query = [];
|
||||
if ($blastFilter !== 'all' && $blastFilter !== '') {
|
||||
@@ -219,6 +242,7 @@ class PembiayaanOnlineController extends Controller
|
||||
*/
|
||||
public function viewBukti($id)
|
||||
{
|
||||
$this->abortUnlessPembiayaanOnline();
|
||||
$kodcaw = $this->kodcaw();
|
||||
$res = $this->api()
|
||||
->get(config('api.url') . '/api/pembiayaan-online/' . $kodcaw . '/lines/' . $id . '/bukti');
|
||||
@@ -258,6 +282,7 @@ class PembiayaanOnlineController extends Controller
|
||||
*/
|
||||
public function markBlast(Request $request)
|
||||
{
|
||||
$this->abortUnlessPembiayaanOnline();
|
||||
$kodcaw = $this->kodcaw();
|
||||
$ids = $request->input('ids', []);
|
||||
if (!is_array($ids)) {
|
||||
@@ -572,9 +597,8 @@ class PembiayaanOnlineController extends Controller
|
||||
$api_url = config('api.url');
|
||||
$status = $request->input('status', '');
|
||||
|
||||
$cawangan_info = $this->api()
|
||||
->get($api_url . '/api/cawangan/' . $kodcaw)
|
||||
->json();
|
||||
$cawangan_info = $this->cawanganInfo();
|
||||
$this->abortUnlessPembiayaanOnline($cawangan_info);
|
||||
|
||||
$modal = $this->api()
|
||||
->get($api_url . '/api/modal-online/' . $kodcaw)
|
||||
@@ -624,6 +648,7 @@ class PembiayaanOnlineController extends Controller
|
||||
*/
|
||||
public function topupRequest(Request $request)
|
||||
{
|
||||
$this->abortUnlessPembiayaanOnline();
|
||||
$kodcaw = $this->kodcaw();
|
||||
$amaun = (float) $request->input('amaun', 0);
|
||||
|
||||
@@ -742,6 +767,7 @@ class PembiayaanOnlineController extends Controller
|
||||
*/
|
||||
public function closeModal(Request $request)
|
||||
{
|
||||
$this->abortUnlessPembiayaanOnline();
|
||||
$kodcaw = $this->kodcaw();
|
||||
|
||||
$res = $this->api()
|
||||
|
||||
Reference in New Issue
Block a user