浏览代码

Fix minor inconsistencies in settings.

- Add missing `app.root_url` key in migration.
- Register `/settings` handler in the backend.
- Add dummy dots in secret fields on the UI for visibility.
Kailash Nadh 5 年之前
父节点
当前提交
7ed07550ff
共有 5 个文件被更改,包括 28 次插入6 次删除
  1. 24 4
      frontend/src/views/Settings.vue
  2. 1 0
      handlers.go
  3. 1 0
      internal/migrations/v0.7.0.go
  4. 1 1
      queries.sql
  5. 1 1
      settings.go

+ 24 - 4
frontend/src/views/Settings.vue

@@ -177,7 +177,8 @@
                         <b-input v-model="form['upload.s3.aws_access_key_id']"
                             name="upload.s3.aws_access_key_id" :maxlength="200" />
                       </b-field>
-                      <b-field label="AWS access secret" label-position="on-border" expanded>
+                      <b-field label="AWS access secret" label-position="on-border" expanded
+                        message="Enter a value to change.">
                         <b-input v-model="form['upload.s3.aws_secret_access_key']"
                             name="upload.s3.aws_secret_access_key" type="password"
                             :maxlength="200" />
@@ -281,7 +282,7 @@
                               name="username" placeholder="mysmtp" :maxlength="200" />
                           </b-field>
                           <b-field label="Password" label-position="on-border" expanded
-                            message="Enter a value to change. Otherwise, leave empty.">
+                            message="Enter a value to change.">
                             <b-input v-model="item.password"
                               :disabled="item.auth_protocol === 'none'"
                               name="password" type="password" placeholder="Enter to change"
@@ -389,6 +390,8 @@ import { mapState } from 'vuex';
 import store from '../store';
 import { models } from '../constants';
 
+const dummyPassword = ' '.repeat(8);
+
 export default Vue.extend({
   data() {
     return {
@@ -419,10 +422,15 @@ export default Vue.extend({
     },
 
     onSubmit() {
-      const form = { ...this.form };
+      const form = JSON.parse(JSON.stringify(this.form));
 
       // De-serialize custom e-mail headers.
       for (let i = 0; i < form.smtp.length; i += 1) {
+        // If it's the dummy UI password placeholder, ignore it.
+        if (form.smtp[i].password === dummyPassword) {
+          form.smtp[i].password = '';
+        }
+
         if (form.smtp[i].strEmailHeaders && form.smtp[i].strEmailHeaders !== '[]') {
           form.smtp[i].email_headers = JSON.parse(form.smtp[i].strEmailHeaders);
         } else {
@@ -430,8 +438,12 @@ export default Vue.extend({
         }
       }
 
+      if (form['upload.s3.aws_secret_access_key'] === dummyPassword) {
+        form['upload.s3.aws_secret_access_key'] = '';
+      }
+
       this.isLoading = true;
-      this.$api.updateSettings(this.form).then((data) => {
+      this.$api.updateSettings(form).then((data) => {
         if (data.needsRestart) {
           // Update the 'needsRestart' flag on the global serverConfig state
           // as there are running campaigns and the app couldn't auto-restart.
@@ -462,6 +474,14 @@ export default Vue.extend({
         // Serialize the `email_headers` array map to display on the form.
         for (let i = 0; i < d.smtp.length; i += 1) {
           d.smtp[i].strEmailHeaders = JSON.stringify(d.smtp[i].email_headers, null, 4);
+
+          // The backend doesn't send passwords, so add a dummy so that it
+          // the password looks filled on the UI.
+          d.smtp[i].password = dummyPassword;
+        }
+
+        if (d['upload.provider'] === 's3') {
+          d['upload.s3.aws_secret_access_key'] = dummyPassword;
         }
 
         this.form = d;

+ 1 - 0
handlers.go

@@ -124,6 +124,7 @@ func registerHTTPHandlers(e *echo.Echo) {
 	e.GET("/campaigns/media", handleIndexPage)
 	e.GET("/campaigns/templates", handleIndexPage)
 	e.GET("/campaigns/:campignID", handleIndexPage)
+	e.GET("/settings", handleIndexPage)
 }
 
 // handleIndex is the root handler that renders the Javascript frontend.

+ 1 - 0
internal/migrations/v0.7.0.go

@@ -66,6 +66,7 @@ func V0_7_0(db *sqlx.DB, fs stuffbin.FileSystem, ko *koanf.Koanf) error {
 	
 	-- Insert default settings if the table is empty.
 	INSERT INTO settings (key, value) SELECT k, v::JSONB FROM (VALUES
+		('app.root_url', '"http://localhost:9000"'),
 		('app.favicon_url', '""'),
 		('app.from_email', '"listmonk <noreply@listmonk.yoursite.com>"'),
 		('app.logo_url', '"http://localhost:9000/public/static/logo.png"'),

+ 1 - 1
queries.sql

@@ -733,5 +733,5 @@ SELECT JSON_OBJECT_AGG(key, value) AS settings
 
 -- name: update-settings
 UPDATE settings AS s SET value = c.value
-    -- For each key in the incoming JSON map, update the row with the key and it's value.
+    -- For each key in the incoming JSON map, update the row with the key and its value.
     FROM(SELECT * FROM JSONB_EACH($1)) AS c(key, value) WHERE s.key = c.key;

+ 1 - 1
settings.go

@@ -117,7 +117,7 @@ func handleUpdateSettings(c echo.Context) error {
 	}
 	if !has {
 		return echo.NewHTTPError(http.StatusBadRequest,
-			"At least one SMTP block should be enabled")
+			"Minimum one SMTP block should be enabled.")
 	}
 
 	// S3 password?