mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[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:
@@ -41,6 +41,7 @@ type BunDBStandardTestSuite struct {
|
||||
testTags map[string]*gtsmodel.Tag
|
||||
testMentions map[string]*gtsmodel.Mention
|
||||
testFollows map[string]*gtsmodel.Follow
|
||||
testEmojis map[string]*gtsmodel.Emoji
|
||||
}
|
||||
|
||||
func (suite *BunDBStandardTestSuite) SetupSuite() {
|
||||
@@ -54,6 +55,7 @@ func (suite *BunDBStandardTestSuite) SetupSuite() {
|
||||
suite.testTags = testrig.NewTestTags()
|
||||
suite.testMentions = testrig.NewTestMentions()
|
||||
suite.testFollows = testrig.NewTestFollows()
|
||||
suite.testEmojis = testrig.NewTestEmojis()
|
||||
}
|
||||
|
||||
func (suite *BunDBStandardTestSuite) SetupTest() {
|
||||
|
@@ -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{}
|
||||
|
||||
|
@@ -38,6 +38,17 @@ func (suite *EmojiTestSuite) TestGetUseableEmojis() {
|
||||
suite.Equal("rainbow", emojis[0].Shortcode)
|
||||
}
|
||||
|
||||
func (suite *EmojiTestSuite) TestDeleteEmojiByID() {
|
||||
testEmoji := suite.testEmojis["rainbow"]
|
||||
|
||||
err := suite.db.DeleteEmojiByID(context.Background(), testEmoji.ID)
|
||||
suite.NoError(err)
|
||||
|
||||
dbEmoji, err := suite.db.GetEmojiByID(context.Background(), testEmoji.ID)
|
||||
suite.Nil(dbEmoji)
|
||||
suite.ErrorIs(err, db.ErrNoEntries)
|
||||
}
|
||||
|
||||
func (suite *EmojiTestSuite) TestGetEmojiByStaticURL() {
|
||||
emoji, err := suite.db.GetEmojiByStaticURL(context.Background(), "http://localhost:8080/fileserver/01F8MH17FWEB39HZJ76B6VXSKF/emoji/static/01F8MH9H8E4VG3KDYJR9EGPXCQ.png")
|
||||
suite.NoError(err)
|
||||
|
@@ -35,6 +35,8 @@ type Emoji interface {
|
||||
// UpdateEmoji updates the given columns of one emoji.
|
||||
// If no columns are specified, every column is updated.
|
||||
UpdateEmoji(ctx context.Context, emoji *gtsmodel.Emoji, columns ...string) (*gtsmodel.Emoji, Error)
|
||||
// DeleteEmojiByID deletes one emoji by its database ID.
|
||||
DeleteEmojiByID(ctx context.Context, id string) Error
|
||||
// GetUseableEmojis gets all emojis which are useable by accounts on this instance.
|
||||
GetUseableEmojis(ctx context.Context) ([]*gtsmodel.Emoji, Error)
|
||||
// GetEmojis gets emojis based on given parameters. Useful for admin actions.
|
||||
|
Reference in New Issue
Block a user