gtsocial-umbx

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

domainblockdelete.go (2994B)


      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 // DomainBlockDELETEHandler swagger:operation DELETE /api/v1/admin/domain_blocks/{id} domainBlockDelete
     32 //
     33 // Delete domain block with the given ID.
     34 //
     35 //	---
     36 //	tags:
     37 //	- admin
     38 //
     39 //	produces:
     40 //	- application/json
     41 //
     42 //	parameters:
     43 //	-
     44 //		name: id
     45 //		type: string
     46 //		description: The id of the domain block.
     47 //		in: path
     48 //		required: true
     49 //
     50 //	security:
     51 //	- OAuth2 Bearer:
     52 //		- admin
     53 //
     54 //	responses:
     55 //		'200':
     56 //			description: The domain block that was just deleted.
     57 //			schema:
     58 //				"$ref": "#/definitions/domainBlock"
     59 //		'400':
     60 //			description: bad request
     61 //		'401':
     62 //			description: unauthorized
     63 //		'403':
     64 //			description: forbidden
     65 //		'404':
     66 //			description: not found
     67 //		'406':
     68 //			description: not acceptable
     69 //		'500':
     70 //			description: internal server error
     71 func (m *Module) DomainBlockDELETEHandler(c *gin.Context) {
     72 	authed, err := oauth.Authed(c, true, true, true, true)
     73 	if err != nil {
     74 		apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
     75 		return
     76 	}
     77 
     78 	if !*authed.User.Admin {
     79 		err := fmt.Errorf("user %s not an admin", authed.User.ID)
     80 		apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
     81 		return
     82 	}
     83 
     84 	if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
     85 		apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
     86 		return
     87 	}
     88 
     89 	domainBlockID := c.Param(IDKey)
     90 	if domainBlockID == "" {
     91 		err := errors.New("no domain block id specified")
     92 		apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
     93 		return
     94 	}
     95 
     96 	domainBlock, errWithCode := m.processor.Admin().DomainBlockDelete(c.Request.Context(), authed.Account, domainBlockID)
     97 	if errWithCode != nil {
     98 		apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
     99 		return
    100 	}
    101 
    102 	c.JSON(http.StatusOK, domainBlock)
    103 }