mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-16 01:43:01 -06:00
[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:
parent
b08c1bd0cb
commit
d2b3d37724
56 changed files with 1389 additions and 726 deletions
|
|
@ -18,7 +18,6 @@
|
|||
package reports
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
|
@ -77,10 +76,9 @@ func (m *Module) ReportGETHandler(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
targetReportID := c.Param(IDKey)
|
||||
if targetReportID == "" {
|
||||
err := errors.New("no report id specified")
|
||||
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
|
||||
targetReportID, errWithCode := apiutil.ParseID(c.Param(apiutil.IDKey))
|
||||
if errWithCode != nil {
|
||||
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ func (suite *ReportGetTestSuite) TestGetReport2() {
|
|||
}
|
||||
|
||||
func (suite *ReportGetTestSuite) TestGetReport3() {
|
||||
report, err := suite.getReport(http.StatusBadRequest, `{"error":"Bad Request: no report id specified"}`, "")
|
||||
report, err := suite.getReport(http.StatusBadRequest, `{"error":"Bad Request: required key id was not set or had empty value"}`, "")
|
||||
suite.NoError(err)
|
||||
suite.Nil(report)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,19 +21,13 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/processing"
|
||||
)
|
||||
|
||||
const (
|
||||
BasePath = "/v1/reports"
|
||||
IDKey = "id"
|
||||
ResolvedKey = "resolved"
|
||||
TargetAccountIDKey = "target_account_id"
|
||||
MaxIDKey = "max_id"
|
||||
SinceIDKey = "since_id"
|
||||
MinIDKey = "min_id"
|
||||
LimitKey = "limit"
|
||||
BasePathWithID = BasePath + "/:" + IDKey
|
||||
BasePath = "/v1/reports"
|
||||
BasePathWithID = BasePath + "/:" + apiutil.IDKey
|
||||
)
|
||||
|
||||
type Module struct {
|
||||
|
|
|
|||
|
|
@ -18,14 +18,13 @@
|
|||
package reports
|
||||
|
||||
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/reports reports
|
||||
|
|
@ -67,7 +66,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
|
||||
// -
|
||||
|
|
@ -76,24 +75,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 less than 1, will be clamped to 1.
|
||||
// If more than 100, will be clamped to 100.
|
||||
// description: Number of reports to return.
|
||||
// default: 20
|
||||
// minimum: 1
|
||||
// maximum: 100
|
||||
// in: query
|
||||
//
|
||||
// security:
|
||||
|
|
@ -134,36 +130,29 @@ 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 <= 0 {
|
||||
i = 1
|
||||
} else if 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.Report().GetMultiple(c.Request.Context(), authed.Account, resolved, c.Query(TargetAccountIDKey), c.Query(MaxIDKey), c.Query(SinceIDKey), c.Query(MinIDKey), limit)
|
||||
resp, errWithCode := m.processor.Report().GetMultiple(
|
||||
c.Request.Context(),
|
||||
authed.Account,
|
||||
resolved,
|
||||
c.Query(apiutil.TargetAccountIDKey),
|
||||
page,
|
||||
)
|
||||
if errWithCode != nil {
|
||||
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import (
|
|||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/api/client/reports"
|
||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
||||
|
|
@ -61,21 +62,21 @@ func (suite *ReportsGetTestSuite) getReports(
|
|||
ctx.Set(oauth.SessionAuthorizedUser, user)
|
||||
|
||||
// create the request URI
|
||||
requestPath := reports.BasePath + "?" + reports.LimitKey + "=" + strconv.Itoa(limit)
|
||||
requestPath := reports.BasePath + "?" + apiutil.LimitKey + "=" + strconv.Itoa(limit)
|
||||
if resolved != nil {
|
||||
requestPath = requestPath + "&" + reports.ResolvedKey + "=" + strconv.FormatBool(*resolved)
|
||||
requestPath = requestPath + "&" + apiutil.ResolvedKey + "=" + strconv.FormatBool(*resolved)
|
||||
}
|
||||
if targetAccountID != "" {
|
||||
requestPath = requestPath + "&" + reports.TargetAccountIDKey + "=" + targetAccountID
|
||||
requestPath = requestPath + "&" + apiutil.TargetAccountIDKey + "=" + targetAccountID
|
||||
}
|
||||
if maxID != "" {
|
||||
requestPath = requestPath + "&" + reports.MaxIDKey + "=" + maxID
|
||||
requestPath = requestPath + "&" + apiutil.MaxIDKey + "=" + maxID
|
||||
}
|
||||
if sinceID != "" {
|
||||
requestPath = requestPath + "&" + reports.SinceIDKey + "=" + sinceID
|
||||
requestPath = requestPath + "&" + apiutil.SinceIDKey + "=" + sinceID
|
||||
}
|
||||
if minID != "" {
|
||||
requestPath = requestPath + "&" + reports.MinIDKey + "=" + minID
|
||||
requestPath = requestPath + "&" + apiutil.MinIDKey + "=" + minID
|
||||
}
|
||||
baseURI := config.GetProtocol() + "://" + config.GetHost()
|
||||
requestURI := baseURI + "/api/" + requestPath
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue