[chore] Deprecate with_approval, always (client API), approvalRequired, always (fedi API) (#4173)

This pull request deprecates `with_approval` and `always` on the client API side, and `approvalRequired` and `always` on the fedi API side, replacing them with `automatic_approval` and `manual_approval` and `automaticApproval` and `manualApproval`, respectively.

Back-compat is kept with these deprecated fields, and they're still serialized to the client API and fedi APIs respectively, in addition to the new non-deprecated properties.

This will stay the case until v0.21.0 when they'll be removed.

For the sake of not doing a massive database migration, the fields are still named `Always` and `WithApproval` in storage. I think this is probably fine!

Part of https://codeberg.org/superseriousbusiness/gotosocial/issues/4026
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4173
Co-authored-by: tobi <tobi.smethurst@protonmail.com>
Co-committed-by: tobi <tobi.smethurst@protonmail.com>
This commit is contained in:
tobi 2025-05-13 14:48:11 +00:00 committed by kim
commit ca12742a7a
28 changed files with 1214 additions and 248 deletions

View file

@ -1173,15 +1173,7 @@ func extractCanLike(
return gtsmodel.PolicyRules{}
}
withRules := propIter.Get()
if withRules == nil {
return gtsmodel.PolicyRules{}
}
return gtsmodel.PolicyRules{
Always: extractPolicyValues(withRules.GetGoToSocialAlways(), owner),
WithApproval: extractPolicyValues(withRules.GetGoToSocialApprovalRequired(), owner),
}
return extractPolicyRules(propIter.Get(), owner)
}
func extractCanReply(
@ -1197,15 +1189,7 @@ func extractCanReply(
return gtsmodel.PolicyRules{}
}
withRules := propIter.Get()
if withRules == nil {
return gtsmodel.PolicyRules{}
}
return gtsmodel.PolicyRules{
Always: extractPolicyValues(withRules.GetGoToSocialAlways(), owner),
WithApproval: extractPolicyValues(withRules.GetGoToSocialApprovalRequired(), owner),
}
return extractPolicyRules(propIter.Get(), owner)
}
func extractCanAnnounce(
@ -1226,9 +1210,39 @@ func extractCanAnnounce(
return gtsmodel.PolicyRules{}
}
return extractPolicyRules(propIter.Get(), owner)
}
func extractPolicyRules(
withRules WithPolicyRules,
owner *gtsmodel.Account,
) gtsmodel.PolicyRules {
if withRules == nil {
return gtsmodel.PolicyRules{}
}
// Check for `automaticApproval` and
// `manualApproval` properties first.
var (
automaticApproval = withRules.GetGoToSocialAutomaticApproval()
manualApproval = withRules.GetGoToSocialManualApproval()
)
if (automaticApproval != nil && automaticApproval.Len() != 0) ||
(manualApproval != nil && manualApproval.Len() != 0) {
// At least one is set, use these props.
return gtsmodel.PolicyRules{
AutomaticApproval: extractPolicyValues(automaticApproval, owner),
ManualApproval: extractPolicyValues(manualApproval, owner),
}
}
// Fall back to deprecated `always`
// and `withApproval` properties.
//
// TODO: Remove this in GtS v0.21.0.
return gtsmodel.PolicyRules{
Always: extractPolicyValues(withRules.GetGoToSocialAlways(), owner),
WithApproval: extractPolicyValues(withRules.GetGoToSocialApprovalRequired(), owner),
AutomaticApproval: extractPolicyValues(withRules.GetGoToSocialAlways(), owner),
ManualApproval: extractPolicyValues(withRules.GetGoToSocialApprovalRequired(), owner),
}
}

View file

