Fix FLEXIAPI-442 Handle Redis delete errors in the UI

This commit is contained in:
Timothée Jaussoin 2026-02-24 17:22:09 +01:00
parent 3f0ecc297b
commit 450844ba33
6 changed files with 38 additions and 15 deletions

View file

@ -45,12 +45,16 @@ class DeviceController extends Controller
$connector = new FlexisipRedisConnector;
$account = Account::findOrFail($accountId);
$device = $connector->getDevices($account->identifier)
->where('uuid', $uuid)->first();
if (!$device) abort(404);
return view(
'admin.account.device.delete',
[
'account' => $account,
'device' => $connector->getDevices($account->identifier)
->where('uuid', $uuid)->first()
'device' => $device
]
);
}
@ -60,8 +64,10 @@ class DeviceController extends Controller
$connector = new FlexisipRedisConnector;
$account = Account::findOrFail($accountId);
$connector->deleteDevice($account->identifier, $request->get('uuid'));
if ($connector->deleteDevice($account->identifier, $request->get('uuid'))) {
return redirect()->route('admin.account.show', $account);
}
return redirect()->route('admin.account.device.delete', [$account, $request->get('uuid')])->withErrors(['Device cannot be deleted']);
}
}

View file

@ -20,7 +20,7 @@ class VoicemailController extends Controller
$account = Account::findOrFail($accountId);
if ($account->email == null) {
abort(422, 'The account should be reachable by email');
abort(422, 'The has not email address attached to it');
}
$request->validate([

View file

@ -47,14 +47,18 @@ class FlexisipRedisConnector
return $devices->keyBy('uuid');
}
public function deleteDevice(string $from, string $uuid)
public function deleteDevice(string $from, string $uuid): bool
{
try {
Redis::hdel('fs:' . $from, '"<' . $uuid . '>"');
$count = Redis::hdel('fs:' . $from, '"<' . $uuid . '>"');
Redis::publish($from, '');
return $count > 0;
} catch (\Throwable $th) {
Log::error('Redis server issue: ' . $th->getMessage());
}
return false;
}
public function pingB2BUA(ExternalAccount $externalAccount): bool

View file

@ -1046,3 +1046,17 @@ small a {
small.error {
color: var(--danger-6);
}
/** Errors box **/
ul.errors {
background-color: var(--color-pink);
padding: 1rem;
border-radius: 1rem;
}
ul.errors li {
list-style-type: none;
margin: 0;
color: white;
}

View file

@ -64,8 +64,6 @@
@include('parts.sidebar')
@endif
@include('parts.errors')
@if (!isset($welcome) || $welcome == false)
<section @if (isset($grid) && $grid) class="grid" @endif>
@ -78,6 +76,7 @@
@endif
@endif
@include('parts.errors')
@yield('content')
@if (!isset($welcome) || $welcome == false)

View file

@ -1,7 +1,7 @@
@if (isset($errors) && isset($name) && count($errors->get($name)) > 0)
@foreach ($errors->get($name) as $error)
<small class="error">
{{ $error }}
</small>
@if (isset($errors) && $errors->isNotEmpty())
<ul class="errors">
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
@endif