From 3409e6414c909b99bb65c5b084d3f978dad3e437 Mon Sep 17 00:00:00 2001 From: tobi Date: Fri, 4 Apr 2025 17:29:15 +0200 Subject: [PATCH] [bugfix] Use "comment" via /api/v1/instance --- docs/admin/domain_permission_subscriptions.md | 21 ++++++++++++++++++ docs/api/swagger.yaml | 22 +++++++++++++++++-- .../client/instance/instancepeersget_test.go | 10 ++++----- internal/api/model/domain.go | 5 +++++ internal/processing/admin/domainpermission.go | 3 ++- internal/processing/instance.go | 6 ++--- internal/subscriptions/domainperms.go | 3 ++- testrig/transportcontroller.go | 2 +- 8 files changed, 59 insertions(+), 13 deletions(-) diff --git a/docs/admin/domain_permission_subscriptions.md b/docs/admin/domain_permission_subscriptions.md index 77ec831e1..78518e187 100644 --- a/docs/admin/domain_permission_subscriptions.md +++ b/docs/admin/domain_permission_subscriptions.md @@ -113,6 +113,27 @@ nothanks.com,suspend,false,false,,false JSON lists use content type `application/json`. +```json +[ + { + "domain": "bumfaces.net", + "suspended_at": "2020-05-13T13:29:12.000Z", + "comment": "big jerks" + }, + { + "domain": "peepee.poopoo", + "suspended_at": "2020-05-13T13:29:12.000Z", + "comment": "harassment" + }, + { + "domain": "nothanks.com", + "suspended_at": "2020-05-13T13:29:12.000Z" + } +] +``` + +As an alternative to `"comment"`, `"public_comment"` will also work: + ```json [ { diff --git a/docs/api/swagger.yaml b/docs/api/swagger.yaml index d3fc3478b..778b1c843 100644 --- a/docs/api/swagger.yaml +++ b/docs/api/swagger.yaml @@ -1099,13 +1099,22 @@ definitions: domain: description: Domain represents a remote domain properties: + comment: + description: |- + If the domain is blocked, what's the publicly-stated reason for the block. + Alternative to `public_comment` to be used when serializing/deserializing via /api/v1/instance. + example: they smell + type: string + x-go-name: Comment domain: description: The hostname of the domain. example: example.org type: string x-go-name: Domain public_comment: - description: If the domain is blocked, what's the publicly-stated reason for the block. + description: |- + If the domain is blocked, what's the publicly-stated reason for the block. + Alternative to `comment` to be used when serializing/deserializing NOT via /api/v1/instance. example: they smell type: string x-go-name: PublicComment @@ -1124,6 +1133,13 @@ definitions: x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model domainPermission: properties: + comment: + description: |- + If the domain is blocked, what's the publicly-stated reason for the block. + Alternative to `public_comment` to be used when serializing/deserializing via /api/v1/instance. + example: they smell + type: string + x-go-name: Comment created_at: description: Time at which the permission entry was created (ISO 8601 Datetime). example: "2021-07-30T09:20:25+00:00" @@ -1162,7 +1178,9 @@ definitions: type: string x-go-name: PrivateComment public_comment: - description: If the domain is blocked, what's the publicly-stated reason for the block. + description: |- + If the domain is blocked, what's the publicly-stated reason for the block. + Alternative to `comment` to be used when serializing/deserializing NOT via /api/v1/instance. example: they smell type: string x-go-name: PublicComment diff --git a/internal/api/client/instance/instancepeersget_test.go b/internal/api/client/instance/instancepeersget_test.go index a2c81cc4e..2421205f7 100644 --- a/internal/api/client/instance/instancepeersget_test.go +++ b/internal/api/client/instance/instancepeersget_test.go @@ -136,7 +136,7 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetOnlySuspended() { { "domain": "replyguys.com", "suspended_at": "2020-05-13T13:29:12.000Z", - "public_comment": "reply-guying to tech posts" + "comment": "reply-guying to tech posts" } ]`, dst.String()) } @@ -186,7 +186,7 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetOnlySuspendedAuthori { "domain": "replyguys.com", "suspended_at": "2020-05-13T13:29:12.000Z", - "public_comment": "reply-guying to tech posts" + "comment": "reply-guying to tech posts" } ]`, dst.String()) } @@ -219,7 +219,7 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetAll() { { "domain": "replyguys.com", "suspended_at": "2020-05-13T13:29:12.000Z", - "public_comment": "reply-guying to tech posts" + "comment": "reply-guying to tech posts" } ]`, dst.String()) } @@ -263,12 +263,12 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetAllWithObfuscated() { "domain": "o*g.*u**.t**.*or*t.*r**ev**", "suspended_at": "2021-06-09T10:34:55.000Z", - "public_comment": "just absolutely the worst, wowza" + "comment": "just absolutely the worst, wowza" }, { "domain": "replyguys.com", "suspended_at": "2020-05-13T13:29:12.000Z", - "public_comment": "reply-guying to tech posts" + "comment": "reply-guying to tech posts" } ]`, dst.String()) } diff --git a/internal/api/model/domain.go b/internal/api/model/domain.go index dbb4a974c..8d94321d0 100644 --- a/internal/api/model/domain.go +++ b/internal/api/model/domain.go @@ -33,6 +33,11 @@ type Domain struct { // example: 2021-07-30T09:20:25+00:00 SilencedAt string `json:"silenced_at,omitempty"` // If the domain is blocked, what's the publicly-stated reason for the block. + // Alternative to `public_comment` to be used when serializing/deserializing via /api/v1/instance. + // example: they smell + Comment *string `form:"comment" json:"comment,omitempty"` + // If the domain is blocked, what's the publicly-stated reason for the block. + // Alternative to `comment` to be used when serializing/deserializing NOT via /api/v1/instance. // example: they smell PublicComment *string `form:"public_comment" json:"public_comment,omitempty"` } diff --git a/internal/processing/admin/domainpermission.go b/internal/processing/admin/domainpermission.go index 14eb6942e..04ee2ab26 100644 --- a/internal/processing/admin/domainpermission.go +++ b/internal/processing/admin/domainpermission.go @@ -18,6 +18,7 @@ package admin import ( + "cmp" "context" "encoding/json" "errors" @@ -239,7 +240,7 @@ func (p *Processor) importOrUpdateDomainPerm( var ( domain = apiDomainPerm.Domain.Domain obfuscate = apiDomainPerm.Obfuscate - publicComment = apiDomainPerm.PublicComment + publicComment = cmp.Or(apiDomainPerm.PublicComment, apiDomainPerm.Comment) privateComment = apiDomainPerm.PrivateComment subscriptionID = "" // No sub ID for imports. ) diff --git a/internal/processing/instance.go b/internal/processing/instance.go index 3848c4e87..e723c751e 100644 --- a/internal/processing/instance.go +++ b/internal/processing/instance.go @@ -106,9 +106,9 @@ func (p *Processor) InstancePeersGet(ctx context.Context, includeSuspended bool, } domains = append(domains, &apimodel.Domain{ - Domain: d, - SuspendedAt: util.FormatISO8601(domainBlock.CreatedAt), - PublicComment: &domainBlock.PublicComment, + Domain: d, + SuspendedAt: util.FormatISO8601(domainBlock.CreatedAt), + Comment: &domainBlock.PublicComment, }) } } diff --git a/internal/subscriptions/domainperms.go b/internal/subscriptions/domainperms.go index 6bc4e81fe..d62805ead 100644 --- a/internal/subscriptions/domainperms.go +++ b/internal/subscriptions/domainperms.go @@ -742,7 +742,8 @@ func permsFromJSON( } // Set remaining fields. - perm.SetPublicComment(util.PtrOrZero(apiPerm.PublicComment)) + publicComment := cmp.Or(apiPerm.PublicComment, apiPerm.Comment) + perm.SetPublicComment(util.PtrOrZero(publicComment)) perm.SetObfuscate(util.Ptr(util.PtrOrZero(apiPerm.Obfuscate))) // We're done. diff --git a/testrig/transportcontroller.go b/testrig/transportcontroller.go index bbcb3901d..d66c71179 100644 --- a/testrig/transportcontroller.go +++ b/testrig/transportcontroller.go @@ -627,7 +627,7 @@ nothanks.com` { "domain": "bumfaces.net", "suspended_at": "2020-05-13T13:29:12.000Z", - "public_comment": "big jerks" + "comment": "big jerks" }, { "domain": "peepee.poopoo",