From 578e26f5da25a3ee1f60fe4aba3dce4c67b6b895 Mon Sep 17 00:00:00 2001 From: LukiBeg Date: Tue, 25 Nov 2025 16:43:52 -0300 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20Visualiza=C3=A7=C3=A3o=20de=20detal?= =?UTF-8?q?hes=20dos=20clientes=20(Commit=20anterior=20n=C3=A3o=20condiz?= =?UTF-8?q?=20com=20essa=20feature).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Livewire/Admin/Client/DeleteClient.php | 1 - app/Livewire/Admin/Client/DetailClient.php | 30 +++ app/Livewire/Admin/Client/EditClient.php | 2 - app/Models/Client.php | 13 ++ app/Services/ClientService.php | 6 + .../0001_01_01_000000_create_users_table.php | 2 +- ...2025_11_06_142841_create_clients_table.php | 49 ++--- resources/views/dashboard.blade.php | 1 + resources/views/layouts/app.blade.php | 6 + .../admin/clients/add-client.blade.php | 46 +++- .../admin/clients/detail-client.blade.php | 197 ++++++++++++++++++ .../admin/clients/edit-client.blade.php | 38 +++- .../livewire/admin/show-client.blade.php | 60 +++--- .../views/livewire/admin/show-users.blade.php | 62 +++--- 14 files changed, 401 insertions(+), 112 deletions(-) create mode 100644 app/Livewire/Admin/Client/DetailClient.php create mode 100644 resources/views/livewire/admin/clients/detail-client.blade.php diff --git a/app/Livewire/Admin/Client/DeleteClient.php b/app/Livewire/Admin/Client/DeleteClient.php index 85b722f..e1ad1f6 100644 --- a/app/Livewire/Admin/Client/DeleteClient.php +++ b/app/Livewire/Admin/Client/DeleteClient.php @@ -19,7 +19,6 @@ public function deleteClient($payload) } $this->dispatch('client-deleted'); - // (Opcional) Envia uma notificação de sucesso $this->dispatch('notify', message: 'Cliente excluído com sucesso!'); } diff --git a/app/Livewire/Admin/Client/DetailClient.php b/app/Livewire/Admin/Client/DetailClient.php new file mode 100644 index 0000000..5a905c2 --- /dev/null +++ b/app/Livewire/Admin/Client/DetailClient.php @@ -0,0 +1,30 @@ +client = Client::findOrFail($id); + $decryptedPassword = Crypt::decryptString($this->client->root_password); + $this->client->root_password = $decryptedPassword; + + } + + public function render() + { + return view('livewire.admin.clients.detail-client'); + } +} diff --git a/app/Livewire/Admin/Client/EditClient.php b/app/Livewire/Admin/Client/EditClient.php index 811ee00..0dc71da 100644 --- a/app/Livewire/Admin/Client/EditClient.php +++ b/app/Livewire/Admin/Client/EditClient.php @@ -21,8 +21,6 @@ class EditClient extends Component // public ClientService $clientService; #[On('update-client')] - - public function loadClient($id) { try { diff --git a/app/Models/Client.php b/app/Models/Client.php index 8ca4daf..3ccf58e 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -28,6 +28,9 @@ class Client extends Model 'carrier', 'access_type', 'server_ip', + 'port', + 'ddr_key', + 'ddr_out', 'root_password', // Lembre-se de criptografar isso! 'has_call_center', 'has_voice_gateway', @@ -35,8 +38,18 @@ class Client extends Model 'modules', 'whatsapp_number', 'whatsapp_activation_date', + 'observation', ]; + /* + + - Número chave, número de saída + - Credenciais de acesso VPN + - Anexos + - Porta de acesso + + */ + /** * Os atributos que devem ser convertidos para tipos nativos. * diff --git a/app/Services/ClientService.php b/app/Services/ClientService.php index 11d53c8..aabe59c 100644 --- a/app/Services/ClientService.php +++ b/app/Services/ClientService.php @@ -25,4 +25,10 @@ public function updateClient(Client $client, $data) $data['name'] = $data['client_name']; return $client->update($data); } + + public function detailClient(Client $client) + { + //Detail method + return $client->all(); + } } diff --git a/database/migrations/0001_01_01_000000_create_users_table.php b/database/migrations/0001_01_01_000000_create_users_table.php index 3a6f800..e01ce60 100644 --- a/database/migrations/0001_01_01_000000_create_users_table.php +++ b/database/migrations/0001_01_01_000000_create_users_table.php @@ -12,7 +12,7 @@ public function up(): void { Schema::create('users', function (Blueprint $table) { - $table->id(); + $table->uuid('id')->primary(); $table->string('name'); $table->json('permissions')->nullable(); $table->string('email')->unique(); diff --git a/database/migrations/2025_11_06_142841_create_clients_table.php b/database/migrations/2025_11_06_142841_create_clients_table.php index ff53844..58a3fd8 100644 --- a/database/migrations/2025_11_06_142841_create_clients_table.php +++ b/database/migrations/2025_11_06_142841_create_clients_table.php @@ -12,45 +12,40 @@ public function up(): void { Schema::create('clients', function (Blueprint $table) { - // 1. Alterado de $table->id() para $table->uuid() - $table->uuid('id')->primary(); + $table->uuid('id')->primary(); - // Informações de Cadastro - $table->string('name'); - $table->string('legal_name'); - $table->string('cnpj')->unique()->nullable(); - - // 2. Adicionado o path da imagem - $table->string('profile_image_path')->nullable(); // "path da imagem do cliente" + $table->string('name'); + $table->string('legal_name'); + $table->string('cnpj')->unique()->nullable(); + + $table->string('profile_image_path')->nullable(); // Informações Técnicas - $table->string('pbx_hosting')->nullable(); - $table->date('activation_date')->nullable(); - $table->string('carrier')->nullable(); - $table->string('access_type')->nullable(); - $table->ipAddress('server_ip')->nullable(); - $table->text('root_password')->nullable(); + $table->string('pbx_hosting')->nullable(); + $table->date('activation_date')->nullable(); + $table->string('carrier')->nullable(); + $table->string('access_type')->nullable(); + $table->ipAddress('server_ip')->nullable(); + $table->text('root_password')->nullable(); + $table->text('ddr_out')->nullable(); + $table->text('ddr_key')->nullable(); + $table->longText('observation')->nullable(); - // Módulos e Features - $table->boolean('has_call_center')->default(false); - $table->boolean('has_voice_gateway')->default(false); - $table->boolean('has_fop2')->default(false); + $table->boolean('has_call_center')->default(false); + $table->boolean('has_voice_gateway')->default(false); + $table->boolean('has_fop2')->default(false); - // Módulos - $table->json('modules')->nullable(); - $table->string('whatsapp_number')->nullable(); - $table->date('whatsapp_activation_date')->nullable(); + $table->json('modules')->nullable(); + $table->string('whatsapp_number')->nullable(); + $table->date('whatsapp_activation_date')->nullable(); $table->timestamps(); $table->softDeletes(); }); } - /** - * Reverse the migrations. - */ public function down(): void { Schema::dropIfExists('clients'); } -}; \ No newline at end of file +}; diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 9060843..5faa88e 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -8,6 +8,7 @@ + diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 4b99110..5b14c93 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -76,6 +76,12 @@ +
  • + + VPN's + +
  • + @endauth diff --git a/resources/views/livewire/admin/clients/add-client.blade.php b/resources/views/livewire/admin/clients/add-client.blade.php index 4b62956..af17eb7 100644 --- a/resources/views/livewire/admin/clients/add-client.blade.php +++ b/resources/views/livewire/admin/clients/add-client.blade.php @@ -22,7 +22,7 @@ class="fixed inset-y-0 right-0 flex max-w-full pl-10" @click.away="showClientMod Adicionar Novo Cliente + + + + @if($client) +
    +
    + +
    +

    Informações Principais

    + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + +
    + @if($client->profile_image_path) +
    + Logo +
    + Abrir imagem + @else + Sem logo + @endif +
    +
    +
    +
    + +
    + +
    +

    Detalhes do Servidor PBX

    +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    + +
    + + +
    +
    + + +
    + +
    + + +
    +
    + +
    + + +
    +
    +
    +
    + +
    + +
    +

    Observações e Credenciais Internas

    +
    + +
    +
    + +
    + +
    +

    WhatsApp

    +
    +
    + + +
    +
    + + +
    +
    +
    + +
    +
    +
    +

    Módulos & Recursos

    + +
    + + + +
    + +
    + + +
    +
    +
    +
    + +
    +
    + @else +
    +
    + + Carregando... +
    +
    + @endif + +
    +
    + +
    +
    + + + + + \ No newline at end of file diff --git a/resources/views/livewire/admin/clients/edit-client.blade.php b/resources/views/livewire/admin/clients/edit-client.blade.php index b3641b5..144031d 100644 --- a/resources/views/livewire/admin/clients/edit-client.blade.php +++ b/resources/views/livewire/admin/clients/edit-client.blade.php @@ -22,7 +22,7 @@ class="fixed inset-y-0 right-0 flex max-w-full pl-10" @click.away="showEditClien Edição de cliente - - - - +
    +
    +
    + Avatar do Cliente
    -
    - {{ $client->name }} +
    + + + +
    +
    + {{ $client->name }} +
    +
    @endforeach
    \ No newline at end of file diff --git a/resources/views/livewire/admin/show-users.blade.php b/resources/views/livewire/admin/show-users.blade.php index ef699eb..467fb74 100644 --- a/resources/views/livewire/admin/show-users.blade.php +++ b/resources/views/livewire/admin/show-users.blade.php @@ -10,43 +10,43 @@
    @forelse ($users as $user) -
    - -
    - {{-- {{ ucfirst($user->permissions) }} --}} - Ativo +
    + +
    + {{-- {{ $user->permissions }} --}} + Ativo -
    +
    @empty -

    Nenhum usuário cadastrado.

    +

    Nenhum usuário cadastrado.

    @endforelse
    From cc52c73f696fa88fce555e0f42582dc787b5a574 Mon Sep 17 00:00:00 2001 From: lukibeg Date: Thu, 27 Nov 2025 20:35:44 -0300 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20Autoriza=C3=A7=C3=A3o=20implementad?= =?UTF-8?q?a=20em=20todos=20os=20controladores.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Livewire/Admin/Client/AddClient.php | 6 +++-- app/Livewire/Admin/Client/DeleteClient.php | 25 +++++++++++++------ app/Livewire/Admin/Client/EditClient.php | 22 ++++++++-------- app/Livewire/Admin/User/CreateUser.php | 6 ++--- app/Livewire/Admin/User/DeleteUser.php | 9 ++++--- app/Livewire/Admin/User/EditUser.php | 6 ++++- app/Providers/AppServiceProvider.php | 19 +++++++++++--- app/Services/UserService.php | 2 ++ .../views/components/flash-messages.blade.php | 4 +-- 9 files changed, 68 insertions(+), 31 deletions(-) diff --git a/app/Livewire/Admin/Client/AddClient.php b/app/Livewire/Admin/Client/AddClient.php index 4ef7c0e..f62fc53 100644 --- a/app/Livewire/Admin/Client/AddClient.php +++ b/app/Livewire/Admin/Client/AddClient.php @@ -18,9 +18,11 @@ class AddClient extends Component public function save(ClientService $clientService) { - $this->form->validate(); try { + $this->authorize('addClient', Auth::user()); + $this->form->validate(); + $data = $this->form->all(); $data['name'] = $data['client_name']; @@ -36,7 +38,7 @@ public function save(ClientService $clientService) $this->dispatch('client-added'); $this->dispatch('notify', message: $client->name . ' adicionado com sucesso!'); } catch (\Exception $e) { - $this->dispatch('notify', message: 'Ocorreu um erro inesperado ao salvar.', type: 'error'); + $this->dispatch('notify', message: 'Ocorreu um erro inesperado ao salvar. ' . $e->getMessage(), type: 'error'); } } diff --git a/app/Livewire/Admin/Client/DeleteClient.php b/app/Livewire/Admin/Client/DeleteClient.php index e1ad1f6..d3c951e 100644 --- a/app/Livewire/Admin/Client/DeleteClient.php +++ b/app/Livewire/Admin/Client/DeleteClient.php @@ -5,25 +5,36 @@ use Livewire\Component; use Livewire\Attributes\On; use App\Models\Client; +use Exception; +use Illuminate\Support\Facades\Auth; class DeleteClient extends Component { #[On('confirm-delete')] public function deleteClient($payload) { + try { + // Sua lógica de autorização e exclusão (Correta) + $this->authorize('deleteClient', Auth::user()); - $deletedClient = Client::findOrFail($payload); + $deletedClient = Client::findOrFail($payload); - if ($deletedClient) { - $deletedClient->delete(); + if ($deletedClient) { + $deletedClient->delete(); + } + + // Sucesso (Dentro do try, onde deve estar) + $this->dispatch('client-deleted'); + $this->dispatch('notify', message: 'Cliente excluído com sucesso!'); + + } catch (Exception $e) { + // Tratamento de erro + $this->dispatch('notify', message: 'Você não possui permissão para realizar essa ação.', type: 'error'); } - - $this->dispatch('client-deleted'); - $this->dispatch('notify', message: 'Cliente excluído com sucesso!'); } public function render() { return '
    '; } -} +} \ No newline at end of file diff --git a/app/Livewire/Admin/Client/EditClient.php b/app/Livewire/Admin/Client/EditClient.php index 0dc71da..7a27f8b 100644 --- a/app/Livewire/Admin/Client/EditClient.php +++ b/app/Livewire/Admin/Client/EditClient.php @@ -5,6 +5,7 @@ use App\Livewire\Forms\ClientForm; use App\Models\Client; use App\Services\ClientService; +use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Crypt; use Livewire\Attributes\On; use Livewire\Component; @@ -18,7 +19,6 @@ class EditClient extends Component public Client $client; public ClientForm $clientForm; - // public ClientService $clientService; #[On('update-client')] public function loadClient($id) @@ -35,17 +35,19 @@ public function loadClient($id) } public function edit(ClientService $clientService) { - $data = $this->clientForm->validate(); - - if ($this->clientForm->profile_image_path) { - $path = $this->clientForm->profile_image_path->store('client_logos', 'public'); - $data['profile_image_path'] = $path; - } - - $data['root_password'] = Crypt::encryptString($data['root_password']); - try { + + $this->authorize('editClient', Auth::user()); + $data = $this->clientForm->validate(); + + if ($this->clientForm->profile_image_path) { + $path = $this->clientForm->profile_image_path->store('client_logos', 'public'); + $data['profile_image_path'] = $path; + } + + $data['root_password'] = Crypt::encryptString($data['root_password']); + if (!$clientService->updateClient($this->client, $data)) { throw new Exception('O serviço não confirmou a atualização.'); } diff --git a/app/Livewire/Admin/User/CreateUser.php b/app/Livewire/Admin/User/CreateUser.php index 9add896..de6e8a2 100644 --- a/app/Livewire/Admin/User/CreateUser.php +++ b/app/Livewire/Admin/User/CreateUser.php @@ -34,11 +34,10 @@ class CreateUser extends Component public function createUser(UserService $userService) { - $validated = $this->validate($this->rules, $this->messages); - try { - $this->authorize('createUser', Auth::user()); + $validated = $this->validate($this->rules, $this->messages); + $user = $userService->createUser($validated); @@ -49,6 +48,7 @@ public function createUser(UserService $userService) $this->dispatch('notify', message: 'Usuário cadastrado com sucesso!'); } catch (\Exception $e) { $this->addError('general', $e->getMessage()); + $this->dispatch('notify', message: 'Ocorreu um erro ao criar o usuário. ' . $e->getMessage(), type: 'error'); } } diff --git a/app/Livewire/Admin/User/DeleteUser.php b/app/Livewire/Admin/User/DeleteUser.php index 9871804..2a0999f 100644 --- a/app/Livewire/Admin/User/DeleteUser.php +++ b/app/Livewire/Admin/User/DeleteUser.php @@ -6,6 +6,7 @@ use Livewire\Attributes\On; use App\Models\User; use App\Services\UserService; +use Illuminate\Support\Facades\Auth; use Exception; class DeleteUser extends Component @@ -14,9 +15,11 @@ class DeleteUser extends Component #[On('confirm-delete-user')] public function deleteUser(UserService $userService, $payload) { - - $deletedUser = User::findOrFail($payload); try { + + $this->authorize('deleteUser', Auth::user()); + + $deletedUser = User::findOrFail($payload); if ($deletedUser) { $deletedUser = $userService->deleteUser($deletedUser); } @@ -25,7 +28,7 @@ public function deleteUser(UserService $userService, $payload) $this->dispatch('notify', message: $deletedUser->name . ' Usuário excluído com sucesso!'); } catch (Exception $e) { $this->dispatch('user-delete-error'); - $this->dispatch('notify', message: $e->getMessage()); + $this->dispatch('notify', message: $e->getMessage(), type: 'error'); } } diff --git a/app/Livewire/Admin/User/EditUser.php b/app/Livewire/Admin/User/EditUser.php index b522ae0..2f35740 100644 --- a/app/Livewire/Admin/User/EditUser.php +++ b/app/Livewire/Admin/User/EditUser.php @@ -7,6 +7,7 @@ use Livewire\Component; use Livewire\Attributes\On; use App\Services\UserService; +use Illuminate\Support\Facades\Auth; class EditUser extends Component { @@ -31,8 +32,11 @@ public function loadUser($id) } public function editUser(UserService $userService) { - $data = $this->userForm->validate(); + try { + $this->authorize('editUser', Auth::user()); + $data = $this->userForm->validate(); + if (!$userService->updateUser($this->user, $data)) { throw new \Exception('O serviço não confirmou a atualização.'); } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index b3423a4..e627d7c 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -22,8 +22,21 @@ public function register(): void */ public function boot(): void { - Gate::define('createUser', function (User $user) { - return isset($user->permissions) ? in_array('admin', $user->permissions) : false; - }); + // Lista de todas as ações que são exclusivas de Admin + $adminActions = [ + 'createUser', + 'editUser', + 'deleteUser', + 'addClient', // Exemplo + 'deleteClient', // Exemplo + 'editClient', + ]; + + foreach ($adminActions as $action) { + Gate::define($action, function (User $user) { + // A lógica fica centralizada aqui. Se mudar, muda pra todos. + return isset($user->permissions) && in_array('admin', $user->permissions); + }); + } } } diff --git a/app/Services/UserService.php b/app/Services/UserService.php index 7af14fc..6f590cd 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -13,6 +13,8 @@ class UserService public function __construct(protected User $user) {} public function createUser(array $user) { + $permissions = [$user['permissions']]; + $user['permissions'] = $permissions; return User::create($user); } diff --git a/resources/views/components/flash-messages.blade.php b/resources/views/components/flash-messages.blade.php index d78d96e..4beca58 100644 --- a/resources/views/components/flash-messages.blade.php +++ b/resources/views/components/flash-messages.blade.php @@ -12,7 +12,7 @@ } }" @notify.window="addToast($event.detail.message, $event.detail.type || 'success')" @notifyError.window="addToast($event.detail.message, $event.detail.type || 'error')" - class="fixed top-5 right-5 z-50 flex w-full max-w-xs flex-col space-y-3"> + class="fixed top-5 right-5 z-50000 flex w-full max-w-xs flex-col space-y-3">