reportget.go (2890B)
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 // ReportGETHandler swagger:operation GET /api/v1/admin/reports/{id} adminReportGet 32 // 33 // View user moderation report 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 report. 47 // in: path 48 // required: true 49 // 50 // security: 51 // - OAuth2 Bearer: 52 // - admin 53 // 54 // responses: 55 // '200': 56 // name: report 57 // description: The requested report. 58 // schema: 59 // "$ref": "#/definitions/adminReport" 60 // '400': 61 // description: bad request 62 // '401': 63 // description: unauthorized 64 // '404': 65 // description: not found 66 // '406': 67 // description: not acceptable 68 // '500': 69 // description: internal server error 70 func (m *Module) ReportGETHandler(c *gin.Context) { 71 authed, err := oauth.Authed(c, true, true, true, true) 72 if err != nil { 73 apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1) 74 return 75 } 76 77 if !*authed.User.Admin { 78 err := fmt.Errorf("user %s not an admin", authed.User.ID) 79 apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1) 80 return 81 } 82 83 if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { 84 apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1) 85 return 86 } 87 88 reportID := c.Param(IDKey) 89 if reportID == "" { 90 err := errors.New("no report id specified") 91 apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1) 92 return 93 } 94 95 report, errWithCode := m.processor.Admin().ReportGet(c.Request.Context(), authed.Account, reportID) 96 if errWithCode != nil { 97 apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1) 98 return 99 } 100 101 c.JSON(http.StatusOK, report) 102 }