[feature] Add emoji DELETE handler at /api/v1/admin/custom_emojis (#913)

* add emoji DELETE handler

* no need to process error (thanks kim)

* don't double check if user is admin

* add missing security annotation
This commit is contained in:
tobi 2022-10-14 17:30:04 +02:00 committed by GitHub
commit f7416d6e94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 369 additions and 0 deletions

View file

@ -68,6 +68,43 @@ func (e *emojiDB) UpdateEmoji(ctx context.Context, emoji *gtsmodel.Emoji, column
return emoji, nil
}
func (e *emojiDB) DeleteEmojiByID(ctx context.Context, id string) db.Error {
if err := e.conn.RunInTx(ctx, func(tx bun.Tx) error {
// delete links between this emoji and any statuses that use it
if _, err := tx.
NewDelete().
TableExpr("? AS ?", bun.Ident("status_to_emojis"), bun.Ident("status_to_emoji")).
Where("? = ?", bun.Ident("status_to_emoji.emoji_id"), id).
Exec(ctx); err != nil {
return err
}
// delete links between this emoji and any accounts that use it
if _, err := tx.
NewDelete().
TableExpr("? AS ?", bun.Ident("account_to_emojis"), bun.Ident("account_to_emoji")).
Where("? = ?", bun.Ident("account_to_emoji.emoji_id"), id).
Exec(ctx); err != nil {
return err
}
if _, err := tx.
NewDelete().
TableExpr("? AS ?", bun.Ident("emojis"), bun.Ident("emoji")).
Where("? = ?", bun.Ident("emoji.id"), id).
Exec(ctx); err != nil {
return e.conn.ProcessError(err)
}
return nil
}); err != nil {
return err
}
e.cache.Invalidate(id)
return nil
}
func (e *emojiDB) GetEmojis(ctx context.Context, domain string, includeDisabled bool, includeEnabled bool, shortcode string, maxShortcodeDomain string, minShortcodeDomain string, limit int) ([]*gtsmodel.Emoji, db.Error) {
emojiIDs := []string{}