[feature/frontend] Reports frontend v2 (#3022)

* use apiutil + paging in admin processor+handlers

* we're making it happen

* fix little whoopsie

* styling for report list

* don't youuuu forget about meee don't don't don't don't

* last bits

* sanitize content before showing in report statuses

* update report docs
This commit is contained in:
tobi
2024-06-18 18:18:00 +02:00
committed by GitHub
parent b08c1bd0cb
commit d2b3d37724
56 changed files with 1389 additions and 726 deletions

View File

@@ -20,12 +20,12 @@ package admin
import (
"fmt"
"net/http"
"strconv"
"github.com/gin-gonic/gin"
apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
"github.com/superseriousbusiness/gotosocial/internal/paging"
)
// ReportsGETHandler swagger:operation GET /api/v1/admin/reports adminReports
@@ -72,7 +72,7 @@ import (
// name: max_id
// type: string
// description: >-
// Return only reports *OLDER* than the given max ID.
// Return only reports *OLDER* than the given max ID (for paging downwards).
// The report with the specified ID will not be included in the response.
// in: query
// -
@@ -81,23 +81,21 @@ import (
// description: >-
// Return only reports *NEWER* than the given since ID.
// The report with the specified ID will not be included in the response.
// This parameter is functionally equivalent to min_id.
// in: query
// -
// name: min_id
// type: string
// description: >-
// Return only reports *NEWER* than the given min ID.
// Return only reports immediately *NEWER* than the given min ID (for paging upwards).
// The report with the specified ID will not be included in the response.
// This parameter is functionally equivalent to since_id.
// in: query
// -
// name: limit
// type: integer
// description: >-
// Number of reports to return.
// If more than 100 or less than 1, will be clamped to 100.
// description: Number of reports to return.
// default: 20
// minimum: 1
// maximum: 100
// in: query
//
// security:
@@ -144,34 +142,30 @@ func (m *Module) ReportsGETHandler(c *gin.Context) {
return
}
var resolved *bool
if resolvedString := c.Query(ResolvedKey); resolvedString != "" {
i, err := strconv.ParseBool(resolvedString)
if err != nil {
err := fmt.Errorf("error parsing %s: %s", ResolvedKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return
}
resolved = &i
resolved, errWithCode := apiutil.ParseResolved(c.Query(apiutil.ResolvedKey), nil)
if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return
}
limit := 20
if limitString := c.Query(LimitKey); limitString != "" {
i, err := strconv.Atoi(limitString)
if err != nil {
err := fmt.Errorf("error parsing %s: %s", LimitKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return
}
// normalize
if i < 1 || i > 100 {
i = 100
}
limit = i
page, errWithCode := paging.ParseIDPage(c,
1, // min limit
100, // max limit
20, // default limit
)
if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return
}
resp, errWithCode := m.processor.Admin().ReportsGet(c.Request.Context(), authed.Account, resolved, c.Query(AccountIDKey), c.Query(TargetAccountIDKey), c.Query(MaxIDKey), c.Query(SinceIDKey), c.Query(MinIDKey), limit)
resp, errWithCode := m.processor.Admin().ReportsGet(
c.Request.Context(),
authed.Account,
resolved,
c.Query(apiutil.AccountIDKey),
c.Query(apiutil.TargetAccountIDKey),
page,
)
if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return