[backend/api] Prevent moderation actions on the authenticated user
This commit is contained in:
parent
5005d81ee7
commit
0496df2c9e
1 changed files with 13 additions and 4 deletions
|
@ -34,6 +34,9 @@ public class ModerationController(DatabaseContext db, NoteService noteSvc, UserS
|
|||
var user = await db.Users.IncludeCommonProperties().FirstOrDefaultAsync(p => p.Id == id && !p.IsSystemUser) ??
|
||||
throw GracefulException.NotFound("User not found");
|
||||
|
||||
if (user == HttpContext.GetUserOrFail())
|
||||
throw GracefulException.BadRequest("You cannot suspend yourself.");
|
||||
|
||||
await userSvc.SuspendUserAsync(user);
|
||||
}
|
||||
|
||||
|
@ -45,6 +48,9 @@ public class ModerationController(DatabaseContext db, NoteService noteSvc, UserS
|
|||
var user = await db.Users.IncludeCommonProperties().FirstOrDefaultAsync(p => p.Id == id && !p.IsSystemUser) ??
|
||||
throw GracefulException.NotFound("User not found");
|
||||
|
||||
if (user == HttpContext.GetUserOrFail())
|
||||
throw GracefulException.BadRequest("You cannot unsuspend yourself.");
|
||||
|
||||
await userSvc.UnsuspendUserAsync(user);
|
||||
}
|
||||
|
||||
|
@ -56,6 +62,9 @@ public class ModerationController(DatabaseContext db, NoteService noteSvc, UserS
|
|||
var user = await db.Users.IncludeCommonProperties().FirstOrDefaultAsync(p => p.Id == id && !p.IsSystemUser) ??
|
||||
throw GracefulException.NotFound("User not found");
|
||||
|
||||
if (user == HttpContext.GetUserOrFail())
|
||||
throw GracefulException.BadRequest("You cannot delete yourself.");
|
||||
|
||||
await userSvc.DeleteUserAsync(user);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue