home: allow disableing list
This commit is contained in:
parent
35544bd64c
commit
5e9795ad0c
9 changed files with 127 additions and 32 deletions
|
|
@ -24,7 +24,7 @@ type Config struct {
|
|||
Listen ListenConfig `yaml:"listen" recurse:"true"`
|
||||
Paths PathsConfig `yaml:"paths" recurse:"true"`
|
||||
HTTP HTTPConfig `yaml:"http" recurse:"true"`
|
||||
Theme ThemeConfig `yaml:"theme" recurse:"true"`
|
||||
Home HomeConfig `yaml:"home" recurse:"true"`
|
||||
Docker DockerConfig `yaml:"docker" recurse:"true"`
|
||||
|
||||
SQL SQLConfig `yaml:"sql" recurse:"true"`
|
||||
|
|
|
|||
|
|
@ -39,10 +39,24 @@ http:
|
|||
# This email address can be configured here.
|
||||
certbot_email: null
|
||||
|
||||
# By default, the default domain redirects to the distillery repository.
|
||||
# If you want to change this, set an alternate domain name here.
|
||||
theme:
|
||||
home: null
|
||||
# Configuration for the (public) homepage of the distillery.
|
||||
home:
|
||||
# the url to redirect to for more information about this instance of the distillery.
|
||||
# to be configured by default.
|
||||
redirect: null
|
||||
|
||||
# configure the list of systems on the homepage.
|
||||
list:
|
||||
# is the list of WissKIs visible for the public?
|
||||
# if this is disabled, only the generic text is shown.
|
||||
public: null
|
||||
|
||||
# is the list of WissKIs visible to logged in users?
|
||||
# if this is disabled, only the generic text is shown.
|
||||
private: null
|
||||
|
||||
# Title of the list (whenever it is shown)
|
||||
title: null
|
||||
|
||||
docker:
|
||||
# The distillery uses several global docker networks.
|
||||
|
|
|
|||
|
|
@ -2,9 +2,17 @@ package config
|
|||
|
||||
import "github.com/FAU-CDI/wisski-distillery/internal/config/validators"
|
||||
|
||||
// ThemeConfig determines theming options
|
||||
type ThemeConfig struct {
|
||||
// By default, the default domain redirects to the distillery repository.
|
||||
// If you want to change this, set an alternate domain name here.
|
||||
SelfRedirect *validators.URL `yaml:"home" default:"https://github.com/FAU-CDI/wisski-distillery" validate:"https"`
|
||||
// HomeConfig determines options for the homepage of the distillery
|
||||
type HomeConfig struct {
|
||||
SelfRedirect *validators.URL `yaml:"redirect" default:"https://github.com/FAU-CDI/wisski-distillery" validate:"https"`
|
||||
List HomeListConfig `yaml:"list" recurse:"true"`
|
||||
}
|
||||
|
||||
type HomeListConfig struct {
|
||||
// Is the list enabled for public visits?
|
||||
Public validators.NullableBool `yaml:"public" default:"true" validate:"bool"`
|
||||
// Is the list enabled for signed-in visits?
|
||||
Private validators.NullableBool `yaml:"private" default:"true" validate:"bool"`
|
||||
// Title of the list whenever it is shown
|
||||
Title string `yaml:"title" default:"WissKIs on this Distillery" validate:"nonempty"`
|
||||
}
|
||||
|
|
|
|||
41
internal/config/validators/bool.go
Normal file
41
internal/config/validators/bool.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package validators
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// NullableBool represents a bool that can be null
|
||||
type NullableBool struct {
|
||||
Null, Value bool
|
||||
}
|
||||
|
||||
func (nb *NullableBool) UnmarshalYAML(value *yaml.Node) error {
|
||||
nb.Null = false
|
||||
if err := value.Decode(&nb.Value); err != nil {
|
||||
nb.Null = true
|
||||
nb.Value = false
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nb *NullableBool) MarshalYAML() (interface{}, error) {
|
||||
if nb.Null {
|
||||
return nil, nil
|
||||
}
|
||||
return nb.Value, nil
|
||||
}
|
||||
|
||||
func ValidateBool(value *NullableBool, dflt string) (err error) {
|
||||
if value.Null {
|
||||
res, err := strconv.ParseBool(dflt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
value.Null = false
|
||||
value.Value = res
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
@ -10,6 +10,8 @@ func New() validator.Collection {
|
|||
|
||||
validator.Add(coll, "nonempty", ValidateNonempty)
|
||||
|
||||
validator.Add(coll, "bool", ValidateBool)
|
||||
|
||||
validator.Add(coll, "directory", ValidateDirectory)
|
||||
validator.Add(coll, "file", ValidateFile)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue