diff options
| author | 2025-06-10 14:29:42 +0200 | |
|---|---|---|
| committer | 2025-06-10 14:29:42 +0200 | |
| commit | 1dc79c95862e083bc743e3ecdf63e6e8d3cc406a (patch) | |
| tree | 28ed327ba266b967c292f7988da258a23936706c /internal/filter/interaction/interactable.go | |
| parent | [chore] update to modernc.org/sqlite v1.38.0 with our concurrency workaround ... (diff) | |
| download | gotosocial-1dc79c95862e083bc743e3ecdf63e6e8d3cc406a.tar.xz | |
[chore] Update interactionPolicy sub-policy parsing in line with documented defaults (#4229)
# 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.
Brings our parsing of unset sub-policies in line with the defaults documented here: https://docs.gotosocial.org/en/v0.19.1/federation/interaction_policy/#defaults-per-sub-policy
Closes https://codeberg.org/superseriousbusiness/gotosocial/issues/4146
Part of https://codeberg.org/superseriousbusiness/gotosocial/issues/4026
## 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 checkbox 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 discussed the proposed changes already, either in an issue on the repository, or in the Matrix chat.
- [x] I/we have not leveraged AI to create the proposed changes.
- [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.
- [ ] I/we have made any necessary changes to documentation.
- [x] 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/4229
Co-authored-by: tobi <tobi.smethurst@protonmail.com>
Co-committed-by: tobi <tobi.smethurst@protonmail.com>
Diffstat (limited to 'internal/filter/interaction/interactable.go')
| -rw-r--r-- | internal/filter/interaction/interactable.go | 58 |
1 files changed, 28 insertions, 30 deletions
diff --git a/internal/filter/interaction/interactable.go b/internal/filter/interaction/interactable.go index 2052ac78e..38a43f23d 100644 --- a/internal/filter/interaction/interactable.go +++ b/internal/filter/interaction/interactable.go @@ -84,8 +84,8 @@ func (f *Filter) StatusLikeable( } switch { - // If status has policy set, check against that. - case status.InteractionPolicy != nil: + // If status has canLike sub-policy set, check against that. + case status.InteractionPolicy != nil && status.InteractionPolicy.CanLike != nil: return f.checkPolicy( ctx, requester, @@ -95,19 +95,18 @@ func (f *Filter) StatusLikeable( // If status is local and has no policy set, // check against the default policy for this - // visibility, as we're interaction-policy aware. + // visibility, as we're canLike sub-policy aware. case *status.Local: - policy := gtsmodel.DefaultInteractionPolicyFor(status.Visibility) return f.checkPolicy( ctx, requester, status, - policy.CanLike, + gtsmodel.DefaultCanLikeFor(status.Visibility), ) // Otherwise, assume the status is from an // instance that does not use / does not care - // about interaction policies, and just return OK. + // about canLike sub-policy, and just return OK. default: return >smodel.PolicyCheckResult{ Permission: gtsmodel.PolicyPermissionAutomaticApproval, @@ -235,8 +234,8 @@ func (f *Filter) StatusReplyable( } switch { - // If status has policy set, check against that. - case status.InteractionPolicy != nil: + // If status has canReply sub-policy set, check against that. + case status.InteractionPolicy != nil && status.InteractionPolicy.CanReply != nil: return f.checkPolicy( ctx, requester, @@ -245,20 +244,19 @@ func (f *Filter) StatusReplyable( ) // If status is local and has no policy set, - // check against the default policy for this - // visibility, as we're interaction-policy aware. + // check against the default canReply for this + // visibility, as we're canReply sub-policy aware. case *status.Local: - policy := gtsmodel.DefaultInteractionPolicyFor(status.Visibility) return f.checkPolicy( ctx, requester, status, - policy.CanReply, + gtsmodel.DefaultCanReplyFor(status.Visibility), ) // Otherwise, assume the status is from an // instance that does not use / does not care - // about interaction policies, and just return OK. + // about canReply sub-policy, and just return OK. default: return >smodel.PolicyCheckResult{ Permission: gtsmodel.PolicyPermissionAutomaticApproval, @@ -297,8 +295,8 @@ func (f *Filter) StatusBoostable( } switch { - // If status has policy set, check against that. - case status.InteractionPolicy != nil: + // If status has canAnnounce sub-policy set, check against that. + case status.InteractionPolicy != nil && status.InteractionPolicy.CanAnnounce != nil: return f.checkPolicy( ctx, requester, @@ -319,7 +317,7 @@ func (f *Filter) StatusBoostable( ) // Status is from an instance that does not use - // or does not care about interaction policies. + // or does not care about canAnnounce sub-policy. // We can boost it if it's unlisted or public. case status.Visibility == gtsmodel.VisibilityPublic || status.Visibility == gtsmodel.VisibilityUnlocked: @@ -340,7 +338,7 @@ func (f *Filter) checkPolicy( ctx context.Context, requester *gtsmodel.Account, status *gtsmodel.Status, - rules gtsmodel.PolicyRules, + rules *gtsmodel.PolicyRules, ) (*gtsmodel.PolicyCheckResult, error) { // Wrap context to be able to @@ -349,8 +347,8 @@ func (f *Filter) checkPolicy( fctx.Context = ctx // Check if requester matches a PolicyValue - // to be always allowed to do this. - matchAlways, matchAlwaysValue, err := f.matchPolicy(fctx, + // to be automatically approved for this. + matchAutomatic, matchAutomaticValue, err := f.matchPolicy(fctx, requester, status, rules.AutomaticApproval, @@ -360,40 +358,40 @@ func (f *Filter) checkPolicy( } // Check if requester matches a PolicyValue - // to be allowed to do this pending approval. - matchWithApproval, _, err := f.matchPolicy(fctx, + // to be manually approved for this. + matchManual, _, err := f.matchPolicy(fctx, requester, status, rules.ManualApproval, ) if err != nil { - return nil, gtserror.Newf("error checking policy approval match: %w", err) + return nil, gtserror.Newf("error checking policy match: %w", err) } switch { // Prefer explicit match, - // prioritizing "always". - case matchAlways == explicit: + // prioritizing automatic. + case matchAutomatic == explicit: return >smodel.PolicyCheckResult{ Permission: gtsmodel.PolicyPermissionAutomaticApproval, - PermissionMatchedOn: &matchAlwaysValue, + PermissionMatchedOn: &matchAutomaticValue, }, nil - case matchWithApproval == explicit: + case matchManual == explicit: return >smodel.PolicyCheckResult{ Permission: gtsmodel.PolicyPermissionManualApproval, }, nil // Then try implicit match, - // prioritizing "always". - case matchAlways == implicit: + // prioritizing automatic. + case matchAutomatic == implicit: return >smodel.PolicyCheckResult{ Permission: gtsmodel.PolicyPermissionAutomaticApproval, - PermissionMatchedOn: &matchAlwaysValue, + PermissionMatchedOn: &matchAutomaticValue, }, nil - case matchWithApproval == implicit: + case matchManual == implicit: return >smodel.PolicyCheckResult{ Permission: gtsmodel.PolicyPermissionManualApproval, }, nil |
