From ca12742a7ac0aec95fc0d7897e54a2272a68c34f Mon Sep 17 00:00:00 2001 From: tobi Date: Tue, 13 May 2025 14:48:11 +0000 Subject: [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 Co-committed-by: tobi --- internal/gtsmodel/interactionpolicy.go | 92 ++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 42 deletions(-) (limited to 'internal/gtsmodel/interactionpolicy.go') diff --git a/internal/gtsmodel/interactionpolicy.go b/internal/gtsmodel/interactionpolicy.go index 7fcafc80d..886c2e44b 100644 --- a/internal/gtsmodel/interactionpolicy.go +++ b/internal/gtsmodel/interactionpolicy.go @@ -123,10 +123,10 @@ const ( // Interaction is conditionally permitted // for this PolicyValue + interaction combo, // pending approval by the item owner. - PolicyPermissionWithApproval + PolicyPermissionManualApproval // Interaction is permitted for this // PolicyValue + interaction combination. - PolicyPermissionPermitted + PolicyPermissionAutomaticApproval ) // PolicyCheckResult encapsulates the results @@ -138,39 +138,39 @@ type PolicyCheckResult struct { Permission PolicyPermission // Value that this check matched on. - // Only set if Permission = permitted. - PermittedMatchedOn *PolicyValue + // Only set if Permission = automatic. + PermissionMatchedOn *PolicyValue } // MatchedOnCollection returns true if this policy check -// result turned up Permitted, and matched based on the +// result turned up AutomaticApproval, and matched based on the // requester's presence in a followers or following collection. func (pcr *PolicyCheckResult) MatchedOnCollection() bool { - if !pcr.Permitted() { + if !pcr.AutomaticApproval() { // Not permitted at all // so definitely didn't // match on collection. return false } - if pcr.PermittedMatchedOn == nil { + if pcr.PermissionMatchedOn == nil { return false } - return *pcr.PermittedMatchedOn == PolicyValueFollowers || - *pcr.PermittedMatchedOn == PolicyValueFollowing + return *pcr.PermissionMatchedOn == PolicyValueFollowers || + *pcr.PermissionMatchedOn == PolicyValueFollowing } -// Permitted returns true if this policy -// check resulted in Permission = permitted. -func (pcr *PolicyCheckResult) Permitted() bool { - return pcr.Permission == PolicyPermissionPermitted +// AutomaticApproval returns true if this policy +// check resulted in Permission = automatic approval. +func (pcr *PolicyCheckResult) AutomaticApproval() bool { + return pcr.Permission == PolicyPermissionAutomaticApproval } // Permitted returns true if this policy -// check resulted in Permission = with approval. -func (pcr *PolicyCheckResult) WithApproval() bool { - return pcr.Permission == PolicyPermissionWithApproval +// check resulted in Permission = manual approval. +func (pcr *PolicyCheckResult) ManualApproval() bool { + return pcr.Permission == PolicyPermissionManualApproval } // Permitted returns true if this policy @@ -201,14 +201,22 @@ type InteractionPolicy struct { // to which a certain interaction is permitted // to various Actor and Actor Collection URIs. type PolicyRules struct { - // Always is for PolicyValues who are - // permitted to do an interaction - // without requiring approval. - Always PolicyValues - // WithApproval is for PolicyValues who - // are conditionally permitted to do - // an interaction, pending approval. - WithApproval PolicyValues + // AutomaticApproval is for PolicyValue entries + // that are pre-approved to do an interaction + // and will receive automatic approval. + // + // Note: This is stored in the db as JSON. + // JSON tags set for back compat with previous + // (now deprecated) name for this PolicyValues. + AutomaticApproval PolicyValues `json:"Always,omitempty"` + // ManualApproval is for PolicyValues entries + // that are conditionally permitted to do + // an interaction, pending manual approval. + // + // Note: This is stored in the db as JSON. + // JSON tags set for back compat with previous + // (now deprecated) name for this PolicyValues. + ManualApproval PolicyValues `json:"WithApproval,omitempty"` } // Returns the default interaction policy @@ -231,24 +239,24 @@ func DefaultInteractionPolicyFor(v Visibility) *InteractionPolicy { var defaultPolicyPublic = &InteractionPolicy{ CanLike: PolicyRules{ // Anyone can like. - Always: PolicyValues{ + AutomaticApproval: PolicyValues{ PolicyValuePublic, }, - WithApproval: make(PolicyValues, 0), + ManualApproval: make(PolicyValues, 0), }, CanReply: PolicyRules{ // Anyone can reply. - Always: PolicyValues{ + AutomaticApproval: PolicyValues{ PolicyValuePublic, }, - WithApproval: make(PolicyValues, 0), + ManualApproval: make(PolicyValues, 0), }, CanAnnounce: PolicyRules{ // Anyone can announce. - Always: PolicyValues{ + AutomaticApproval: PolicyValues{ PolicyValuePublic, }, - WithApproval: make(PolicyValues, 0), + ManualApproval: make(PolicyValues, 0), }, } @@ -269,29 +277,29 @@ var defaultPolicyFollowersOnly = &InteractionPolicy{ CanLike: PolicyRules{ // Self, followers and // mentioned can like. - Always: PolicyValues{ + AutomaticApproval: PolicyValues{ PolicyValueAuthor, PolicyValueFollowers, PolicyValueMentioned, }, - WithApproval: make(PolicyValues, 0), + ManualApproval: make(PolicyValues, 0), }, CanReply: PolicyRules{ // Self, followers and // mentioned can reply. - Always: PolicyValues{ + AutomaticApproval: PolicyValues{ PolicyValueAuthor, PolicyValueFollowers, PolicyValueMentioned, }, - WithApproval: make(PolicyValues, 0), + ManualApproval: make(PolicyValues, 0), }, CanAnnounce: PolicyRules{ // Only self can announce. - Always: PolicyValues{ + AutomaticApproval: PolicyValues{ PolicyValueAuthor, }, - WithApproval: make(PolicyValues, 0), + ManualApproval: make(PolicyValues, 0), }, } @@ -305,27 +313,27 @@ var defaultPolicyDirect = &InteractionPolicy{ CanLike: PolicyRules{ // Mentioned and self // can always like. - Always: PolicyValues{ + AutomaticApproval: PolicyValues{ PolicyValueAuthor, PolicyValueMentioned, }, - WithApproval: make(PolicyValues, 0), + ManualApproval: make(PolicyValues, 0), }, CanReply: PolicyRules{ // Mentioned and self // can always reply. - Always: PolicyValues{ + AutomaticApproval: PolicyValues{ PolicyValueAuthor, PolicyValueMentioned, }, - WithApproval: make(PolicyValues, 0), + ManualApproval: make(PolicyValues, 0), }, CanAnnounce: PolicyRules{ // Only self can announce. - Always: PolicyValues{ + AutomaticApproval: PolicyValues{ PolicyValueAuthor, }, - WithApproval: make(PolicyValues, 0), + ManualApproval: make(PolicyValues, 0), }, } -- cgit v1.2.3