gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

emojidelete.go (3285B)


      1 // GoToSocial
      2 // Copyright (C) GoToSocial Authors admin@gotosocial.org
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18 package admin
     19 
     20 import (
     21 	"errors"
     22 	"fmt"
     23 	"net/http"
     24 
     25 	"github.com/gin-gonic/gin"
     26 	apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
     27 	"github.com/superseriousbusiness/gotosocial/internal/gtserror"
     28 	"github.com/superseriousbusiness/gotosocial/internal/oauth"
     29 )
     30 
     31 // EmojiDELETEHandler swagger:operation DELETE /api/v1/admin/custom_emojis/{id} emojiDelete
     32 //
     33 // Delete a **local** emoji with the given ID from the instance.
     34 //
     35 // Emoji with the given ID will no longer be available to use on the instance.
     36 //
     37 // If you just want to update the emoji image instead, use the `/api/v1/admin/custom_emojis/{id}` PATCH route.
     38 //
     39 // To disable emojis from **remote** instances, use the `/api/v1/admin/custom_emojis/{id}` PATCH route.
     40 //
     41 //	---
     42 //	tags:
     43 //	- admin
     44 //
     45 //	produces:
     46 //	- application/json
     47 //
     48 //	parameters:
     49 //	-
     50 //		name: id
     51 //		type: string
     52 //		description: The id of the emoji.
     53 //		in: path
     54 //		required: true
     55 //
     56 //	security:
     57 //	- OAuth2 Bearer:
     58 //		- admin
     59 //
     60 //	responses:
     61 //		'200':
     62 //			description: The deleted emoji will be returned to the caller in case further processing is necessary.
     63 //			schema:
     64 //				"$ref": "#/definitions/adminEmoji"
     65 //		'400':
     66 //			description: bad request
     67 //		'401':
     68 //			description: unauthorized
     69 //		'403':
     70 //			description: forbidden
     71 //		'404':
     72 //			description: not found
     73 //		'406':
     74 //			description: not acceptable
     75 //		'500':
     76 //			description: internal server error
     77 func (m *Module) EmojiDELETEHandler(c *gin.Context) {
     78 	authed, err := oauth.Authed(c, true, true, true, true)
     79 	if err != nil {
     80 		apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
     81 		return
     82 	}
     83 
     84 	if !*authed.User.Admin {
     85 		err := fmt.Errorf("user %s not an admin", authed.User.ID)
     86 		apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
     87 		return
     88 	}
     89 
     90 	if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
     91 		apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
     92 		return
     93 	}
     94 
     95 	emojiID := c.Param(IDKey)
     96 	if emojiID == "" {
     97 		err := errors.New("no emoji id specified")
     98 		apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
     99 		return
    100 	}
    101 
    102 	emoji, errWithCode := m.processor.Admin().EmojiDelete(c.Request.Context(), emojiID)
    103 	if errWithCode != nil {
    104 		apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
    105 		return
    106 	}
    107 
    108 	c.JSON(http.StatusOK, emoji)
    109 }