Skip to content

Commit

Permalink
Fix settings form input validation.
Browse files Browse the repository at this point in the history
- Fix settings UI form submit button.
- Validate upload URI. Closes #621.
  • Loading branch information
knadh committed Dec 9, 2021
1 parent e9dded7 commit 4cb5eb7
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 62 deletions.
7 changes: 3 additions & 4 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func initMediaStore() media.Store {
o.RootURL = ko.String("app.root_url")
o.UploadPath = filepath.Clean(o.UploadPath)
o.UploadURI = filepath.Clean(o.UploadURI)
up, err := filesystem.NewDiskStore(o)
up, err := filesystem.New(o)
if err != nil {
lo.Fatalf("error initializing filesystem upload provider %s", err)
}
Expand Down Expand Up @@ -628,9 +628,8 @@ func initHTTPServer(app *App) *echo.Echo {
srv.GET("/admin/static/*", echo.WrapHandler(fSrv))

// Public (subscriber) facing media upload files.
if ko.String("upload.provider") == "filesystem" {
srv.Static(ko.String("upload.filesystem.upload_uri"),
ko.String("upload.filesystem.upload_path"))
if ko.String("upload.provider") == "filesystem" && ko.String("upload.filesystem.upload_uri") != "" {
srv.Static(ko.String("upload.filesystem.upload_uri"), ko.String("upload.filesystem.upload_path"))
}

// Register all HTTP handlers.
Expand Down
108 changes: 54 additions & 54 deletions frontend/src/views/Settings.vue
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
<template>
<section class="settings">
<b-loading :is-full-page="true" v-if="loading.settings || isLoading" active />
<header class="columns page-header">
<div class="column is-half">
<h1 class="title is-4">{{ $t('settings.title') }}
<span class="has-text-grey-light">({{ serverConfig.version }})</span>
</h1>
</div>
<div class="column has-text-right">
<b-field expanded>
<b-button expanded :disabled="!hasFormChanged"
type="is-primary" icon-left="content-save-outline"
@click="onSubmit" class="isSaveEnabled" data-cy="btn-save">
{{ $t('globals.buttons.save') }}
</b-button>
</b-field>
</div>
</header>
<hr />

<section class="wrap">
<form @submit.prevent="onSubmit">
<b-tabs type="is-boxed" :animated="false">
<b-tab-item :label="$t('settings.general.name')" label-position="on-border">
<general-settings :form="form" :key="key" />
</b-tab-item><!-- general -->

<b-tab-item :label="$t('settings.performance.name')">
<performance-settings :form="form" :key="key" />
</b-tab-item><!-- performance -->

<b-tab-item :label="$t('settings.privacy.name')">
<privacy-settings :form="form" :key="key" />
</b-tab-item><!-- privacy -->

<b-tab-item :label="$t('settings.media.title')">
<media-settings :form="form" :key="key" />
</b-tab-item><!-- media -->

<b-tab-item :label="$t('settings.smtp.name')">
<smtp-settings :form="form" :key="key" />
</b-tab-item><!-- mail servers -->

<b-tab-item :label="$t('settings.bounces.name')">
<bounce-settings :form="form" :key="key" />
</b-tab-item><!-- bounces -->

<b-tab-item :label="$t('settings.messengers.name')">
<messenger-settings :form="form" :key="key" />
</b-tab-item><!-- messengers -->
</b-tabs>

</form>
<form @submit.prevent="onSubmit">
<section class="settings">
<b-loading :is-full-page="true" v-if="loading.settings || isLoading" active />
<header class="columns page-header">
<div class="column is-half">
<h1 class="title is-4">{{ $t('settings.title') }}
<span class="has-text-grey-light">({{ serverConfig.version }})</span>
</h1>
</div>
<div class="column has-text-right">
<b-field expanded>
<b-button expanded :disabled="!hasFormChanged"
type="is-primary" icon-left="content-save-outline" native-type="submit"
class="isSaveEnabled" data-cy="btn-save">
{{ $t('globals.buttons.save') }}
</b-button>
</b-field>
</div>
</header>
<hr />

<section class="wrap">
<b-tabs type="is-boxed" :animated="false">
<b-tab-item :label="$t('settings.general.name')" label-position="on-border">
<general-settings :form="form" :key="key" />
</b-tab-item><!-- general -->

<b-tab-item :label="$t('settings.performance.name')">
<performance-settings :form="form" :key="key" />
</b-tab-item><!-- performance -->

<b-tab-item :label="$t('settings.privacy.name')">
<privacy-settings :form="form" :key="key" />
</b-tab-item><!-- privacy -->

<b-tab-item :label="$t('settings.media.title')">
<media-settings :form="form" :key="key" />
</b-tab-item><!-- media -->

<b-tab-item :label="$t('settings.smtp.name')">
<smtp-settings :form="form" :key="key" />
</b-tab-item><!-- mail servers -->

<b-tab-item :label="$t('settings.bounces.name')">
<bounce-settings :form="form" :key="key" />
</b-tab-item><!-- bounces -->

<b-tab-item :label="$t('settings.messengers.name')">
<messenger-settings :form="form" :key="key" />
</b-tab-item><!-- messengers -->
</b-tabs>

</section>
</section>
</section>
</form>
</template>

<script>
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/views/settings/media.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
:message="$t('settings.media.upload.pathHelp')">
<b-input v-model="data['upload.filesystem.upload_path']"
name="app.upload_path" placeholder='/home/listmonk/uploads'
:maxlength="200" />
:maxlength="200" required />
</b-field>

<b-field :label="$t('settings.media.upload.uri')" label-position="on-border"
:message="$t('settings.media.upload.uriHelp')">
<b-input v-model="data['upload.filesystem.upload_uri']"
name="app.upload_uri" placeholder='/uploads' :maxlength="200" />
name="app.upload_uri" placeholder='/uploads' :maxlength="200"
required pattern="^\/(.+?)" />
</b-field>
</div><!-- filesystem -->

Expand Down
4 changes: 2 additions & 2 deletions internal/media/providers/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ type Client struct {
// on the filesystem.
var fnameRegexp = regexp.MustCompile(`(.+?)_([0-9]+)$`)

// NewDiskStore initialises store for Filesystem provider.
func NewDiskStore(opts Opts) (media.Store, error) {
// New initialises store for Filesystem provider.
func New(opts Opts) (media.Store, error) {
return &Client{
opts: opts,
}, nil
Expand Down

0 comments on commit 4cb5eb7

Please sign in to comment.