Fix: Usuarios Admin No Pueden Tener Avisos Propios
This commit is contained in:
@@ -452,7 +452,11 @@ public class AdminController : ControllerBase
|
|||||||
if (string.IsNullOrEmpty(q)) return Ok(new List<object>());
|
if (string.IsNullOrEmpty(q)) return Ok(new List<object>());
|
||||||
|
|
||||||
var users = await _context.Users
|
var users = await _context.Users
|
||||||
.Where(u => (u.Email ?? "").Contains(q) || (u.UserName ?? "").Contains(q) || (u.FirstName ?? "").Contains(q) || (u.LastName ?? "").Contains(q))
|
.Where(u =>
|
||||||
|
((u.Email ?? "").Contains(q) || (u.UserName ?? "").Contains(q) || (u.FirstName ?? "").Contains(q) || (u.LastName ?? "").Contains(q))
|
||||||
|
&&
|
||||||
|
u.UserType != 3 // Excluir usuarios tipo 3 de la búsqueda para asignar avisos, ya que no pueden ser asignados a nuevos avisos en V2.
|
||||||
|
)
|
||||||
.Take(10)
|
.Take(10)
|
||||||
.Select(u => new { u.UserID, u.UserName, u.Email, u.FirstName, u.LastName, u.PhoneNumber, u.IsBlocked })
|
.Select(u => new { u.UserID, u.UserName, u.Email, u.FirstName, u.LastName, u.PhoneNumber, u.IsBlocked })
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|||||||
@@ -349,10 +349,25 @@ public class AdsV2Controller : ControllerBase
|
|||||||
{
|
{
|
||||||
if (request.TargetUserID.HasValue)
|
if (request.TargetUserID.HasValue)
|
||||||
{
|
{
|
||||||
|
// Validación adicional: Asegurar que el ID seleccionado no sea Admin (por seguridad extra)
|
||||||
|
var targetUser = await _context.Users.FindAsync(request.TargetUserID.Value);
|
||||||
|
if (targetUser != null && targetUser.UserType == 3)
|
||||||
|
{
|
||||||
|
return BadRequest("No se puede asignar un aviso a una cuenta de Administrador.");
|
||||||
|
}
|
||||||
finalUserId = request.TargetUserID.Value;
|
finalUserId = request.TargetUserID.Value;
|
||||||
}
|
}
|
||||||
else if (!string.IsNullOrEmpty(request.GhostUserEmail))
|
else if (!string.IsNullOrEmpty(request.GhostUserEmail))
|
||||||
{
|
{
|
||||||
|
// Verificamos si el email escrito manualmente pertenece a un Admin existente
|
||||||
|
var existingAdmin = await _context.Users
|
||||||
|
.AnyAsync(u => u.Email == request.GhostUserEmail && u.UserType == 3);
|
||||||
|
|
||||||
|
if (existingAdmin)
|
||||||
|
{
|
||||||
|
return BadRequest($"El correo '{request.GhostUserEmail}' pertenece a un Administrador. No puedes asignar avisos a administradores.");
|
||||||
|
}
|
||||||
|
|
||||||
// Pasamos nombre y apellido por separado
|
// Pasamos nombre y apellido por separado
|
||||||
var ghost = await _identityService.CreateGhostUserAsync(
|
var ghost = await _identityService.CreateGhostUserAsync(
|
||||||
request.GhostUserEmail,
|
request.GhostUserEmail,
|
||||||
|
|||||||
Reference in New Issue
Block a user