Private
Public Access
cambios en unificar los permisos de empresa con los gfenerales
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
7ba7d379ec
commit
f2cf7927eb
25 files changed
+104
-557
No files matched your search
@@ -42,12 +42,6 @@ type RepositorioEmpresa interface {
|
||||
ObtenerInvitacionPorToken(token string) (*models_seguridad.InvitacionEmpresa, error)
|
||||
MarcarInvitacionUsada(id uint) error
|
||||
EliminarInvitacion(empresaID, id uint) error
|
||||
|
||||
PlataformaAdminDe(usuarioID uint) (*models_seguridad.PlataformaAdmin, error)
|
||||
ListarPlataformaAdmins() ([]models_seguridad.PlataformaAdmin, error)
|
||||
ContarPlataformaAdmins() (int64, error)
|
||||
AgregarPlataformaAdmin(usuarioID uint, rol models_seguridad.RolPlataforma) error
|
||||
QuitarPlataformaAdmin(usuarioID uint) error
|
||||
}
|
||||
|
||||
type repositorioEmpresa struct {
|
||||
@@ -407,50 +401,6 @@ func (r *repositorioEmpresa) EliminarInvitacion(empresaID, id uint) error {
|
||||
Delete(&models_seguridad.InvitacionEmpresa{}).Error
|
||||
}
|
||||
|
||||
func (r *repositorioEmpresa) PlataformaAdminDe(usuarioID uint) (*models_seguridad.PlataformaAdmin, error) {
|
||||
var admin models_seguridad.PlataformaAdmin
|
||||
if err := r.db.Where("usuario_id = ? AND activo = ?", usuarioID, true).
|
||||
First(&admin).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &admin, nil
|
||||
}
|
||||
|
||||
func (r *repositorioEmpresa) ListarPlataformaAdmins() ([]models_seguridad.PlataformaAdmin, error) {
|
||||
var admins []models_seguridad.PlataformaAdmin
|
||||
err := r.db.Preload("Usuario").Order("created_at ASC").Find(&admins).Error
|
||||
return admins, err
|
||||
}
|
||||
|
||||
func (r *repositorioEmpresa) ContarPlataformaAdmins() (int64, error) {
|
||||
var total int64
|
||||
err := r.db.Model(&models_seguridad.PlataformaAdmin{}).Where("activo = ?", true).Count(&total).Error
|
||||
return total, err
|
||||
}
|
||||
|
||||
func (r *repositorioEmpresa) AgregarPlataformaAdmin(usuarioID uint, rol models_seguridad.RolPlataforma) error {
|
||||
if rol != models_seguridad.RolSuperadmin && rol != models_seguridad.RolSoporte {
|
||||
rol = models_seguridad.RolSuperadmin
|
||||
}
|
||||
var admin models_seguridad.PlataformaAdmin
|
||||
err := r.db.Where("usuario_id = ?", usuarioID).First(&admin).Error
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return r.db.Create(&models_seguridad.PlataformaAdmin{
|
||||
UsuarioID: usuarioID,
|
||||
Rol: rol,
|
||||
Activo: true,
|
||||
}).Error
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return r.db.Model(&admin).Updates(map[string]any{"rol": rol, "activo": true}).Error
|
||||
}
|
||||
|
||||
func (r *repositorioEmpresa) QuitarPlataformaAdmin(usuarioID uint) error {
|
||||
return r.db.Where("usuario_id = ?", usuarioID).Delete(&models_seguridad.PlataformaAdmin{}).Error
|
||||
}
|
||||
|
||||
func (r *repositorioEmpresa) slugDisponible(slug, nombre string) string {
|
||||
base := config.Slugify(slug)
|
||||
if base == "" {
|
||||
|
||||
Reference in new issue
Block a user