Add config annotation to mark a setting as "plan requires"

This commit is contained in:
Patrick Pacher 2023-07-19 10:59:31 +02:00
parent 2d0ce85661
commit c992b8ea54
No known key found for this signature in database
GPG key ID: E8CD2DA160925A6D
3 changed files with 10 additions and 2 deletions

2
.gitignore vendored
View file

@ -4,3 +4,5 @@ misc
go.mod.*
vendor
go.work
go.work.sum

View file

@ -108,6 +108,11 @@ const (
// requirement. The type of RequiresAnnotation is []ValueRequirement
// or ValueRequirement.
RequiresAnnotation = "safing/portbase:config:requires"
// SettingRequiresFeaturePlan can be used to mark a setting as only available
// when the user has a certain feature ID activated by the subscription plan.
// The type is []string or string.
SettingRequiresFeaturePlan = "safing/portmaster:ui:config:requires-feature"
)
// QuickSettingsAction defines the action of a quick setting.

View file

@ -52,6 +52,7 @@ func replaceConfig(newValues map[string]interface{}) []*ValidationError {
option.Lock()
option.activeValue = nil
if ok {
valueCache, err := validateValue(option, newValue)
if err == nil {
@ -103,11 +104,11 @@ func replaceDefaultConfig(newValues map[string]interface{}) []*ValidationError {
}
// SetConfigOption sets a single value in the (prioritized) user defined config.
func SetConfigOption(key string, value interface{}) error {
func SetConfigOption(key string, value any) error {
return setConfigOption(key, value, true)
}
func setConfigOption(key string, value interface{}, push bool) (err error) {
func setConfigOption(key string, value any, push bool) (err error) {
option, err := GetOption(key)
if err != nil {
return err