feat: pagina principal configurable por rol (HomeUrl)

This commit is contained in:
Lizandro Guarnizo
2026-07-06 23:05:02 -05:00
parent 7d27240f27
commit 9a3a5d4b25
5 changed files with 50 additions and 5 deletions
+1
View File
@@ -13,6 +13,7 @@ type Roles struct {
CreatedAt time.Time `json:"created_at" gorm:"column:created_at"` CreatedAt time.Time `json:"created_at" gorm:"column:created_at"`
Description string `json:"description" gorm:"column:description"` Description string `json:"description" gorm:"column:description"`
Name string `json:"name" gorm:"column:name"` Name string `json:"name" gorm:"column:name"`
HomeUrl string `json:"home_url" gorm:"column:home_url"`
EsPortalCliente bool `json:"es_portal_cliente" gorm:"column:es_portal_cliente;default:false"` EsPortalCliente bool `json:"es_portal_cliente" gorm:"column:es_portal_cliente;default:false"`
EsPortalPartner bool `json:"es_portal_partner" gorm:"column:es_portal_partner;default:false"` EsPortalPartner bool `json:"es_portal_partner" gorm:"column:es_portal_partner;default:false"`
Submodules []Submodules `json:"submodules" gorm:"many2many:roles_submodules"` Submodules []Submodules `json:"submodules" gorm:"many2many:roles_submodules"`
+1 -2
View File
@@ -190,8 +190,7 @@ func GetUserByUsuario(usuario string) (*Users, error) {
var user Users var user Users
fmt.Println(usuario) // Verifica el usuario recibido fmt.Println(usuario) // Verifica el usuario recibido
db := app.Http.Database.DB.Model(&Users{}) db := app.Http.Database.DB.Model(&Users{})
// Usamos 1 explícitamente para indicar que el estado debe ser "activo" if err := db.Where("nombre_usuario = ? AND email_verified = ? AND estado = ?", usuario, true, true).Preload("Role").First(&user).Error; err != nil {
if err := db.Where("nombre_usuario = ? AND email_verified = ? AND estado = ?", usuario, true, true).First(&user).Error; err != nil {
return nil, err return nil, err
} }
+37
View File
@@ -52,6 +52,7 @@
<th class="py-2 px-4 border-b">Descripción</th> <th class="py-2 px-4 border-b">Descripción</th>
<th class="py-2 px-4 border-b">Submodulos</th> <th class="py-2 px-4 border-b">Submodulos</th>
<th class="py-2 px-4 border-b w-28">Portal</th> <th class="py-2 px-4 border-b w-28">Portal</th>
<th class="py-2 px-4 border-b w-40">Página principal</th>
<th class="py-2 px-4 border-b w-32"></th> <th class="py-2 px-4 border-b w-32"></th>
</tr> </tr>
</thead> </thead>
@@ -97,6 +98,9 @@
</template> </template>
</div> </div>
</td> </td>
<td class="py-3 text-xs px-4 border-b">
<span x-text="registro.home_url || 'Predeterminada'" class="text-xs text-slate-500"></span>
</td>
<td class="py-3 text-xs px-4 border-b "> <td class="py-3 text-xs px-4 border-b ">
<div class="flex justify-between space-x-1"> <div class="flex justify-between space-x-1">
<button <button
@@ -118,6 +122,7 @@
Submodules = [...registro.submodules]; Submodules = [...registro.submodules];
EsPortalCliente = registro.es_portal_cliente || false; EsPortalCliente = registro.es_portal_cliente || false;
EsPortalPartner = registro.es_portal_partner || false; EsPortalPartner = registro.es_portal_partner || false;
HomeUrl = registro.home_url || '';
modulos.forEach(modulo => { modulos.forEach(modulo => {
modulo.submodules.forEach(submodulo => { modulo.submodules.forEach(submodulo => {
submodulo.checked = Submodules.some(sm => sm.ID === submodulo.ID); submodulo.checked = Submodules.some(sm => sm.ID === submodulo.ID);
@@ -235,6 +240,20 @@
</label> </label>
</div> </div>
</div> </div>
<div class="mt-4 p-3 border rounded-md bg-slate-50">
<label class="font-semibold text-sm mb-2 block" for="editHomeUrl">Página principal después del login</label>
<select id="editHomeUrl" x-model="HomeUrl"
class="border border-gray-300 rounded w-full p-2 text-sm">
<option value="">Predeterminada (/app/servidor)</option>
<template x-for="modulo in modulos" :key="modulo.ID">
<optgroup :label="modulo.title">
<template x-for="submodulo in modulo.submodules" :key="submodulo.ID">
<option :value="submodulo.url" x-text="submodulo.title + ' (' + submodulo.url + ')'"></option>
</template>
</optgroup>
</template>
</select>
</div>
<div class="mt-4 flex justify-between"> <div class="mt-4 flex justify-between">
<button type="submit" class="bg-[#8eb02f] text-white px-4 py-2 rounded">Guardar Cambios</button> <button type="submit" class="bg-[#8eb02f] text-white px-4 py-2 rounded">Guardar Cambios</button>
<button type="button" class="bg-gray-600 text-white px-4 py-2 rounded" <button type="button" class="bg-gray-600 text-white px-4 py-2 rounded"
@@ -293,6 +312,20 @@
</div> </div>
</div> </div>
<div class="mt-4 p-3 border rounded-md bg-slate-50">
<label class="font-semibold text-sm mb-2 block" for="addHomeUrl">Página principal después del login</label>
<select id="addHomeUrl" x-model="newHomeUrl"
class="border border-gray-300 rounded w-full p-2 text-sm">
<option value="">Predeterminada (/app/servidor)</option>
<template x-for="modulo in modulos" :key="modulo.ID">
<optgroup :label="modulo.title">
<template x-for="submodulo in modulo.submodules" :key="submodulo.ID">
<option :value="submodulo.url" x-text="submodulo.title + ' (' + submodulo.url + ')'"></option>
</template>
</optgroup>
</template>
</select>
</div>
<div class="mt-4 flex justify-between"> <div class="mt-4 flex justify-between">
<button type="submit" class="bg-[#8eb02f] text-white px-4 py-2 rounded">Guardar</button> <button type="submit" class="bg-[#8eb02f] text-white px-4 py-2 rounded">Guardar</button>
<button type="button" class="bg-gray-600 text-white px-4 py-2 rounded" <button type="button" class="bg-gray-600 text-white px-4 py-2 rounded"
@@ -332,11 +365,13 @@
newDescription: '', newDescription: '',
newEsPortalCliente: false, newEsPortalCliente: false,
newEsPortalPartner: false, newEsPortalPartner: false,
newHomeUrl: '',
Name: '', Name: '',
Description: '', Description: '',
EsPortalCliente: false, EsPortalCliente: false,
EsPortalPartner: false, EsPortalPartner: false,
HomeUrl: '',
modulos: [], modulos: [],
Submodules: [], Submodules: [],
submodulos: [], submodulos: [],
@@ -460,6 +495,7 @@
description: this.newDescription, description: this.newDescription,
es_portal_cliente: this.newEsPortalCliente, es_portal_cliente: this.newEsPortalCliente,
es_portal_partner: this.newEsPortalPartner, es_portal_partner: this.newEsPortalPartner,
home_url: this.newHomeUrl,
submodules: selectedSubmodules.flatMap(modulo => modulo.submodules) submodules: selectedSubmodules.flatMap(modulo => modulo.submodules)
}; };
@@ -520,6 +556,7 @@
description: this.Description, description: this.Description,
es_portal_cliente: this.EsPortalCliente, es_portal_cliente: this.EsPortalCliente,
es_portal_partner: this.EsPortalPartner, es_portal_partner: this.EsPortalPartner,
home_url: this.HomeUrl,
submodules: this.submodulos submodules: this.submodulos
}) })
}) })
+6 -2
View File
@@ -37,8 +37,12 @@ func LoginPost(c *fiber.Ctx) error {
return c.Redirect("/login?error=" + url.QueryEscape(err.Error())) return c.Redirect("/login?error=" + url.QueryEscape(err.Error()))
} }
// Si todo está bien, redirige al inicio de la app // Redirige según la página principal del rol, o por defecto a /app/servidor
return c.Redirect("/app/servidor") homeUrl := "/app/servidor"
if user.Role.HomeUrl != "" {
homeUrl = user.Role.HomeUrl
}
return c.Redirect(homeUrl)
} }
var store = session.New() var store = session.New()
+5 -1
View File
@@ -11,7 +11,11 @@ import (
func RedirectToHomePageOnLogin(c *fiber.Ctx) error { func RedirectToHomePageOnLogin(c *fiber.Ctx) error {
if auth.IsLoggedIn(c) { if auth.IsLoggedIn(c) {
return c.Redirect("/app/dashboard") user, err := auth.User(c)
if err == nil && user != nil && user.Role.HomeUrl != "" {
return c.Redirect(user.Role.HomeUrl)
}
return c.Redirect("/app/servidor")
} }
// Si tiene sesión de portal activa, ir al portal // Si tiene sesión de portal activa, ir al portal
if user, err := auth.PortalUser(c); err == nil && user != nil { if user, err := auth.PortalUser(c); err == nil && user != nil {