diff options
| author | 2024-07-24 13:27:42 +0200 | |
|---|---|---|
| committer | 2024-07-24 12:27:42 +0100 | |
| commit | c9b6220fef01dce80a31436660cd06b4e1db030f (patch) | |
| tree | 5fbade865a920a5ea04fdd63763eca1880d60c5d /internal/gtsmodel | |
| parent | [chore] renames the `GTS` caches to `DB` caches (#3127) (diff) | |
| download | gotosocial-c9b6220fef01dce80a31436660cd06b4e1db030f.tar.xz | |
[chore] Add interaction filter to complement existing visibility filter (#3111)
* [chore] Add interaction filter to complement existing visibility filter
* pass in ptr to visibility and interaction filters to Processor{} to ensure shared
* use int constants for for match type, cache db calls in filterctx
* function name typo :innocent:
---------
Co-authored-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/gtsmodel')
| -rw-r--r-- | internal/gtsmodel/interactionpolicy.go | 66 | 
1 files changed, 57 insertions, 9 deletions
| diff --git a/internal/gtsmodel/interactionpolicy.go b/internal/gtsmodel/interactionpolicy.go index 993763dc3..d8d890e69 100644 --- a/internal/gtsmodel/interactionpolicy.go +++ b/internal/gtsmodel/interactionpolicy.go @@ -111,26 +111,74 @@ func (p PolicyValue) FeasibleForVisibility(v Visibility) bool {  type PolicyValues []PolicyValue -// PolicyResult represents the result of -// checking an Actor URI and interaction -// type against the conditions of an -// InteractionPolicy to determine if that -// interaction is permitted. -type PolicyResult int +// PolicyPermission represents the permission +// state for a certain Actor URI and interaction +// type, in relation to a policy. +type PolicyPermission int  const (  	// Interaction is forbidden for this  	// PolicyValue + interaction combination. -	PolicyResultForbidden PolicyResult = iota +	PolicyPermissionForbidden PolicyPermission = iota  	// Interaction is conditionally permitted  	// for this PolicyValue + interaction combo,  	// pending approval by the item owner. -	PolicyResultWithApproval +	PolicyPermissionWithApproval  	// Interaction is permitted for this  	// PolicyValue + interaction combination. -	PolicyResultPermitted +	PolicyPermissionPermitted  ) +// PolicyCheckResult encapsulates the results +// of checking a certain Actor URI + type +// of interaction against an interaction policy. +type PolicyCheckResult struct { +	// Permission permitted / +	// with approval / forbidden. +	Permission PolicyPermission + +	// Value that this check matched on. +	// Only set if Permission = permitted. +	PermittedMatchedOn *PolicyValue +} + +// MatchedOnCollection returns true if this policy check +// result turned up Permitted, and matched based on the +// requester's presence in a followers or following collection. +func (pcr *PolicyCheckResult) MatchedOnCollection() bool { +	if !pcr.Permitted() { +		// Not permitted at all +		// so definitely didn't +		// match on collection. +		return false +	} + +	if pcr.PermittedMatchedOn == nil { +		return false +	} + +	return *pcr.PermittedMatchedOn == PolicyValueFollowers || +		*pcr.PermittedMatchedOn == PolicyValueFollowing +} + +// Permitted returns true if this policy +// check resulted in Permission = permitted. +func (pcr *PolicyCheckResult) Permitted() bool { +	return pcr.Permission == PolicyPermissionPermitted +} + +// Permitted returns true if this policy +// check resulted in Permission = with approval. +func (pcr *PolicyCheckResult) WithApproval() bool { +	return pcr.Permission == PolicyPermissionWithApproval +} + +// Permitted returns true if this policy +// check resulted in Permission = forbidden. +func (pcr *PolicyCheckResult) Forbidden() bool { +	return pcr.Permission == PolicyPermissionForbidden +} +  // An InteractionPolicy determines which  // interactions will be accepted for an  // item, and according to what rules. | 
