up
This commit is contained in:
@@ -78,7 +78,7 @@ func PortalDashboard(c *fiber.Ctx) error {
|
||||
"portalUser": fullUser,
|
||||
"proyectos": proyectos,
|
||||
"grupos": grupos,
|
||||
"isPartner": fullUser.Rol == "partner",
|
||||
"isPartner": fullUser.Rol == "partner" || (fullUser.Role != nil && fullUser.Role.EsPortalPartner),
|
||||
}, "layouts/portal")
|
||||
}
|
||||
|
||||
|
||||
@@ -29,12 +29,14 @@ func LoadPortalUsuarios(c *fiber.Ctx) error {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
clientes, _, _ := models.GetAllClientes(200, 0, "")
|
||||
portalRoles, _ := models.GetPortalRoles()
|
||||
return c.JSON(fiber.Map{
|
||||
"items": items,
|
||||
"total": total,
|
||||
"totalPages": int(math.Ceil(float64(total) / float64(limit))),
|
||||
"page": page,
|
||||
"clientes": clientes,
|
||||
"items": items,
|
||||
"total": total,
|
||||
"totalPages": int(math.Ceil(float64(total) / float64(limit))),
|
||||
"page": page,
|
||||
"clientes": clientes,
|
||||
"portalRoles": portalRoles,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -44,7 +46,7 @@ func CreatePortalUsuario(c *fiber.Ctx) error {
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
ClienteID *uint `json:"cliente_id"`
|
||||
Rol string `json:"rol"`
|
||||
RoleID *uint `json:"role_id"`
|
||||
Notas string `json:"notas"`
|
||||
}
|
||||
var req Req
|
||||
@@ -58,15 +60,23 @@ func CreatePortalUsuario(c *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": "Error al hashear contraseña"})
|
||||
}
|
||||
if req.Rol == "" {
|
||||
req.Rol = "cliente"
|
||||
// Derivar Rol del tipo de rol seleccionado
|
||||
rol := "cliente"
|
||||
if req.RoleID != nil {
|
||||
var role models.Roles
|
||||
if err := app.Http.Database.DB.First(&role, *req.RoleID).Error; err == nil {
|
||||
if role.EsPortalPartner {
|
||||
rol = "partner"
|
||||
}
|
||||
}
|
||||
}
|
||||
u := &models.PortalUser{
|
||||
Nombre: req.Nombre,
|
||||
Email: strings.ToLower(strings.TrimSpace(req.Email)),
|
||||
Password: hashed,
|
||||
ClienteID: req.ClienteID,
|
||||
Rol: req.Rol,
|
||||
RoleID: req.RoleID,
|
||||
Rol: rol,
|
||||
Activo: true,
|
||||
Notas: req.Notas,
|
||||
}
|
||||
@@ -87,7 +97,7 @@ func UpdatePortalUsuario(c *fiber.Ctx) error {
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
ClienteID *uint `json:"cliente_id"`
|
||||
Rol string `json:"rol"`
|
||||
RoleID *uint `json:"role_id"`
|
||||
Activo bool `json:"activo"`
|
||||
Notas string `json:"notas"`
|
||||
}
|
||||
@@ -95,11 +105,22 @@ func UpdatePortalUsuario(c *fiber.Ctx) error {
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return c.Status(400).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
// Derivar Rol del tipo de rol seleccionado
|
||||
rol := "cliente"
|
||||
if req.RoleID != nil {
|
||||
var role models.Roles
|
||||
if err := app.Http.Database.DB.First(&role, *req.RoleID).Error; err == nil {
|
||||
if role.EsPortalPartner {
|
||||
rol = "partner"
|
||||
}
|
||||
}
|
||||
}
|
||||
u := &models.PortalUser{
|
||||
Nombre: req.Nombre,
|
||||
Email: strings.ToLower(strings.TrimSpace(req.Email)),
|
||||
ClienteID: req.ClienteID,
|
||||
Rol: req.Rol,
|
||||
RoleID: req.RoleID,
|
||||
Rol: rol,
|
||||
Activo: req.Activo,
|
||||
Notas: req.Notas,
|
||||
}
|
||||
@@ -109,7 +130,7 @@ func UpdatePortalUsuario(c *fiber.Ctx) error {
|
||||
}
|
||||
// Actualizar password solo si se envió
|
||||
if strings.TrimSpace(req.Password) != "" {
|
||||
hashed, err := app.Http.Hash.Create(req.Password)
|
||||
hashed, err := app.Http.Hash.Create(req.Password)
|
||||
if err == nil {
|
||||
_ = models.UpdatePortalUserPassword(uint(id), hashed)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user