diff options
author | 2024-07-26 12:04:28 +0200 | |
---|---|---|
committer | 2024-07-26 12:04:28 +0200 | |
commit | 8ab2b19a946251f258446d22f420d401f61d22f6 (patch) | |
tree | 39fb674f135fd1cfcf4de5b319913f0d0c17d11a /internal/ap/normalize.go | |
parent | [docs] Add separate migration section + instructions for moving to GtS and no... (diff) | |
download | gotosocial-8ab2b19a946251f258446d22f420d401f61d22f6.tar.xz |
[feature] Federate interaction policies + Accepts; enforce policies (#3138)
* [feature] Federate interaction policies + Accepts; enforce policies
* use Acceptable type
* fix index
* remove appendIRIStrs
* add GetAccept federatingdb function
* lock on object IRI
Diffstat (limited to 'internal/ap/normalize.go')
-rw-r--r-- | internal/ap/normalize.go | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/internal/ap/normalize.go b/internal/ap/normalize.go index bef6d93b0..30d8515a5 100644 --- a/internal/ap/normalize.go +++ b/internal/ap/normalize.go @@ -575,6 +575,107 @@ func NormalizeOutgoingContentProp(item WithContent, rawJSON map[string]interface } } +// NormalizeOutgoingInteractionPolicyProp replaces single-entry interactionPolicy values +// with single-entry arrays, for better compatibility with other AP implementations. +// +// Ie: +// +// "interactionPolicy": { +// "canAnnounce": { +// "always": "https://www.w3.org/ns/activitystreams#Public", +// "approvalRequired": [] +// }, +// "canLike": { +// "always": "https://www.w3.org/ns/activitystreams#Public", +// "approvalRequired": [] +// }, +// "canReply": { +// "always": "https://www.w3.org/ns/activitystreams#Public", +// "approvalRequired": [] +// } +// } +// +// becomes: +// +// "interactionPolicy": { +// "canAnnounce": { +// "always": [ +// "https://www.w3.org/ns/activitystreams#Public" +// ], +// "approvalRequired": [] +// }, +// "canLike": { +// "always": [ +// "https://www.w3.org/ns/activitystreams#Public" +// ], +// "approvalRequired": [] +// }, +// "canReply": { +// "always": [ +// "https://www.w3.org/ns/activitystreams#Public" +// ], +// "approvalRequired": [] +// } +// } +// +// Noop for items with no attachments, or with attachments that are already a slice. +func NormalizeOutgoingInteractionPolicyProp(item WithInteractionPolicy, rawJSON map[string]interface{}) { + policy, ok := rawJSON["interactionPolicy"] + if !ok { + // No 'interactionPolicy', + // nothing to change. + return + } + + policyMap, ok := policy.(map[string]interface{}) + if !ok { + // Malformed 'interactionPolicy', + // nothing to change. + return + } + + for _, rulesKey := range []string{ + "canLike", + "canReply", + "canAnnounce", + } { + // Either "canAnnounce", + // "canLike", or "canApprove" + rulesVal, ok := policyMap[rulesKey] + if !ok { + // Not set. + return + } + + rulesValMap, ok := rulesVal.(map[string]interface{}) + if !ok { + // Malformed or not + // present skip. + return + } + + for _, PolicyValuesKey := range []string{ + "always", + "approvalRequired", + } { + PolicyValuesVal, ok := rulesValMap[PolicyValuesKey] + if !ok { + // Not set. + continue + } + + if _, ok := PolicyValuesVal.([]interface{}); ok { + // Already slice, + // nothing to change. + continue + } + + // Coerce single-object to slice. + rulesValMap[PolicyValuesKey] = []interface{}{PolicyValuesVal} + } + } +} + // NormalizeOutgoingObjectProp normalizes each Object entry in the rawJSON of the given // item by calling custom serialization / normalization functions on them in turn. // |