From f90851b6f2c60fc2f81f09660625ba0904a96a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Mon, 27 May 2024 12:49:34 +0000 Subject: [PATCH] Fix FLEXIAPI-178 Show the unused code in the Activity tab of the accounts in the admin panel --- CHANGELOG.md | 1 + flexiapi/app/Account.php | 7 +--- .../Admin/AccountActionController.php | 24 ++++++------- .../Admin/AccountActivityController.php | 5 ++- .../Admin/AccountContactController.php | 16 ++++----- .../Controllers/Admin/AccountController.php | 35 +++++++++---------- .../Admin/AccountDeviceController.php | 10 +++--- .../Admin/AccountDictionaryController.php | 27 +++++++++----- .../Admin/AccountTypeController.php | 2 +- flexiapi/public/css/style.css | 8 ++--- .../admin/account/activity/index.blade.php | 16 +++++---- 11 files changed, 78 insertions(+), 73 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 770e7f8..db09c2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 !) diff --git a/flexiapi/app/Account.php b/flexiapi/app/Account.php index a70d554..a78bf65 100644 --- a/flexiapi/app/Account.php +++ b/flexiapi/app/Account.php @@ -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; } diff --git a/flexiapi/app/Http/Controllers/Admin/AccountActionController.php b/flexiapi/app/Http/Controllers/Admin/AccountActionController.php index f560831..f890636 100644 --- a/flexiapi/app/Http/Controllers/Admin/AccountActionController.php +++ b/flexiapi/app/Http/Controllers/Admin/AccountActionController.php @@ -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) diff --git a/flexiapi/app/Http/Controllers/Admin/AccountActivityController.php b/flexiapi/app/Http/Controllers/Admin/AccountActivityController.php index a0ae08f..e4ffefb 100644 --- a/flexiapi/app/Http/Controllers/Admin/AccountActivityController.php +++ b/flexiapi/app/Http/Controllers/Admin/AccountActivityController.php @@ -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) ] ); } diff --git a/flexiapi/app/Http/Controllers/Admin/AccountContactController.php b/flexiapi/app/Http/Controllers/Admin/AccountContactController.php index f79f39e..d401af0 100644 --- a/flexiapi/app/Http/Controllers/Admin/AccountContactController.php +++ b/flexiapi/app/Http/Controllers/Admin/AccountContactController.php @@ -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); diff --git a/flexiapi/app/Http/Controllers/Admin/AccountController.php b/flexiapi/app/Http/Controllers/Admin/AccountController.php index 562a0e7..da8e993 100644 --- a/flexiapi/app/Http/Controllers/Admin/AccountController.php +++ b/flexiapi/app/Http/Controllers/Admin/AccountController.php @@ -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'); } } diff --git a/flexiapi/app/Http/Controllers/Admin/AccountDeviceController.php b/flexiapi/app/Http/Controllers/Admin/AccountDeviceController.php index 478300d..2b96e13 100644 --- a/flexiapi/app/Http/Controllers/Admin/AccountDeviceController.php +++ b/flexiapi/app/Http/Controllers/Admin/AccountDeviceController.php @@ -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'); } diff --git a/flexiapi/app/Http/Controllers/Admin/AccountDictionaryController.php b/flexiapi/app/Http/Controllers/Admin/AccountDictionaryController.php index 026e43d..9378806 100644 --- a/flexiapi/app/Http/Controllers/Admin/AccountDictionaryController.php +++ b/flexiapi/app/Http/Controllers/Admin/AccountDictionaryController.php @@ -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); diff --git a/flexiapi/app/Http/Controllers/Admin/AccountTypeController.php b/flexiapi/app/Http/Controllers/Admin/AccountTypeController.php index 9dfd443..8e5a2b9 100644 --- a/flexiapi/app/Http/Controllers/Admin/AccountTypeController.php +++ b/flexiapi/app/Http/Controllers/Admin/AccountTypeController.php @@ -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(); diff --git a/flexiapi/public/css/style.css b/flexiapi/public/css/style.css index 29bc1b4..df0cce0 100644 --- a/flexiapi/public/css/style.css +++ b/flexiapi/public/css/style.css @@ -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 { diff --git a/flexiapi/resources/views/admin/account/activity/index.blade.php b/flexiapi/resources/views/admin/account/activity/index.blade.php index f1587a1..8f48d74 100644 --- a/flexiapi/resources/views/admin/account/activity/index.blade.php +++ b/flexiapi/resources/views/admin/account/activity/index.blade.php @@ -16,7 +16,7 @@ @if ($account->apiKey)

Api Key

- +
@@ -50,7 +50,7 @@ @if ($account->accountCreationToken)

Account Creation Token

-
Code
+
@@ -78,7 +78,7 @@ @if ($account->recoveryCodes->isNotEmpty())

Recovery Codes

-
Code
+
@@ -108,10 +108,11 @@ @if ($account->phoneChangeCodes->isNotEmpty())

Phone Change requests

-
Code
+
+ @@ -121,6 +122,7 @@ @foreach ($account->phoneChangeCodes as $phoneChangeCode) consumed()) class="disabled crossed" @endif> + @@ -138,10 +140,11 @@ @if ($account->emailChangeCodes->isNotEmpty())

Email Change requests

-
PhoneCode Created Used IP
{{ $phoneChangeCode->phone }}{{ $phoneChangeCode->code ?? '-' }} {{ $phoneChangeCode->created_at }}
+
+ @@ -151,6 +154,7 @@ @foreach ($account->emailChangeCodes as $emailChangeCode) consumed()) class="disabled crossed" @endif> + @@ -168,7 +172,7 @@ @if ($account->provisioningTokens->isNotEmpty())

Provisioning tokens

-
EmailCode Created Used IP
{{ $emailChangeCode->email }}{{ $emailChangeCode->code ?? '-' }} {{ $emailChangeCode->created_at }}
+
Token