New option to disable provider edition
continuous-integration/drone/push Build encountered an error Details

This will be useful for the demo instance
This commit is contained in:
nemunaire 2024-01-02 13:28:31 +01:00
parent c5131b4f91
commit 497269f811
7 changed files with 55 additions and 19 deletions

View File

@ -100,6 +100,9 @@ func getProviderSettingsState(cfg *config.Options, c *gin.Context) {
if err != forms.DoneForm {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": err.Error()})
return
} else if cfg.DisableProviders {
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"errmsg": "Cannot change provider settings as DisableProviders parameter is set."})
return
} else if _, err = src.NewDNSServiceProvider(); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": err.Error()})
return

View File

@ -39,18 +39,39 @@ import (
func declareProvidersRoutes(cfg *config.Options, router *gin.RouterGroup) {
router.GET("/providers", getProviders)
router.POST("/providers", addProvider)
router.POST("/providers", func(c *gin.Context) {
if cfg.DisableProviders {
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"errmsg": "Cannot add provider as DisableProviders parameter is set."})
return
}
addProvider(c)
})
apiProvidersMetaRoutes := router.Group("/providers/:pid")
apiProvidersMetaRoutes.Use(ProviderMetaHandler)
apiProvidersMetaRoutes.DELETE("", deleteProvider)
apiProvidersMetaRoutes.DELETE("", func(c *gin.Context) {
if cfg.DisableProviders {
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"errmsg": "Cannot delete provider as DisableProviders parameter is set."})
return
}
deleteProvider(c)
})
apiProviderRoutes := router.Group("/providers/:pid")
apiProviderRoutes.Use(ProviderHandler)
apiProviderRoutes.GET("", GetProvider)
apiProviderRoutes.PUT("", UpdateProvider)
apiProviderRoutes.PUT("", func(c *gin.Context) {
if cfg.DisableProviders {
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"errmsg": "Cannot update provider as DisableProviders parameter is set."})
return
}
UpdateProvider(c)
})
apiProviderRoutes.GET("/domains", getDomainsHostedByProvider)
}

View File

@ -33,6 +33,7 @@ func (o *Options) declareFlags() {
flag.StringVar(&o.DevProxy, "dev", o.DevProxy, "Proxify traffic to this host for static assets")
flag.StringVar(&o.AdminBind, "admin-bind", o.AdminBind, "Bind port/socket for administration interface")
flag.StringVar(&o.Bind, "bind", ":8081", "Bind port/socket")
flag.BoolVar(&o.DisableProviders, "disable-providers-edit", o.DisableProviders, "Disallow all actions on provider (add/edit/delete)")
flag.Var(&o.ExternalURL, "externalurl", "Begining of the URL, before the base, that should be used eg. in mails")
flag.StringVar(&o.BaseURL, "baseurl", o.BaseURL, "URL prepended to each URL")
flag.StringVar(&o.DefaultNameServer, "default-ns", o.DefaultNameServer, "Adress to the default name server")

View File

@ -52,6 +52,9 @@ type Options struct {
// DefaultNameServer is the NS server suggested by default.
DefaultNameServer string
// DisableProviders should disallow all actions on provider (add/edit/delete) through public API.
DisableProviders bool
// ExternalAuth is the URL of the login form to use instead of the embedded one.
ExternalAuth URL

View File

@ -56,6 +56,10 @@ func init() {
}
func DeclareRoutes(cfg *config.Options, router *gin.Engine) {
if cfg.DisableProviders {
CustomHeadHTML += `<script type="text/javascript">window.disable_providers = true;</script>`
}
if HideVoxPeople {
CustomHeadHTML += "<style>#voxpeople { display: none !important; }</style>"
}

View File

@ -111,13 +111,15 @@
>
<div class="card-header d-flex justify-content-between">
{$t("provider.title")}
<Button
size="sm"
color="light"
href="/providers/new"
>
<Icon name="plus" />
</Button>
{#if !window.disable_providers}
<Button
size="sm"
color="light"
href="/providers/new"
>
<Icon name="plus" />
</Button>
{/if}
</div>
{#if !$providers || !$providersSpecs}
<div class="d-flex justify-content-center">

View File

@ -41,15 +41,17 @@
</script>
<Container class="flex-fill pt-4 pb-5">
<Button
type="button"
color="primary"
class="float-end"
on:click={() => goto('providers/new')}
>
<Icon name="plus" />
{$t('common.add-new-thing', { thing: $t('provider.kind') })}
</Button>
{#if !window.disable_providers}
<Button
type="button"
color="primary"
class="float-end"
on:click={() => goto('providers/new')}
>
<Icon name="plus" />
{$t('common.add-new-thing', { thing: $t('provider.kind') })}
</Button>
{/if}
<h1 class="text-center mb-4">
{$t('provider.title')}
</h1>