Move integration credentials into encrypted dashboard settings
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 1m42s
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 1m42s
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\IntegrationSetting;
|
||||
use App\Services\IntegrationSettings;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class IntegrationSettingsController extends Controller
|
||||
{
|
||||
public function update(Request $request, string $provider, IntegrationSettings $settings): RedirectResponse
|
||||
{
|
||||
abort_unless($request->user()->role === 'admin', 403);
|
||||
abort_unless(in_array($provider, ['parcel2go', 'bambuddy', 'dryer'], true), 404);
|
||||
|
||||
$rules = match ($provider) {
|
||||
'parcel2go' => [
|
||||
'client_id' => ['nullable', 'string', 'max:255'],
|
||||
'client_secret' => ['nullable', 'string', 'max:255'],
|
||||
'auth_url' => ['nullable', 'url:https', 'max:2048'],
|
||||
'base_url' => ['nullable', 'url:https', 'max:2048'],
|
||||
],
|
||||
default => [
|
||||
'url' => ['nullable', 'url:https', 'max:2048'],
|
||||
'api_key' => ['nullable', 'string', 'max:512'],
|
||||
],
|
||||
};
|
||||
$submitted = array_filter($request->validate($rules), fn (?string $value): bool => filled($value));
|
||||
$effective = $settings->for($provider);
|
||||
if ($submitted === [] && ! collect($effective)->contains(fn ($value): bool => filled($value))) {
|
||||
return redirect()->route('settings.index')->with('status', 'No integration settings changed.');
|
||||
}
|
||||
|
||||
$record = IntegrationSetting::find($provider) ?? new IntegrationSetting(['provider' => $provider]);
|
||||
$record->settings = array_replace($effective, $submitted);
|
||||
$record->save();
|
||||
|
||||
return redirect()->route('settings.index')->with('status', ucfirst($provider).' settings saved.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user