gtsocial-umbx

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

reportresolve.go (3692B)


      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 	apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
     27 	apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
     28 	"github.com/superseriousbusiness/gotosocial/internal/gtserror"
     29 	"github.com/superseriousbusiness/gotosocial/internal/oauth"
     30 )
     31 
     32 // ReportResolvePOSTHandler swagger:operation POST /api/v1/admin/reports/{id}/resolve adminReportResolve
     33 //
     34 // Mark a report as resolved.
     35 //
     36 //	---
     37 //	tags:
     38 //	- admin
     39 //
     40 //	consumes:
     41 //	- application/json
     42 //	- application/xml
     43 //	- multipart/form-data
     44 //
     45 //	produces:
     46 //	- application/json
     47 //
     48 //	parameters:
     49 //	-
     50 //		name: id
     51 //		type: string
     52 //		description: The id of the report.
     53 //		in: path
     54 //		required: true
     55 //	-
     56 //		name: action_taken_comment
     57 //		in: formData
     58 //		description: >-
     59 //			Optional admin comment on the action taken in response to this report.
     60 //			Useful for providing an explanation about what action was taken (if any)
     61 //			before the report was marked as resolved. This will be visible to the user
     62 //			that created the report!
     63 //		type: string
     64 //		example: The reported account was suspended.
     65 //
     66 //	security:
     67 //	- OAuth2 Bearer:
     68 //		- admin
     69 //
     70 //	responses:
     71 //		'200':
     72 //			name: report
     73 //			description: The resolved report.
     74 //			schema:
     75 //				"$ref": "#/definitions/adminReport"
     76 //		'400':
     77 //			description: bad request
     78 //		'401':
     79 //			description: unauthorized
     80 //		'404':
     81 //			description: not found
     82 //		'406':
     83 //			description: not acceptable
     84 //		'500':
     85 //			description: internal server error
     86 func (m *Module) ReportResolvePOSTHandler(c *gin.Context) {
     87 	authed, err := oauth.Authed(c, true, true, true, true)
     88 	if err != nil {
     89 		apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
     90 		return
     91 	}
     92 
     93 	if !*authed.User.Admin {
     94 		err := fmt.Errorf("user %s not an admin", authed.User.ID)
     95 		apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
     96 		return
     97 	}
     98 
     99 	if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
    100 		apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
    101 		return
    102 	}
    103 
    104 	reportID := c.Param(IDKey)
    105 	if reportID == "" {
    106 		err := errors.New("no report id specified")
    107 		apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
    108 		return
    109 	}
    110 
    111 	form := &apimodel.AdminReportResolveRequest{}
    112 	if err := c.ShouldBind(form); err != nil {
    113 		apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
    114 		return
    115 	}
    116 
    117 	report, errWithCode := m.processor.Admin().ReportResolve(c.Request.Context(), authed.Account, reportID, form.ActionTakenComment)
    118 	if errWithCode != nil {
    119 		apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
    120 		return
    121 	}
    122 
    123 	c.JSON(http.StatusOK, report)
    124 }