[backend/api] Allow updating remote emojis but limited to sensitive status

This commit is contained in:
pancakes 2025-03-07 15:10:44 +10:00 committed by Laura Hausmann
parent d160d7337e
commit af580eeed1
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 14 additions and 2 deletions

View file

@ -206,7 +206,7 @@ public class EmojiController(
[Authorize("role:moderator")]
[Consumes(MediaTypeNames.Application.Json)]
[ProducesResults(HttpStatusCode.OK)]
[ProducesErrors(HttpStatusCode.NotFound)]
[ProducesErrors(HttpStatusCode.BadRequest, HttpStatusCode.NotFound)]
public async Task<EmojiResponse> UpdateEmoji(string id, UpdateEmojiRequest request)
{
var emoji = await emojiSvc.UpdateLocalEmojiAsync(id, request.Name, request.Tags, request.Category,

View file

@ -229,7 +229,19 @@ public partial class EmojiService(
{
var emoji = await db.Emojis.FirstOrDefaultAsync(p => p.Id == id);
if (emoji == null) return null;
if (emoji.Host != null) return null;
if (emoji.Host != null)
{
// Only allow changing remote emoji sensitive status
if (!sensitive.HasValue)
throw GracefulException.BadRequest("Only sensitive can be updated on remote emojis");
emoji.Sensitive = sensitive.Value;
emoji.UpdatedAt = DateTime.UtcNow;
await db.SaveChangesAsync();
return emoji;
}
emoji.UpdatedAt = DateTime.UtcNow;