[feature] Add button to clear instance delivery errors (#4818)

# Description

> If this is a code change, please include a summary of what you've coded, and link to the issue(s) it closes/implements.
>
> If this is a documentation change, please briefly describe what you've changed and why.

Should be useful: if you've defederated from an instance cuz it's not online anymore, you don't need those delivery errors hanging around forever.

## Checklist

Please put an x inside each checkbox to indicate that you've read and followed it: `[ ]` -> `[x]`

If this is a documentation change, only the first two checkboxes must be filled (you can delete the others if you want).

- [x] I/we have read the [GoToSocial contribution guidelines](https://codeberg.org/superseriousbusiness/gotosocial/src/branch/main/CONTRIBUTING.md).
- [x] I/we have not used so-called 'AI' to create the proposed changes.
- [ ] I/we have discussed the proposed changes already, either in an issue on the repository, or in the Matrix chat.
- [x] I/we have performed a self-review of added code.
- [x] I/we have written code that is legible and maintainable by others.
- [x] I/we have commented the added code, particularly in hard-to-understand areas.
- [x] I/we have made any necessary changes to documentation.
- [ ] I/we have added tests that cover new code.
- [x] I/we have run tests and they pass locally with the changes.
- [x] I/we have run `go fmt ./...` and `golangci-lint run`.

Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4818
This commit is contained in:
tobi
2026-05-11 17:48:06 +02:00
committed by tobi
parent 4e2589bc3c
commit 603c849740
13 changed files with 242 additions and 5 deletions
+44
View File
@@ -4250,6 +4250,7 @@ info:
admin:write:domain_allows: grants admin write access to domain allows
admin:write:domain_blocks: grants admin write access to domain blocks
admin:write:domain_limits: grants admin write access to domain limits
admin:write:instances: grants admin write access to instances
admin:write:relays: grants admin write access to relays
admin:write:reports: grants admin write access to reports
profile: grants read access to verify_credentials
@@ -9228,6 +9229,48 @@ paths:
summary: Show admin view of one instance.
tags:
- admin
/api/v1/admin/instances/{id}/clear_delivery_errors:
post:
operationId: adminInstanceClearDeliveryErrors
parameters:
- description: The id of the instance.
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: Admin model instance.
schema:
$ref: '#/definitions/adminInstance'
"400":
description: bad request
schema:
$ref: '#/definitions/error'
"401":
description: unauthorized
schema:
$ref: '#/definitions/error'
"404":
description: not found
schema:
$ref: '#/definitions/error'
"406":
description: not acceptable
schema:
$ref: '#/definitions/error'
"500":
description: internal server error
schema:
$ref: '#/definitions/error'
security:
- OAuth2 Bearer:
- admin:write:instances
summary: Clear delivery errors for instance with given ID.
tags:
- admin
/api/v1/admin/media_cleanup:
post:
consumes:
@@ -18179,6 +18222,7 @@ securityDefinitions:
admin:write:domain_allows: grants admin write access to domain allows
admin:write:domain_blocks: grants admin write access to domain blocks
admin:write:domain_limits: grants admin write access to domain limits
admin:write:instances: grants admin write access to instances
admin:write:relays: grants admin write access to relays
admin:write:reports: grants admin write access to reports
profile: grants read access to verify_credentials
+2
View File
@@ -39,6 +39,7 @@
// - admin:write:domain_allows: grants admin write access to domain allows
// - admin:write:domain_blocks: grants admin write access to domain blocks
// - admin:write:domain_limits: grants admin write access to domain limits
// - admin:write:instances: grants admin write access to instances
// - admin:write:relays: grants admin write access to relays
// - admin:write:reports: grants admin write access to reports
// - profile: grants read access to verify_credentials
@@ -107,6 +108,7 @@
// admin:write:domain_allows: grants admin write access to domain allows
// admin:write:domain_blocks: grants admin write access to domain blocks
// admin:write:domain_limits: grants admin write access to domain limits
// admin:write:instances: grants admin write access to instances
// admin:write:relays: grants admin write access to relays
// admin:write:reports: grants admin write access to reports
// profile: grants read access to verify_credentials
+2
View File
@@ -72,6 +72,7 @@ const (
InstanceRulesPathWithID = InstanceRulesPath + WithID
InstancesPath = BasePath + "/instances"
InstancesPathWithID = InstancesPath + WithID
InstanceClearDeliveryErrorsPath = InstancesPathWithID + "/clear_delivery_errors"
RelaySubscriptionsPath = BasePath + "/relay_subscriptions"
RelaySubscriptionsPathWithID = RelaySubscriptionsPath + WithID
RelaySubscriptionMatchersPath = RelaySubscriptionsPathWithID + "/matchers"
@@ -190,6 +191,7 @@ func (m *Module) Route(attachHandler func(method string, path string, f ...gin.H
// instances stuff
attachHandler(http.MethodGet, InstancesPath, m.InstancesGETHandler)
attachHandler(http.MethodGet, InstancesPathWithID, m.InstanceGETHandler)
attachHandler(http.MethodPost, InstanceClearDeliveryErrorsPath, m.InstanceClearDeliveryErrorsPOSTHandler)
// relays stuff
attachHandler(http.MethodGet, RelaySubscriptionsPath, m.RelaySubscriptionsGETHandler)
@@ -0,0 +1,120 @@
// GoToSocial
// Copyright (C) GoToSocial Authors admin@gotosocial.org
// SPDX-License-Identifier: AGPL-3.0-or-later
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package admin
import (
"fmt"
"net/http"
apiutil "code.superseriousbusiness.org/gotosocial/internal/api/util"
"code.superseriousbusiness.org/gotosocial/internal/gtserror"
"github.com/gin-gonic/gin"
)
// InstanceClearDeliveryErrorsPOSTHandler swagger:operation POST /api/v1/admin/instances/{id}/clear_delivery_errors adminInstanceClearDeliveryErrors
//
// Clear delivery errors for instance with given ID.
//
// ---
// tags:
// - admin
//
// produces:
// - application/json
//
// parameters:
// -
// name: id
// type: string
// description: The id of the instance.
// in: path
// required: true
//
// security:
// - OAuth2 Bearer:
// - admin:write:instances
//
// responses:
// '200':
// name: instances
// description: Admin model instance.
// schema:
// "$ref": "#/definitions/adminInstance"
// '400':
// schema:
// "$ref": "#/definitions/error"
// description: bad request
// '401':
// schema:
// "$ref": "#/definitions/error"
// description: unauthorized
// '404':
// schema:
// "$ref": "#/definitions/error"
// description: not found
// '406':
// schema:
// "$ref": "#/definitions/error"
// description: not acceptable
// '500':
// schema:
// "$ref": "#/definitions/error"
// description: internal server error
func (m *Module) InstanceClearDeliveryErrorsPOSTHandler(c *gin.Context) {
authed, errWithCode := apiutil.TokenAuth(c,
true, true, true, true,
apiutil.ScopeAdminWriteInstances,
)
if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return
}
if !*authed.User.Admin {
err := fmt.Errorf("user %s not an admin", authed.User.ID)
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
return
}
if authed.Account.IsMoving() {
apiutil.ForbiddenAfterMove(c)
return
}
if _, errWithCode := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return
}
id, errWithCode := apiutil.ParseID(c.Param(apiutil.IDKey))
if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return
}
resp, errWithCode := m.processor.Admin().InstanceDeliveryErrorsClear(
c.Request.Context(),
id,
)
if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return
}
apiutil.JSON(c, http.StatusOK, resp)
}
+1
View File
@@ -102,6 +102,7 @@ const (
ScopeAdminReadDomainLimits Scope = ScopeAdminRead + ":" + scopeDomainLimits
ScopeAdminWriteDomainLimits Scope = ScopeAdminWrite + ":" + scopeDomainLimits
ScopeAdminReadInstances Scope = ScopeAdminRead + ":" + scopeInstances
ScopeAdminWriteInstances Scope = ScopeAdminWrite + ":" + scopeInstances
ScopeAdminReadRelays Scope = ScopeAdminRead + ":" + scopeRelays
ScopeAdminWriteRelays Scope = ScopeAdminWrite + ":" + scopeRelays
ScopeAdminReadReports Scope = ScopeAdminRead + ":" + scopeReports
+2 -2
View File
@@ -639,7 +639,7 @@ func (i *instanceDB) SetInstanceSuccessfulDelivery(
}
// Clear delivery errors for this instance (if any).
if err := i.clearFederationErrors(ctx,
if err := i.ClearFederationErrors(ctx,
instance.ID,
gtsmodel.FederationErrorTypeDelivery,
); err != nil {
@@ -692,7 +692,7 @@ func (i *instanceDB) getFederationErrors(
return i.getFederationErrorsByIDs(ctx, ids)
}
func (i *instanceDB) clearFederationErrors(
func (i *instanceDB) ClearFederationErrors(
ctx context.Context,
instanceID string,
errType gtsmodel.FederationErrorType,
+3
View File
@@ -55,6 +55,9 @@ type Instance interface {
// instance entry for the given domain to time.Now() and clears stored delivery errors.
SetInstanceSuccessfulDelivery(ctx context.Context, domain string) error
// ClearFederationErrors clears any stored federation errors for the given instance ID and error type.
ClearFederationErrors(ctx context.Context, instanceID string, errType gtsmodel.FederationErrorType) error
// GetInstanceAccounts returns a slice of accounts from the given instance, arranged by ID.
GetInstanceAccounts(ctx context.Context, domain string, maxID string, limit int) ([]*gtsmodel.Account, error)
+34
View File
@@ -27,6 +27,7 @@ import (
apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model"
apiutil "code.superseriousbusiness.org/gotosocial/internal/api/util"
"code.superseriousbusiness.org/gotosocial/internal/db"
"code.superseriousbusiness.org/gotosocial/internal/gtscontext"
"code.superseriousbusiness.org/gotosocial/internal/gtserror"
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
"code.superseriousbusiness.org/gotosocial/internal/paging"
@@ -111,3 +112,36 @@ func (p *Processor) InstanceGet(ctx context.Context, id string) (*apimodel.Admin
return item, nil
}
func (p *Processor) InstanceDeliveryErrorsClear(ctx context.Context, id string) (*apimodel.AdminInstance, gtserror.WithCode) {
// Get barebones model of instance with
// specified ID to make sure it exists.
//
// This will avoid populating delivery
// errors, which we're about to clear anyway.
instance, err := p.state.DB.GetInstanceByID(
gtscontext.SetBarebones(ctx),
id,
)
if err != nil {
err := gtserror.Newf("db error getting instance: %w", err)
return nil, gtserror.NewErrorInternalError(err)
}
// Clear delivery errors for the instance.
if err := p.state.DB.ClearFederationErrors(ctx,
id,
gtsmodel.FederationErrorTypeDelivery,
); err != nil {
err := gtserror.Newf("db error clearing delivery errors: %w", err)
return nil, gtserror.NewErrorInternalError(err)
}
item, err := p.converter.InstanceToAdminAPIInstance(ctx, instance)
if err != nil {
err := gtserror.Newf("error converting to admin API instance: %w", err)
return nil, gtserror.NewErrorInternalError(err)
}
return item, nil
}
@@ -148,6 +148,20 @@ const extended = gtsApi.injectEndpoints({
],
}),
clearInstanceDeliveryErrors: build.mutation<AdminInstance, string>({
query: (id) => ({
method: "POST",
url: `/api/v1/admin/instances/${id}/clear_delivery_errors`,
}),
invalidatesTags: (_result, _error, id) => [
// Invalidate this instance entry.
{ type: 'AdminInstance', id },
// Invalidate the whole list as
// this instance entry has changed.
{ type: "AdminInstance", id: "TRANSFORMED" },
],
}),
handleSignup: build.mutation<AdminAccount, HandleSignupParams>({
query: ({id, approve_or_reject, ...formData}) => {
return {
@@ -246,4 +260,5 @@ export const {
useDeleteInstanceRuleMutation,
useLazySearchInstancesQuery,
useGetInstanceQuery,
useClearInstanceDeliveryErrorsMutation,
} = extended;
@@ -19,12 +19,13 @@
import React, { ReactNode } from "react";
import { useGetInstanceQuery } from "../../../../lib/query/admin";
import { useClearInstanceDeliveryErrorsMutation, useGetInstanceQuery } from "../../../../lib/query/admin";
import FormWithData from "../../../../lib/form/form-with-data";
import { AdminInstance } from "../../../../lib/types/instance";
import { useLocation, useParams } from "wouter";
import { useBaseUrl } from "../../../../lib/navigation/util";
import BackButton from "../../../../components/back-button";
import MutationButton from "../../../../components/form/mutation-button";
export default function InstanceDetail() {
const params: { instanceID: string } = useParams();
@@ -94,6 +95,8 @@ function InstanceDetailForm({ data: instance }: { data: AdminInstance }) {
function InstanceDeliveryErrors({ data: instance }: { data: AdminInstance }): ReactNode {
const baseUrl = useBaseUrl();
const backLocation = `~${baseUrl}/${instance.id}`;
const [ clearDeliveryErrors, clearDeliveryErrorsResult ] = useClearInstanceDeliveryErrorsMutation();
if (!instance.delivery_errors) {
return null;
}
@@ -110,6 +113,19 @@ function InstanceDeliveryErrors({ data: instance }: { data: AdminInstance }): Re
risk of later federating with an instance created by a baddie masquerading as the original instance owner.
</p>
</div>
<MutationButton
label={"Clear delivery errors"}
title={"Clear delivery errors"}
type="button"
className="button danger"
onClick={(e) => {
e.preventDefault();
clearDeliveryErrors(instance.id);
}}
disabled={false}
showError={false}
result={clearDeliveryErrorsResult}
/>
<dl className="info-list delivery-errors-list">
{ instance.delivery_errors.map((err, i) => {
return (
+2 -2
View File
@@ -34,8 +34,8 @@ import HeaderPermDetail from "./http-header-permissions/detail";
import Email from "./actions/email";
import ApURL from "./debug/apurl";
import Caches from "./debug/caches";
import InstancesSearch from "./instances.go";
import InstanceDetail from "./instances.go/detail";
import InstancesSearch from "./instances";
import InstanceDetail from "./instances/detail";
import RelaySubscriptionsOverview from "./relay-subscriptions";
import RelaySubscriptionNew from "./relay-subscriptions/new";
import RelaySubscriptionDetail from "./relay-subscriptions/detail";