Fix FLEXIAPI-178 Show the unused code in the Activity tab of the accounts in the admin panel

This commit is contained in:
Timothée Jaussoin 2024-05-27 12:49:34 +00:00
parent b44d6e1b25
commit f90851b6f2
11 changed files with 78 additions and 73 deletions

View file

@ -2,6 +2,7 @@
v1.5
----
- Fix FLEXIAPI-178 Show the unused code in the Activity tab of the accounts in the admin panel
- Fix FLEXIAPI-177 Complete vcards-storage and devices related endpoints with their User/Admin ones
- Fix FLEXIAPI-176 Improve logs for the deprecated endpoints and AccountCreationToken related serialization
- Fix FLEXIAPI-175 and FLEXISIP-231 Rewrite the Redis contacts parser to handle properly SIP uris (thanks @thibault.lemaire !)

View file

@ -68,12 +68,7 @@ class Account extends Authenticatable
protected static function booted()
{
static::addGlobalScope('domain', function (Builder $builder) {
if (Auth::hasUser()) {
$user = Auth::user();
if (!$user->admin || !config('app.admins_manage_multi_domains')) {
$builder->where('domain', config('app.sip_domain'));
}
if (Auth::hasUser() && Auth::user()->admin && config('app.admins_manage_multi_domains')) {
return;
}

View file

@ -29,9 +29,9 @@ use App\Rules\NoUppercase;
class AccountActionController extends Controller
{
public function create(int $id)
public function create(int $accountId)
{
$account = Account::findOrFail($id);
$account = Account::findOrFail($accountId);
return view('admin.account.action.create_edit', [
'action' => new AccountAction,
@ -39,9 +39,9 @@ class AccountActionController extends Controller
]);
}
public function store(Request $request, int $id)
public function store(Request $request, int $accountId)
{
$account = Account::findOrFail($id);
$account = Account::findOrFail($accountId);
$request->validate([
'key' => ['required', 'alpha_dash', new NoUppercase],
@ -59,9 +59,9 @@ class AccountActionController extends Controller
return redirect()->route('admin.account.edit', $accountAction->account);
}
public function edit(int $id, int $actionId)
public function edit(int $accountId, int $actionId)
{
$account = Account::findOrFail($id);
$account = Account::findOrFail($accountId);
$accountAction = $account->actions()
->where('id', $actionId)
@ -73,9 +73,9 @@ class AccountActionController extends Controller
]);
}
public function update(Request $request, int $id, int $actionId)
public function update(Request $request, int $accountId, int $actionId)
{
$account = Account::findOrFail($id);
$account = Account::findOrFail($accountId);
$request->validate([
'key' => ['alpha_dash', new NoUppercase],
@ -94,9 +94,9 @@ class AccountActionController extends Controller
return redirect()->route('admin.account.edit', $account);
}
public function delete(int $id, int $actionId)
public function delete(int $accountId, int $actionId)
{
$account = Account::findOrFail($id);
$account = Account::findOrFail($accountId);
return view('admin.account.action.delete', [
'action' => $account->actions()
@ -105,9 +105,9 @@ class AccountActionController extends Controller
]);
}
public function destroy(Request $request, int $id, int $actionId)
public function destroy(Request $request, int $accountId, int $actionId)
{
$account = Account::findOrFail($id);
$account = Account::findOrFail($accountId);
$accountAction = $account->actions()
->where('id', $actionId)

View file

@ -20,18 +20,17 @@
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Account;
class AccountActivityController extends Controller
{
public function index(Request $request, Account $account)
public function index(int $accountId)
{
return view(
'admin.account.activity.index',
[
'account' => $account
'account' => Account::findOrFail($accountId)
]
);
}

View file

@ -27,22 +27,22 @@ use App\Account;
class AccountContactController extends Controller
{
public function create(int $id)
public function create(int $accountId)
{
$account = Account::findOrFail($id);
$account = Account::findOrFail($accountId);
return view('admin.account.contact.create', [
'account' => $account
]);
}
public function store(Request $request, int $id)
public function store(Request $request, int $accountId)
{
$request->validate([
'sip' => 'required',
]);
$account = Account::findOrFail($id);
$account = Account::findOrFail($accountId);
$contact = Account::sip($request->get('sip'))->first();
if (!$contact) {
@ -59,9 +59,9 @@ class AccountContactController extends Controller
return redirect()->route('admin.account.edit', $account);
}
public function delete(int $id, int $contactId)
public function delete(int $accountId, int $contactId)
{
$account = Account::findOrFail($id);
$account = Account::findOrFail($accountId);
$contact = $account->contacts()->where('id', $contactId)->firstOrFail();
return view('admin.account.contact.delete', [
@ -70,9 +70,9 @@ class AccountContactController extends Controller
]);
}
public function destroy(Request $request, int $id)
public function destroy(Request $request, int $accountId)
{
$account = Account::findOrFail($id);
$account = Account::findOrFail($accountId);
$contact = $account->contacts()->where('id', $request->get('contact_id'))->firstOrFail();
$account->contacts()->detach($contact->id);

View file

@ -27,7 +27,6 @@ use App\Account;
use App\ContactsList;
use App\Http\Requests\Account\Create\Web\AsAdminRequest;
use App\Http\Requests\Account\Update\Web\AsAdminRequest as WebAsAdminRequest;
use App\Http\Requests\UpdateAccountRequest;
use App\Services\AccountService;
class AccountController extends Controller
@ -89,31 +88,31 @@ class AccountController extends Controller
return redirect()->route('admin.account.edit', $account->id);
}
public function edit(int $id)
public function edit(int $accountId)
{
return view('admin.account.create_edit', [
'account' => Account::findOrFail($id),
'account' => Account::findOrFail($accountId),
'protocols' => [null => 'None'] + Account::$dtmfProtocols,
'contacts_lists' => ContactsList::whereNotIn('id', function ($query) use ($id) {
'contacts_lists' => ContactsList::whereNotIn('id', function ($query) use ($accountId) {
$query->select('contacts_list_id')
->from('account_contacts_list')
->where('account_id', $id);
->where('account_id', $accountId);
})->get()
]);
}
public function update(WebAsAdminRequest $request, int $id)
public function update(WebAsAdminRequest $request, int $accountId)
{
$account = (new AccountService)->update($request, $id);
$account = (new AccountService)->update($request, $accountId);
Log::channel('events')->info('Web Admin: Account updated', ['id' => $account->identifier]);
return redirect()->route('admin.account.edit', $id);
return redirect()->route('admin.account.edit', $accountId);
}
public function provision(int $id)
public function provision(int $accountId)
{
$account = Account::findOrFail($id);
$account = Account::findOrFail($accountId);
$account->provision();
$account->save();
@ -122,9 +121,9 @@ class AccountController extends Controller
return redirect()->back()->withFragment('provisioning');
}
public function delete(int $id)
public function delete(int $accountId)
{
$account = Account::findOrFail($id);
$account = Account::findOrFail($accountId);
return view('admin.account.delete', [
'account' => $account
@ -142,24 +141,24 @@ class AccountController extends Controller
return redirect()->route('admin.account.index');
}
public function contactsListAdd(Request $request, int $id)
public function contactsListAdd(Request $request, int $accountId)
{
$request->validate([
'contacts_list_id' => 'required|exists:contacts_lists,id'
]);
$account = Account::findOrFail($id);
$account = Account::findOrFail($accountId);
$account->contactsLists()->detach([$request->get('contacts_list_id')]);
$account->contactsLists()->attach([$request->get('contacts_list_id')]);
return redirect()->route('admin.account.edit', $id)->withFragment('#contacts_lists');
return redirect()->route('admin.account.edit', $accountId)->withFragment('#contacts_lists');
}
public function contactsListRemove(Request $request, int $id)
public function contactsListRemove(Request $request, int $accountId)
{
$account = Account::findOrFail($id);
$account = Account::findOrFail($accountId);
$account->contactsLists()->detach([$request->get('contacts_list_id')]);
return redirect()->route('admin.account.edit', $id)->withFragment('#contacts_lists');
return redirect()->route('admin.account.edit', $accountId)->withFragment('#contacts_lists');
}
}

View file

@ -26,9 +26,10 @@ use App\Libraries\FlexisipConnector;
class AccountDeviceController extends Controller
{
public function index(Request $request, Account $account)
public function index(int $accountId)
{
$connector = new FlexisipConnector;
$account = Account::findOrFail($accountId);
return view(
'admin.account.device.index',
@ -39,9 +40,10 @@ class AccountDeviceController extends Controller
);
}
public function delete(Request $request, Account $account, string $uuid)
public function delete(int $accountId, string $uuid)
{
$connector = new FlexisipConnector;
$account = Account::findOrFail($accountId);
return view(
'admin.account.device.delete',
@ -53,10 +55,10 @@ class AccountDeviceController extends Controller
);
}
public function destroy(Request $request, Account $account)
public function destroy(Request $request, int $accountId)
{
$connector = new FlexisipConnector;
$connector->deleteDevice($account->identifier, $request->get('uuid'));
$connector->deleteDevice(Account::findOrFail($accountId)->identifier, $request->get('uuid'));
return redirect()->route('admin.account.device.index');
}

View file

@ -27,26 +27,28 @@ use App\AccountDictionaryEntry;
class AccountDictionaryController extends Controller
{
public function index(Request $request, Account $account)
public function index(int $accountId)
{
return view(
'admin.account.dictionary.index',
[
'account' => $account
'account' => Account::findOrFail($accountId)
]
);
}
public function create(Request $request, Account $account)
public function create(int $accountId)
{
return view('admin.account.dictionary.create_edit', [
'account' => $account,
'account' => Account::findOrFail($accountId),
'entry' => new AccountDictionaryEntry
]);
}
public function store(Request $request, Account $account)
public function store(Request $request, int $accountId)
{
$account = Account::findOrFail($accountId);
$request->validate([
'key' => 'required',
'value' => 'required'
@ -57,20 +59,24 @@ class AccountDictionaryController extends Controller
return redirect()->route('admin.account.dictionary.index', $account->id);
}
public function edit(Account $account, string $key)
public function edit(int $accountId, string $key)
{
$account = Account::findOrFail($accountId);
return view('admin.account.dictionary.create_edit', [
'account' => $account,
'entry' => $account->dictionaryEntries()->where('key', $key)->firstOrFail()
]);
}
public function update(Request $request, Account $account, int $entryId)
public function update(Request $request, int $accountId, int $entryId)
{
$request->validate([
'value' => 'required'
]);
$account = Account::findOrFail($accountId);
$entry = $account->dictionaryEntries()->findOrFail($entryId);
$entry->value = $request->get('value');
$entry->save();
@ -78,8 +84,10 @@ class AccountDictionaryController extends Controller
return redirect()->route('admin.account.dictionary.index', $account->id);
}
public function delete(Request $request, Account $account, string $key)
public function delete(int $accountId, string $key)
{
$account = Account::findOrFail($accountId);
return view(
'admin.account.dictionary.delete',
[
@ -89,8 +97,9 @@ class AccountDictionaryController extends Controller
);
}
public function destroy(Request $request, Account $account)
public function destroy(Request $request, int $accountId)
{
$account = Account::findOrFail($accountId);
$account->dictionaryEntries()->where('key', $request->get('key'))->delete();
return redirect()->route('admin.account.dictionary.index', $account);

View file

@ -86,7 +86,7 @@ class AccountTypeController extends Controller
]);
}
public function destroy(Request $request, int $typeId)
public function destroy(int $typeId)
{
$type = AccountType::findOrFail($typeId);
$type->delete();

View file

@ -36,7 +36,7 @@
}
html {
font-size: 10px;
font-size: 62%;
}
body {
@ -484,7 +484,7 @@ body.welcome::after {
display: block;
height: 10rem;
width: 100%;
background-size: 50rem;
background-size: 51rem;
content: '';
height: 5rem;
margin-top: 2rem;
@ -678,10 +678,6 @@ table tr.empty td:before {
line-height: 8rem;
}
table.third th {
width: 33.33%;
}
/* Display/hide */
.on_mobile {

View file

@ -16,7 +16,7 @@
@if ($account->apiKey)
<h3>Api Key</h3>
<table class="third">
<table>
<thead>
<tr>
<th>Code</th>
@ -50,7 +50,7 @@
@if ($account->accountCreationToken)
<h3>Account Creation Token</h3>
<table class="third">
<table>
<thead>
<tr>
<th>Code</th>
@ -78,7 +78,7 @@
@if ($account->recoveryCodes->isNotEmpty())
<h3>Recovery Codes</h3>
<table class="third">
<table>
<thead>
<tr>
<th>Code</th>
@ -108,10 +108,11 @@
@if ($account->phoneChangeCodes->isNotEmpty())
<h3>Phone Change requests</h3>
<table class="third">
<table>
<thead>
<tr>
<th>Phone</th>
<th>Code</th>
<th>Created</th>
<th>Used</th>
<th>IP</th>
@ -121,6 +122,7 @@
@foreach ($account->phoneChangeCodes as $phoneChangeCode)
<tr @if ($phoneChangeCode->consumed()) class="disabled crossed" @endif>
<td>{{ $phoneChangeCode->phone }}</td>
<td>{{ $phoneChangeCode->code ?? '-' }}</td>
<td>
{{ $phoneChangeCode->created_at }}
</td>
@ -138,10 +140,11 @@
@if ($account->emailChangeCodes->isNotEmpty())
<h3>Email Change requests</h3>
<table class="third">
<table>
<thead>
<tr>
<th>Email</th>
<th>Code</th>
<th>Created</th>
<th>Used</th>
<th>IP</th>
@ -151,6 +154,7 @@
@foreach ($account->emailChangeCodes as $emailChangeCode)
<tr @if ($emailChangeCode->consumed()) class="disabled crossed" @endif>
<td>{{ $emailChangeCode->email }}</td>
<td>{{ $emailChangeCode->code ?? '-' }}</td>
<td>
{{ $emailChangeCode->created_at }}
</td>
@ -168,7 +172,7 @@
@if ($account->provisioningTokens->isNotEmpty())
<h3>Provisioning tokens</h3>
<table class="third">
<table>
<thead>
<tr>
<th>Token</th>