mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: add delete functionality for pastes with authorization check
This commit is contained in:
@@ -64,6 +64,7 @@ namespace SharpbinV3.Server.Controllers
|
|||||||
paste.Syntax,
|
paste.Syntax,
|
||||||
paste.Visibility,
|
paste.Visibility,
|
||||||
paste.ExpiresAt,
|
paste.ExpiresAt,
|
||||||
|
paste.EditedAt,
|
||||||
Author = paste.User != null && paste.User.Visibility == 0 ? new
|
Author = paste.User != null && paste.User.Visibility == 0 ? new
|
||||||
{
|
{
|
||||||
paste.User.UID,
|
paste.User.UID,
|
||||||
@@ -157,6 +158,21 @@ namespace SharpbinV3.Server.Controllers
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
[HttpDelete]
|
||||||
|
[Route("{id}")]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<IActionResult> DeletePaste(string id)
|
||||||
|
{
|
||||||
|
var paste = await _pasteService.Get(id);
|
||||||
|
if (paste == null) return NotFound();
|
||||||
|
var httpUser = HttpContext.User;
|
||||||
|
var userUUID = httpUser?.FindFirst("UUID")?.Value;
|
||||||
|
if (userUUID == null || paste.AuthorUUID != Guid.Parse(userUUID))
|
||||||
|
return Forbid();
|
||||||
|
bool result = await _pasteService.Delete(paste);
|
||||||
|
if (!result) return NotFound();
|
||||||
|
return Ok(new { message = "Paste deleted successfully." });
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("create/options")]
|
[Route("create/options")]
|
||||||
|
|||||||
Reference in New Issue
Block a user