mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-01-31 05:06:41 +00:00
feat: Add EnumConfigItem for service configuration options
This commit is contained in:
parent
eecc71cc1e
commit
89afd8b32d
|
@ -28,7 +28,10 @@ from selfprivacy_api.graphql.queries.services import Services
|
||||||
from selfprivacy_api.graphql.queries.storage import Storage
|
from selfprivacy_api.graphql.queries.storage import Storage
|
||||||
from selfprivacy_api.graphql.queries.system import System
|
from selfprivacy_api.graphql.queries.system import System
|
||||||
|
|
||||||
from selfprivacy_api.graphql.common_types.service import StringConfigItem, BoolConfigItem
|
from selfprivacy_api.graphql.common_types.service import (
|
||||||
|
StringConfigItem,
|
||||||
|
BoolConfigItem,
|
||||||
|
)
|
||||||
|
|
||||||
from selfprivacy_api.graphql.mutations.users_mutations import UsersMutations
|
from selfprivacy_api.graphql.mutations.users_mutations import UsersMutations
|
||||||
from selfprivacy_api.graphql.queries.users import Users
|
from selfprivacy_api.graphql.queries.users import Users
|
||||||
|
@ -149,5 +152,5 @@ schema = strawberry.Schema(
|
||||||
query=Query,
|
query=Query,
|
||||||
mutation=Mutation,
|
mutation=Mutation,
|
||||||
subscription=Subscription,
|
subscription=Subscription,
|
||||||
types=[StringConfigItem, BoolConfigItem]
|
types=[StringConfigItem, BoolConfigItem],
|
||||||
)
|
)
|
||||||
|
|
|
@ -71,3 +71,28 @@ class BoolConfigItem(ConfigItem):
|
||||||
|
|
||||||
def set_value(self, value, service_options):
|
def set_value(self, value, service_options):
|
||||||
service_options[self.id] = value
|
service_options[self.id] = value
|
||||||
|
|
||||||
|
|
||||||
|
class EnumConfigItem(ConfigItem):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
id: str,
|
||||||
|
default_value: str,
|
||||||
|
description: str,
|
||||||
|
options: list[str],
|
||||||
|
widget: Optional[str] = None,
|
||||||
|
):
|
||||||
|
self.id = id
|
||||||
|
self.type = "enum"
|
||||||
|
self.default_value = default_value
|
||||||
|
self.description = description
|
||||||
|
self.options = options
|
||||||
|
self.widget = widget if widget else "select"
|
||||||
|
|
||||||
|
def get_value(self, service_options):
|
||||||
|
return service_options.get(self.id, self.default_value)
|
||||||
|
|
||||||
|
def set_value(self, value, service_options):
|
||||||
|
if value not in self.options:
|
||||||
|
raise ValueError(f"Value {value} not in options {self.options}")
|
||||||
|
service_options[self.id] = value
|
||||||
|
|
|
@ -11,6 +11,7 @@ from selfprivacy_api.services.forgejo.icon import FORGEJO_ICON
|
||||||
from selfprivacy_api.services.config_item import (
|
from selfprivacy_api.services.config_item import (
|
||||||
StringConfigItem,
|
StringConfigItem,
|
||||||
BoolConfigItem,
|
BoolConfigItem,
|
||||||
|
EnumConfigItem,
|
||||||
ConfigItem,
|
ConfigItem,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -54,6 +55,19 @@ class Forgejo(Service):
|
||||||
default_value=False,
|
default_value=False,
|
||||||
description="Require signin to view any page",
|
description="Require signin to view any page",
|
||||||
),
|
),
|
||||||
|
"defaultTheme": EnumConfigItem(
|
||||||
|
id="defaultTheme",
|
||||||
|
default_value="forgejo-auto",
|
||||||
|
description="Default theme",
|
||||||
|
options=[
|
||||||
|
"forgejo-auto",
|
||||||
|
"forgejo-light",
|
||||||
|
"forgejo-dark",
|
||||||
|
"auto",
|
||||||
|
"gitea",
|
||||||
|
"arc-green",
|
||||||
|
],
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
Loading…
Reference in a new issue