@ -43,6 +43,106 @@ func (suite *ExtractPolicyTestSuite) TestExtractPolicy() {
"en": "hey @f0x and @dumpsterqueer",
"fr": "bonjour @f0x et @dumpsterqueer"
},
"interactionPolicy": {
"canLike": {
"automaticApproval": [
"https://www.w3.org/ns/activitystreams#Public"
],
"manualApproval": []
},
"canReply": {
"automaticApproval": [
"http://localhost:8080/users/the_mighty_zork",
"http://localhost:8080/users/the_mighty_zork/followers",
"https://gts.superseriousbusiness.org/users/dumpsterqueer",
"https://gts.superseriousbusiness.org/users/f0x"
],
"manualApproval": [
"https://www.w3.org/ns/activitystreams#Public"
]
},
"canAnnounce": {
"automaticApproval": [
"http://localhost:8080/users/the_mighty_zork"
],
"manualApproval": [
"https://www.w3.org/ns/activitystreams#Public"
]
}
},
"tag": [
{
"href": "https://gts.superseriousbusiness.org/users/dumpsterqueer",
"name": "@dumpsterqueer@superseriousbusiness.org",
"type": "Mention"
},
{
"href": "https://gts.superseriousbusiness.org/users/f0x",
"name": "@f0x@superseriousbusiness.org",
"type": "Mention"
}
],
"type": "Note"
}`
statusable, err := ap.ResolveStatusable(
context.Background(),
io.NopCloser(
bytes.NewBufferString(rawNote),
),
)
if err != nil {
suite.FailNow(err.Error())
}
policy := ap.ExtractInteractionPolicy(
statusable,
// Zork didn't actually create
// this status but nevermind.
suite.testAccounts["local_account_1"],
)
expectedPolicy := &gtsmodel.InteractionPolicy{
CanLike: gtsmodel.PolicyRules{
AutomaticApproval: gtsmodel.PolicyValues{
gtsmodel.PolicyValuePublic,
},
ManualApproval: gtsmodel.PolicyValues{},
},
CanReply: gtsmodel.PolicyRules{
AutomaticApproval: gtsmodel.PolicyValues{
gtsmodel.PolicyValueAuthor,
gtsmodel.PolicyValueFollowers,
"https://gts.superseriousbusiness.org/users/dumpsterqueer",
"https://gts.superseriousbusiness.org/users/f0x",
},
ManualApproval: gtsmodel.PolicyValues{
gtsmodel.PolicyValuePublic,
},
},
CanAnnounce: gtsmodel.PolicyRules{
AutomaticApproval: gtsmodel.PolicyValues{
gtsmodel.PolicyValueAuthor,
},
ManualApproval: gtsmodel.PolicyValues{
gtsmodel.PolicyValuePublic,
},
},
}
suite.EqualValues(expectedPolicy, policy)
}
func (suite *ExtractPolicyTestSuite) TestExtractPolicyDeprecated() {
rawNote := `{
"@context": [
"https://gotosocial.org/ns",
"https://www.w3.org/ns/activitystreams"
],
"content": "hey @f0x and @dumpsterqueer",
"contentMap": {
"en": "hey @f0x and @dumpsterqueer",
"fr": "bonjour @f0x et @dumpsterqueer"
},
"interactionPolicy": {
"canLike": {
"always": [
@ -104,27 +204,27 @@ func (suite *ExtractPolicyTestSuite) TestExtractPolicy() {
expectedPolicy := &gtsmodel.InteractionPolicy{
CanLike: gtsmodel.PolicyRules{
Always: gtsmodel.PolicyValues{
AutomaticApproval: gtsmodel.PolicyValues{
gtsmodel.PolicyValuePublic,
},
WithApproval: gtsmodel.PolicyValues{},
ManualApproval: gtsmodel.PolicyValues{},
},
CanReply: gtsmodel.PolicyRules{
Always: gtsmodel.PolicyValues{
AutomaticApproval: gtsmodel.PolicyValues{
gtsmodel.PolicyValueAuthor,
gtsmodel.PolicyValueFollowers,
"https://gts.superseriousbusiness.org/users/dumpsterqueer",
"https://gts.superseriousbusiness.org/users/f0x",
},
WithApproval: gtsmodel.PolicyValues{
ManualApproval: gtsmodel.PolicyValues{
gtsmodel.PolicyValuePublic,
},
},
CanAnnounce: gtsmodel.PolicyRules{
Always: gtsmodel.PolicyValues{
AutomaticApproval: gtsmodel.PolicyValues{
gtsmodel.PolicyValueAuthor,
},
WithApproval: gtsmodel.PolicyValues{
ManualApproval: gtsmodel.PolicyValues{
gtsmodel.PolicyValuePublic,
},
},

View file

@ -755,8 +755,10 @@ type WithInteractionPolicy interface {
// WithPolicyRules represents an activity with always and approvalRequired properties.
type WithPolicyRules interface {
GetGoToSocialAlways() vocab.GoToSocialAlwaysProperty
GetGoToSocialApprovalRequired() vocab.GoToSocialApprovalRequiredProperty
GetGoToSocialAutomaticApproval() vocab.GoToSocialAutomaticApprovalProperty
GetGoToSocialManualApproval() vocab.GoToSocialManualApprovalProperty
GetGoToSocialAlways() vocab.GoToSocialAlwaysProperty // Deprecated
GetGoToSocialApprovalRequired() vocab.GoToSocialApprovalRequiredProperty // Deprecated
}
// WithApprovedBy represents a Statusable with the approvedBy property.

View file

@ -582,16 +582,16 @@ func NormalizeOutgoingContentProp(item WithContent, rawJSON map[string]interface
//
// "interactionPolicy": {
// "canAnnounce": {
// "always": "https://www.w3.org/ns/activitystreams#Public",
// "approvalRequired": []
// "automaticApproval": "https://www.w3.org/ns/activitystreams#Public",
// "manualApproval": []
// },
// "canLike": {
// "always": "https://www.w3.org/ns/activitystreams#Public",
// "approvalRequired": []
// "automaticApproval": "https://www.w3.org/ns/activitystreams#Public",
// "manualApproval": []
// },
// "canReply": {
// "always": "https://www.w3.org/ns/activitystreams#Public",
// "approvalRequired": []
// "automaticApproval": "https://www.w3.org/ns/activitystreams#Public",
// "manualApproval": []
// }
// }
//
@ -599,22 +599,22 @@ func NormalizeOutgoingContentProp(item WithContent, rawJSON map[string]interface
//
// "interactionPolicy": {
// "canAnnounce": {
// "always": [
// "automaticApproval": [
// "https://www.w3.org/ns/activitystreams#Public"
// ],
// "approvalRequired": []
// "manualApproval": []
// },
// "canLike": {
// "always": [
// "automaticApproval": [
// "https://www.w3.org/ns/activitystreams#Public"
// ],
// "approvalRequired": []
// "manualApproval": []
// },
// "canReply": {
// "always": [
// "automaticApproval": [
// "https://www.w3.org/ns/activitystreams#Public"
// ],
// "approvalRequired": []
// "manualApproval": []
// }
// }
//
@ -655,8 +655,10 @@ func NormalizeOutgoingInteractionPolicyProp(item WithInteractionPolicy, rawJSON
}
for _, PolicyValuesKey := range []string{
"always",
"approvalRequired",
"automaticApproval",
"manualApproval",
"always", // deprecated
"approvalRequired", // deprecated
} {
PolicyValuesVal, ok := rulesValMap[PolicyValuesKey]
if !ok {