fix(impersonation): resolve 1-click impersonation with dedicated HTTP route, consolidate Cecilia Tordini studio scoping (#13), enable Adminer dual DB switcher (MySQL/PgSQL), and update ASCII wireframes (task-d095b0e23b)

This commit is contained in:
michele 2026-08-28 12:59:09 +02:00
parent c167140160
commit 300774623b
5 changed files with 163 additions and 120 deletions

View File

@ -155,20 +155,9 @@ public function impersonaSelected(): void
return;
}
$amm = Amministratore::query()->with('user')->find($this->selectedAmministratoreId);
if ($amm && $amm->user) {
$actorId = Auth::id();
$targetUser = $amm->user;
if (method_exists($targetUser, 'hasRole') && ! $targetUser->hasAnyRole(['admin', 'amministratore', 'super-admin'])) {
$targetUser->assignRole('amministratore');
}
session(['impersonator_id' => $actorId]);
Auth::guard('web')->login($targetUser, true);
request()->session()->regenerate();
$this->redirect('/admin-filament');
$amm = Amministratore::query()->find($this->selectedAmministratoreId);
if ($amm && $amm->user_id) {
$this->redirect(route('impersonate.take', ['user' => $amm->user_id]), navigate: false);
}
}
@ -273,16 +262,8 @@ public function table(Table $table): Table
->modalDescription('Stai per accedere al sistema impersonando lo studio dellamministratore selezionato. Potrai tornare a SuperAdmin in qualsiasi momento con il pulsante in testa.')
->visible(fn(Amministratore $record): bool => (bool) $record->user_id && $record->user_id !== Auth::id())
->action(function (Amministratore $record): void {
if ($record->user) {
$actorId = Auth::id();
$targetUser = $record->user;
if (method_exists($targetUser, 'hasRole') && ! $targetUser->hasAnyRole(['admin', 'amministratore', 'super-admin'])) {
$targetUser->assignRole('amministratore');
}
session(['impersonator_id' => $actorId]);
Auth::login($targetUser);
session()->save();
$this->redirect('/admin-filament', navigate: false);
if ($record->user_id) {
$this->redirect(route('impersonate.take', ['user' => $record->user_id]), navigate: false);
}
}),

View File

@ -4,6 +4,7 @@
*
* SECURE WRAPPER FOR ADMINER
* - Disabled in Production (APP_ENV=production or APP_DEBUG=false)
* - Supports 1-Click Switching between MySQL Staging and PostgreSQL Consolidato
* - Auto-connects via TCP (127.0.0.1) to avoid Unix Socket Peer Auth failures
* - Strips and hides credentials from URL query parameters to prevent password leaks
*/
@ -53,14 +54,17 @@ function env_get_val($key, $default = '') {
function adminer_object() {
class NetGesconAdminerSecurity extends \Adminer\Adminer {
function name() {
return "NetGescon Database Visualizer";
return "NetGescon Database Visualizer (MySQL / PostgreSQL)";
}
function credentials() {
$dbHost = env_get_val("DB_HOST", "127.0.0.1");
if ($dbHost === "localhost") {
$dbHost = "127.0.0.1";
$driver = $_POST["auth"]["driver"] ?? $_GET["pgsql"] ?? "server";
$dbHost = "127.0.0.1";
if ($driver === "pgsql" || isset($_GET["pgsql"])) {
return array($dbHost, "netgescon", "netgescon_pass");
}
$dbUser = env_get_val("DB_USERNAME", "netgescon_user");
$dbPass = env_get_val("DB_PASSWORD", "NetGescon2024!");
@ -77,29 +81,48 @@ function login($login, $password) {
function loginForm() {
$connection = env_get_val("DB_CONNECTION", "mysql");
$driverVal = ($connection === "pgsql") ? "pgsql" : "server";
$dbUser = env_get_val("DB_USERNAME", "netgescon_user");
$dbPass = env_get_val("DB_PASSWORD", "NetGescon2024!");
$dbName = env_get_val("DB_DATABASE", "netgescon");
$defaultDriver = ($connection === "pgsql") ? "pgsql" : "server";
$mySqlUser = env_get_val("DB_USERNAME", "netgescon_user");
$mySqlPass = env_get_val("DB_PASSWORD", "NetGescon2024!");
$dbName = env_get_val("DB_DATABASE", "netgescon");
echo '<div style="background:#1e293b; color:#f8fafc; padding:16px; border-radius:10px; margin-bottom:15px; font-family:sans-serif; font-size:13px; line-height:1.5; border:1px solid #334155;">';
echo '<strong style="color:#38bdf8; font-size:15px;">🔒 NetGescon Secure DB Console Visualizer</strong><br>';
echo 'Connessione locale (.env): Engine=<strong>' . strtoupper($connection) . '</strong> | DB=<strong>' . $dbName . '</strong> | User=<strong>' . $dbUser . '</strong>.<br>';
echo '<button type="submit" style="margin-top:10px; background:#0284c7; color:#ffffff; font-weight:bold; border:none; padding:8px 16px; border-radius:6px; cursor:pointer;">⚡ ENTRA NEL DATABASE NETGESCON</button>';
echo '<div style="background:#0f172a; color:#f8fafc; padding:18px; border-radius:12px; margin-bottom:18px; font-family:sans-serif; font-size:13px; line-height:1.6; border:1px solid #334155; shadow:0 10px 15px -3px rgba(0,0,0,0.3);">';
echo '<strong style="color:#38bdf8; font-size:16px;">🔒 NetGescon Secure Dual DB Visualizer</strong><br>';
echo 'Seleziona il motore di database su cui operare (TCP 127.0.0.1):<br>';
echo '<div style="margin-top:12px; display:flex; gap:10px; flex-wrap:wrap;">';
echo '<button type="button" onclick="selectEngine(\'mysql\')" style="background:#0284c7; color:#ffffff; font-weight:bold; border:none; padding:9px 16px; border-radius:8px; cursor:pointer; font-size:12px;">🐬 SELEZIONA MYSQL STAGING (' . $mySqlUser . ')</button>';
echo '<button type="button" onclick="selectEngine(\'pgsql\')" style="background:#334155; color:#38bdf8; font-weight:bold; border:1px solid #38bdf8; padding:9px 16px; border-radius:8px; cursor:pointer; font-size:12px;">🐘 SELEZIONA POSTGRESQL (netgescon)</button>';
echo '</div>';
echo '<div style="margin-top:12px;">';
echo '<button type="submit" style="background:#16a34a; color:#ffffff; font-weight:bold; border:none; padding:10px 20px; border-radius:8px; cursor:pointer; font-size:13px; shadow:0 4px 6px -1px rgba(0,0,0,0.1);">⚡ ENTRA ADESSO NEL DATABASE SELEZIONATO</button>';
echo '</div>';
echo '</div>';
echo '<script>
window.addEventListener("DOMContentLoaded", function() {
function selectEngine(type) {
var drv = document.querySelector("select[name=\'auth[driver]\']");
if (drv) { drv.value = "' . $driverVal . '"; if (typeof loginDriver === "function") loginDriver(); }
var srv = document.querySelector("input[name=\'auth[server]\']");
if (srv) srv.value = "127.0.0.1";
var usr = document.querySelector("input[name=\'auth[username]\']");
if (usr) usr.value = "' . $dbUser . '";
var pwd = document.querySelector("input[name=\'auth[password]\']");
if (pwd) pwd.value = "' . $dbPass . '";
var db = document.querySelector("input[name=\'auth[db]\']");
if (db) db.value = "' . $dbName . '";
var db = document.querySelector("input[name=\'auth[db]\']");
if (type === "pgsql") {
if (drv) { drv.value = "pgsql"; if (typeof loginDriver === "function") loginDriver(); }
if (srv) srv.value = "127.0.0.1";
if (usr) usr.value = "netgescon";
if (pwd) pwd.value = "netgescon_pass";
if (db) db.value = "' . $dbName . '";
} else {
if (drv) { drv.value = "server"; if (typeof loginDriver === "function") loginDriver(); }
if (srv) srv.value = "127.0.0.1";
if (usr) usr.value = "' . $mySqlUser . '";
if (pwd) pwd.value = "' . $mySqlPass . '";
if (db) db.value = "' . $dbName . '";
}
}
window.addEventListener("DOMContentLoaded", function() {
selectEngine("' . ($defaultDriver === 'pgsql' ? 'pgsql' : 'mysql') . '");
});
</script>';
return true;

View File

@ -41,6 +41,28 @@
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
// --- Impersonation Take Route ---
Route::get('/admin-filament/impersonate/take/{user}', function (\App\Models\User $user) {
$currentActor = Auth::user();
if (! $currentActor || ! $currentActor->hasRole('super-admin')) {
if (! session('impersonator_id')) {
abort(403, 'Solo un SuperAdmin può impersonare uno studio.');
}
}
$actorId = session('impersonator_id') ?: Auth::id();
if (method_exists($user, 'hasRole') && ! $user->hasAnyRole(['admin', 'amministratore', 'super-admin'])) {
$user->assignRole('amministratore');
}
session(['impersonator_id' => $actorId]);
Auth::guard('web')->login($user, true);
request()->session()->regenerate();
return redirect('/admin-filament');
})->name('impersonate.take');
// --- Impersonation Leave Route ---
Route::get('/admin-filament/impersonate/leave', function () {
$impersonatorId = session('impersonator_id');

View File

@ -1,13 +1,26 @@
# ASCII Wireframe - Gestione Fornitori & Anagrafica Accreditate (/admin-filament/gescon/anagrafica/fornitori)
## 1. VISUALIZZAZIONE DESKTOP (High-Density Multi-Column Grid)
## 0. STICKY HEADER BANNER - IMPERSONIFICAZIONE CONTESTUALE ATTIVA (Se attiva)
```text
+-------------------------------------------------------------------------------------------------------------------+
| NETGESCON - ANAGRAFICA UNIFICATA STABILI & FORNITORI [SuperAdmin: Michele] |
| ⚠️ MODALITÀ IMPERSONIFICAZIONE ATTIVA: Stai operando come STUDIO TORDINI CECILIA (ID #13) [ ↩️ TORNA A SUPER ADMIN ]|
+-------------------------------------------------------------------------------------------------------------------+
```
---
## 1. TAB 1: 🏢 ELENCO FORNITORI ACCREDITATI STUDIO (#13 CECILIA TORDINI)
```text
+-------------------------------------------------------------------------------------------------------------------+
| NETGESCON - ANAGRAFICA UNIFICATA STABILI & FORNITORI [Studio: Cecilia Tordini]|
+-------------------------------------------------------------------------------------------------------------------+
| PATH: Home > NetGescon > Anagrafica > Fornitori & Imprese Accreditate |
+-------------------------------------------------------------------------------------------------------------------+
| BARRA PULSANTINI ICONICI COMPATTI (SENZA SCROLL ORIZZONTALE): |
| [ 🏢 Elenco ] [ ✏️ Modifica (#10) ] [ 📄 Fatture FE ] [ 🔑 Matrice ACL ] |
+-------------------------------------------------------------------------------------------------------------------+
| |
| [ + NUOVO FORNITORE ] [ 🔄 IMPORTA DA LEGACY MDB ] [ 🔍 Cerca per Ragione Sociale, P.IVA, CF, Tag... ] |
| |
@ -16,16 +29,24 @@ ## 1. VISUALIZZAZIONE DESKTOP (High-Density Multi-Column Grid)
| +----+----------------------------+-----------------+-----------------------+-------------------+-----------------+
| | ID | RAGIONE SOCIALE / IMPRESA | P.IVA / C.F. | RECAPITI MULTICANALE | CATEGORIE / TAGS | AZIONI |
| +----+----------------------------+-----------------+-----------------------+-------------------+-----------------+
| | 10 | TECNOREPAIR S.R.L. | 01234567890 | ✉ info@tecnorepair.it | [Idraulico] | [Modifica Scheda|
| | | | | 📱 335-9988776 | [Elettricista] | [Assegna Ticket |
| | 11 | CLEAN & SHINE PULIZIE | 09876543210 | ✉ ordini@cleanshine.it| [Pulizie Parti C.]| [Modifica Scheda|
| | 12 | ASCENSORI ROMA NORD S.A.S. | RMCNSC65L11H501K| ☎ 06-44332211 | [Manut. Ascensore]| [Modifica Scheda|
| | 13 | EDILIZIA SUBALPINA S.R.L. | 05544332211 | ✉ cantiere@subalpina.it| [Edile] [Tetti] | [Modifica Scheda|
| | 10 | TECNOREPAIR S.R.L. | 01234567890 | ✉ info@tecnorepair.it | [Idraulico] | [✏️ Modifica] |
| | | | | 📱 335-9988776 | [Elettricista] | [📄 Fatture FE] |
| | 11 | CLEAN & SHINE PULIZIE | 09876543210 | ✉ ordini@cleanshine.it| [Pulizie Parti C.]| [✏️ Modifica] |
| | 12 | ASCENSORI ROMA NORD S.A.S. | RMCNSC65L11H501K| ☎ 06-44332211 | [Manut. Ascensore]| [✏️ Modifica] |
| | 13 | EDILIZIA SUBALPINA S.R.L. | 05544332211 | ✉ cantiere@subalpina.it| [Edile] [Tetti] | [✏️ Modifica] |
| +----+----------------------------+-----------------+-----------------------+-------------------+-----------------+
| Mostrati 4 di 4 fornitori accreditati per gli stabili dell'amministratore |
| Mostrati 370 di 370 fornitori accreditati per gli stabili dello studio |
+-------------------------------------------------------------------------------------------------------------------+
```
---
## 2. TAB 2: ✏️ SCHEDA DETTAGLIO & EDITING INLINE FORNITORE (#10 TECNOREPAIR S.R.L.)
```text
+-------------------------------------------------------------------------------------------------------------------+
| DETTAGLIO ED EDITING SCHEDA FORNITORE (#10 TECNOREPAIR S.R.L.) |
+-------------------------------------------------------------------------------------------------------------------+
| DETTAGLIO ED EDITING SCHEDA FORNITORE (#10 TECNOREPAIR S.R.L.) |
| |
| [ Ragione Sociale: TECNOREPAIR S.R.L. ] |
| [ Partita IVA: 01234567890 ] [ Codice Fiscale: 01234567890 ] |
| [ Indirizzo: Via Ottaviano 45 ] [ Città: ROMA ] [ CAP: 00192 ] |
@ -41,29 +62,3 @@ ## 1. VISUALIZZAZIONE DESKTOP (High-Density Multi-Column Grid)
| [ SALVA SCHEDA FORNITORE ] [ ANNULLA ] [ ASSEGNA NUOVO TICKET INTERVENTO ] |
+-------------------------------------------------------------------------------------------------------------------+
```
## 2. VISUALIZZAZIONE RESPONSIVE MOBILE (Adaptive Collapsible Card View)
```text
+--------------------------------------------------+
| 📱 NETGESCON FORNITORI [SuperAdmin: M] |
+--------------------------------------------------+
| ANAGRAFICA FORNITORI ACCREDITATI |
| [ + NUOVO FORNITORE ] [ 🔍 Cerca... ] |
+--------------------------------------------------+
| 🛠️ TECNOREPAIR S.R.L. (ID #10) |
| • P.IVA: 01234567890 | Tags: [Idraulico] [Elect] |
| ✉ info@tecnorepair.it | 📱 335-9988776 |
| 🏦 IBAN: IT60X0100503301000000123456 |
| ──────────────────────────────────────────────── |
| AZIONI APPARATO MOBILE: |
| [ ✏️ Modifica Scheda ] |
| [ 🛠️ Assegna Ticket Intervento ] |
| [ 📱 Chiama subito ] [ 📧 Invia Ordine ] |
+--------------------------------------------------+
| 🧹 CLEAN & SHINE PULIZIE (ID #11) |
| • P.IVA: 09876543210 | Tags: [Pulizie] |
| ✉ ordini@cleanshine.it |
| [ ✏️ Modifica Scheda ] |
+--------------------------------------------------+
```

View File

@ -1,45 +1,67 @@
# ASCII Wireframe - Scheda Stabile e Dati Catastali
# ASCII Wireframe - Gestione Stabili Condominiali (/admin-filament/condomini/stabile)
URL: `http://192.168.0.205:8000/admin-filament/condomini/stabile`
## 0. STICKY HEADER BANNER - IMPERSONIFICAZIONE CONTESTUALE ATTIVA (Se attiva)
```text
+-----------------------------------------------------------------------------------------------------------------------+
| NETGESCON · CENTRO STELLA [ Utente: Cecilia Tordini v ] |
+-----------------------------------------------------------------------------------------------------------------------+
| CONDOMINI > SCHEDA STABILE |
| |
| SUPERCONDOMINIO MILIZIE 3 |
| Codice Operatore: 0021 · Viale delle Milizie 3 · Roma |
| [ Rate emesse ] [ Movimenti / Import estratto ] [ Posta stabile ] |
| |
| +-----------------------------------------------------------------------------------------------------------------+ |
| | TAB: [ Dati generali (Active) ] [ Unità ] [ Palazzine ] [ Assicurazioni ] [ Tabelle ] [ Rate ] [ Gestioni ] ... | |
| +-----------------------------------------------------------------------------------------------------------------+ |
| |
| +------------------------------------------------------+ +-------------------------------------------------------+ |
| | INFORMAZIONI GENERALI | | INDIRIZZO COMPLETO | |
| +------------------------------------------------------+ +-------------------------------------------------------+ |
| | ID Stabile: STAB-0021 | | Indirizzo: Viale delle Milizie 3 | |
| | Denominazione: SUPERCONDOMINIO MILIZIE 3 | | Città: Roma | |
| | Codice Fiscale: 80234560589 | | CAP: 00192 | |
| | CF Amministratore: BRNMHL69M11H501K | | Provincia: RM | |
| | Riscaldamento: [ Attivo / Disattivo ] | | Indirizzo Completo: Viale delle Milizie 3, 00192 Roma | |
| +------------------------------------------------------+ +-------------------------------------------------------+ |
| |
| +-----------------------------------------------------------------------------------------------------------------+ |
| | DATI CATASTALI E AMMINISTRATIVI (Da Stabili.mdb e Archivio Consolidato) | |
| +-----------------------------------------------------------------------------------------------------------------+ |
| | CATASTO PRINCIPALE | CONTRIBUTI / INPS | STATISTICHE E PALAZZINE | |
| +------------------------------------------+-------------------------------+--------------------------------------+ |
| | Codice Comune: H501 (Roma) | Posizione INPS: 8493021948 | N. Condomini: 48 | |
| | Foglio: 404 | N. Contribuente: 1029482 | N. Unità: 52 | |
| | Particella: 98 | Codice Destinatario SDI: 00000| N. Palazzine: 4 (A, B, C, D) | |
| | Sezione: H501 | PEC: milizie3@pec.it | | |
| +------------------------------------------+-------------------------------+--------------------------------------+ |
| | RIFERIMENTI CATASTALI AGGIUNTIVI / SECONDARI (Es. Palazzina D o Corpi Separati) [ + Aggiungi Sezione ] | |
| +------------------------------------------+-------------------------------+--------------------------------------+ |
| | - Ref #1: Palazzina D (Corpo Separato) | Foglio: 404 | Particella: 99 | Sezione: H501 | Sub: — | |
| | - Ref #2: Locali Commerciali Seminterrato | Foglio: 404 | Particella: 100 | Sezione: H501 | Sub: — | |
| +-----------------------------------------------------------------------------------------------------------------+ |
+-----------------------------------------------------------------------------------------------------------------------+
+-------------------------------------------------------------------------------------------------------------------+
| ⚠️ MODALITÀ IMPERSONIFICAZIONE ATTIVA: Stai operando come STUDIO TORDINI CECILIA (ID #13) [ ↩️ TORNA A SUPER ADMIN ]|
+-------------------------------------------------------------------------------------------------------------------+
```
---
## 1. TAB 1: 🏢 ELENCO STABILI CONDOMINIALI
```text
+-------------------------------------------------------------------------------------------------------------------+
| NETGESCON - CENTRO STELLA SYSTEM MANAGEMENT [SuperAdmin: Michele] |
+-------------------------------------------------------------------------------------------------------------------+
| PATH: Home > Condomini > Gestione Stabili |
+-------------------------------------------------------------------------------------------------------------------+
| BARRA PULSANTINI ICONICI COMPATTI (SENZA SCROLL ORIZZONTALE): |
| [ 🏢 Elenco ] [ ✏️ Modifica (#15) ] [ 🏛️ Catasto ] [ 🏦 Conti & Casse ] [ 🔑 Matrice ACL ] |
+-------------------------------------------------------------------------------------------------------------------+
| |
| [ + NUOVO STABILE ] [ 🔄 SYNC DA STABILI.MDB ] [ 🔍 Cerca per Codice, Denominazione, Codice Fiscale... ] |
| |
| +------+----------------------------------------+---------------+--------------------------------+----------------+
| | COD. | DENOMINAZIONE STABILE CONDOMINIALE | CODICE FISCALE| BANCA PRINCIPALE & IBAN | CASSE |
| +------+----------------------------------------+---------------+--------------------------------+----------------+
| | 0010 | CATONE 34 - GERMANICO 85 - GRACCHI 32 | 80017140585 | ISTITUTO SAN PAOLO | [CCB] [CCP] |
| | | | | IT26Z0306905077100000013753 | [CON] [CAG] |
| | 0013 | OTTAVIANO 105 - GIULIO CESARE 171 | 80212560587 | BANCO BPM | [CON] |
| | | | | IT88A0503403214000000000707 | |
| | 0016 | GERMANICO 96 | 80115200588 | BANCA DEL FUCINO | [CCB] [CCP] |
| | | | | IT48W0312403203000000233378 | [CON] |
| | 0021 | SUPERCONDOMINIO MILIZIE 3 | 97487690584 | UNICREDIT | [CCB] [CON] |
| | | | | IT30Q0200805170000104951005 | |
| +------+----------------------------------------+---------------+--------------------------------+----------------+
| Mostrati 16 di 16 stabili censiti gestiti dallo studio |
+-------------------------------------------------------------------------------------------------------------------+
```
---
## 2. TAB 2: ✏️ SCHEDA DETTAGLIO & EDITING INLINE STABILE (#0010 CATONE 34)
```text
+-------------------------------------------------------------------------------------------------------------------+
| DETTAGLIO ED EDITING SCHEDA STABILE CONDOMINIALE (#0010 CATONE 34 - GERMANICO 85 - GRACCHI 32) |
+-------------------------------------------------------------------------------------------------------------------+
| [ Codice Stabile: 0010 ] [ Codice Fiscale: 80017140585 ] |
| [ Denominazione: CATONE 34 - GERMANICO 85 - GRACCHI 32 ] |
| [ Indirizzo: VIA CATONE 34 ] [ Città: ROMA ] [ CAP: 00192 ] [ PR: RM ] |
| [ Num. Unità Immobiliari: 48 ] [ Num. Scale: 3 ] [ Anno Gestione Attivo: 2024 ] |
| |
| BANCA PRINCIPALE E COORDINATE BANCARIE: |
| • Istituto Bancario: ISTITUTO SAN PAOLO |
| • IBAN Principale: IT26Z0306905077100000013753 |
| |
| TABELLA ANAGR_CASSE AGGANCIATE: |
| • [CCB] Conto Corrente Bancario (Saldo: 0.00 EUR) |
| • [CCP] C corrente Postale n. 50581008 (Saldo: -2861.24 EUR) |
| • [CON] Cassa Contanti (Saldo: 0.00 EUR) |
| |
| [ SALVA SCHEDA STABILE ] [ ANNULLA ] [ 🏛️ APRI CATASTO STABILE ] |
+-------------------------------------------------------------------------------------------------------------------+
```