From 04ea18c87d807ab63606bbc26ca0cd0d318a32b0 Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Sat, 15 Jan 2022 15:50:13 +0530 Subject: [PATCH] Refactor opt-in confirmation behaviour in subscriber update API. - Updating a subscriber no longer triggers an opt-in confirmation mail as `POST /api/subscribers/:id/optin` allows that. - A "Send opt-in confirmation" option is added to the subscriber update UI. Closes #656. --- cmd/subscribers.go | 4 ---- frontend/src/api/index.js | 3 +++ frontend/src/assets/style.scss | 4 ++++ frontend/src/views/SubscriberForm.vue | 30 +++++++++++++++++++++++---- i18n/cs-cz.json | 2 ++ i18n/de.json | 2 ++ i18n/en.json | 2 ++ i18n/es.json | 2 ++ i18n/fr.json | 2 ++ i18n/hu.json | 2 ++ i18n/it.json | 2 ++ i18n/ml.json | 2 ++ i18n/nl.json | 2 ++ i18n/pl.json | 2 ++ i18n/pt-BR.json | 2 ++ i18n/pt.json | 2 ++ i18n/ro.json | 2 ++ i18n/ru.json | 2 ++ i18n/tr.json | 2 ++ 19 files changed, 63 insertions(+), 8 deletions(-) diff --git a/cmd/subscribers.go b/cmd/subscribers.go index 4e25a9b..8559460 100644 --- a/cmd/subscribers.go +++ b/cmd/subscribers.go @@ -367,10 +367,6 @@ func handleUpdateSubscriber(c echo.Context) error { return err } - if !req.PreconfirmSubs && app.constants.SendOptinConfirmation { - _, _ = sendOptinConfirmation(sub, []int64(req.Lists), app) - } - return c.JSON(http.StatusOK, okResp{sub}) } diff --git a/frontend/src/api/index.js b/frontend/src/api/index.js index 41dff58..0fab357 100644 --- a/frontend/src/api/index.js +++ b/frontend/src/api/index.js @@ -158,6 +158,9 @@ export const createSubscriber = (data) => http.post('/api/subscribers', data, export const updateSubscriber = (data) => http.put(`/api/subscribers/${data.id}`, data, { loading: models.subscribers }); +export const sendSubscriberOptin = (id) => http.post(`/api/subscribers/${id}/optin`, {}, + { loading: models.subscribers }); + export const deleteSubscriber = (id) => http.delete(`/api/subscribers/${id}`, { loading: models.subscribers }); diff --git a/frontend/src/assets/style.scss b/frontend/src/assets/style.scss index 720b2b7..cbdf64e 100644 --- a/frontend/src/assets/style.scss +++ b/frontend/src/assets/style.scss @@ -104,6 +104,10 @@ section { } } +.is-disabled { + opacity: 0.30; +} + .box { background: $white; box-shadow: 2px 2px 0 #f3f3f3; diff --git a/frontend/src/views/SubscriberForm.vue b/frontend/src/views/SubscriberForm.vue index 9a32c25..a2d164c 100644 --- a/frontend/src/views/SubscriberForm.vue +++ b/frontend/src/views/SubscriberForm.vue @@ -48,10 +48,22 @@ :all="lists.results" > - - {{ $t('subscribers.preconfirm') }} - +
+
+ + + {{ $t('subscribers.preconfirm') }} + + +
+ +
@@ -250,6 +262,12 @@ export default Vue.extend({ }); }, + sendOptinConfirmation() { + this.$api.sendSubscriberOptin(this.form.id).then(() => { + this.$utils.toast(this.$t('subscribers.sentOptinConfirm')); + }); + }, + validateAttribs(str) { // Parse and validate attributes JSON. let attribs = {}; @@ -271,6 +289,10 @@ export default Vue.extend({ computed: { ...mapState(['lists', 'loading']), + + hasOptinList() { + return this.form.lists.some((l) => l.optin === 'double'); + }, }, mounted() { diff --git a/i18n/cs-cz.json b/i18n/cs-cz.json index 092c48b..6e9c9c3 100644 --- a/i18n/cs-cz.json +++ b/i18n/cs-cz.json @@ -479,6 +479,8 @@ "subscribers.queryPlaceholder": "E-mail nebo jméno", "subscribers.reset": "Reset", "subscribers.selectAll": "Vybrat vše {num}", + "subscribers.sendOptinConfirm": "Send opt-in confirmation", + "subscribers.sentOptinConfirm": "Opt-in confirmation sent", "subscribers.status.blocklisted": "Uvedeno na seznamu blokovaných", "subscribers.status.confirmed": "Potvrzeno", "subscribers.status.enabled": "Povoleno", diff --git a/i18n/de.json b/i18n/de.json index 84828cd..50ddafc 100644 --- a/i18n/de.json +++ b/i18n/de.json @@ -479,6 +479,8 @@ "subscribers.queryPlaceholder": "E-Mail oder Name", "subscribers.reset": "Zurücksetzen", "subscribers.selectAll": "Wähle alle {num}", + "subscribers.sendOptinConfirm": "Send opt-in confirmation", + "subscribers.sentOptinConfirm": "Opt-in confirmation sent", "subscribers.status.blocklisted": "Blockiert", "subscribers.status.confirmed": "Bestätigt", "subscribers.status.enabled": "Aktiviert", diff --git a/i18n/en.json b/i18n/en.json index c87232c..12e17c7 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -479,6 +479,8 @@ "subscribers.queryPlaceholder": "E-mail or name", "subscribers.reset": "Reset", "subscribers.selectAll": "Select all {num}", + "subscribers.sendOptinConfirm": "Send opt-in confirmation", + "subscribers.sentOptinConfirm": "Opt-in confirmation sent", "subscribers.status.blocklisted": "Blocklisted", "subscribers.status.confirmed": "Confirmed", "subscribers.status.enabled": "Enabled", diff --git a/i18n/es.json b/i18n/es.json index 56311c4..4e0390b 100644 --- a/i18n/es.json +++ b/i18n/es.json @@ -479,6 +479,8 @@ "subscribers.queryPlaceholder": "Correo electrónico o nombre", "subscribers.reset": "Restablecer", "subscribers.selectAll": "Seleccionar todos {num}", + "subscribers.sendOptinConfirm": "Send opt-in confirmation", + "subscribers.sentOptinConfirm": "Opt-in confirmation sent", "subscribers.status.blocklisted": "Bloqueado", "subscribers.status.confirmed": "Confirmado", "subscribers.status.enabled": "Habilitado", diff --git a/i18n/fr.json b/i18n/fr.json index be1596b..f181841 100644 --- a/i18n/fr.json +++ b/i18n/fr.json @@ -479,6 +479,8 @@ "subscribers.queryPlaceholder": "Email ou nom", "subscribers.reset": "Réinitialiser", "subscribers.selectAll": "Sélectionner tout {num}", + "subscribers.sendOptinConfirm": "Send opt-in confirmation", + "subscribers.sentOptinConfirm": "Opt-in confirmation sent", "subscribers.status.blocklisted": "Bloqué·e", "subscribers.status.confirmed": "Confirmé·e", "subscribers.status.enabled": "Activé·e", diff --git a/i18n/hu.json b/i18n/hu.json index bc797bf..993adf6 100644 --- a/i18n/hu.json +++ b/i18n/hu.json @@ -479,6 +479,8 @@ "subscribers.queryPlaceholder": "E-mail vagy név", "subscribers.reset": "Visszaállítás", "subscribers.selectAll": "Összes kijelölése {num}", + "subscribers.sendOptinConfirm": "Send opt-in confirmation", + "subscribers.sentOptinConfirm": "Opt-in confirmation sent", "subscribers.status.blocklisted": "Feketelistás", "subscribers.status.confirmed": "Megerősített", "subscribers.status.enabled": "Engedélyezve", diff --git a/i18n/it.json b/i18n/it.json index 266c9f8..238e6bb 100644 --- a/i18n/it.json +++ b/i18n/it.json @@ -479,6 +479,8 @@ "subscribers.queryPlaceholder": "Email o nome", "subscribers.reset": "Ripristina", "subscribers.selectAll": "Seleziona tutto {num}", + "subscribers.sendOptinConfirm": "Send opt-in confirmation", + "subscribers.sentOptinConfirm": "Opt-in confirmation sent", "subscribers.status.blocklisted": "Lista bloccata", "subscribers.status.confirmed": "Confermato", "subscribers.status.enabled": "Attivata", diff --git a/i18n/ml.json b/i18n/ml.json index fa809d0..1113e2c 100644 --- a/i18n/ml.json +++ b/i18n/ml.json @@ -479,6 +479,8 @@ "subscribers.queryPlaceholder": "പേരോ ഇ-മെയിൽ വിലാസമോ", "subscribers.reset": "പുനഃസജ്ജമാക്കുക", "subscribers.selectAll": "{num} എല്ലാം തിരഞ്ഞടുക്കുക", + "subscribers.sendOptinConfirm": "Send opt-in confirmation", + "subscribers.sentOptinConfirm": "Opt-in confirmation sent", "subscribers.status.blocklisted": "തടയുന്ന പട്ടികയിൽ ചേർത്തു", "subscribers.status.confirmed": "Confirmed", "subscribers.status.enabled": "പ്രവർത്തനക്ഷമാക്കി", diff --git a/i18n/nl.json b/i18n/nl.json index 9d19bfb..d645e04 100644 --- a/i18n/nl.json +++ b/i18n/nl.json @@ -479,6 +479,8 @@ "subscribers.queryPlaceholder": "E-mail of naam", "subscribers.reset": "Resetten", "subscribers.selectAll": "Selecteer alle {num}", + "subscribers.sendOptinConfirm": "Send opt-in confirmation", + "subscribers.sentOptinConfirm": "Opt-in confirmation sent", "subscribers.status.blocklisted": "Geblokkeerd", "subscribers.status.confirmed": "Bevestigd", "subscribers.status.enabled": "Geactiveerd", diff --git a/i18n/pl.json b/i18n/pl.json index 64ff503..6f10c84 100644 --- a/i18n/pl.json +++ b/i18n/pl.json @@ -479,6 +479,8 @@ "subscribers.queryPlaceholder": "E-mail lub nazwa", "subscribers.reset": "Resetuj", "subscribers.selectAll": "Wybierz wszystkich {num}", + "subscribers.sendOptinConfirm": "Send opt-in confirmation", + "subscribers.sentOptinConfirm": "Opt-in confirmation sent", "subscribers.status.blocklisted": "Zablokowany", "subscribers.status.confirmed": "Potwierdzony", "subscribers.status.enabled": "Aktywny", diff --git a/i18n/pt-BR.json b/i18n/pt-BR.json index ba29c89..77837b5 100644 --- a/i18n/pt-BR.json +++ b/i18n/pt-BR.json @@ -479,6 +479,8 @@ "subscribers.queryPlaceholder": "E-mail ou nome", "subscribers.reset": "Redefinir", "subscribers.selectAll": "Selecionar todos {num}", + "subscribers.sendOptinConfirm": "Send opt-in confirmation", + "subscribers.sentOptinConfirm": "Opt-in confirmation sent", "subscribers.status.blocklisted": "Lista de bloqueados", "subscribers.status.confirmed": "Confirmado", "subscribers.status.enabled": "Habilitado", diff --git a/i18n/pt.json b/i18n/pt.json index 2602583..a0bc234 100644 --- a/i18n/pt.json +++ b/i18n/pt.json @@ -479,6 +479,8 @@ "subscribers.queryPlaceholder": "E-mail ou nome", "subscribers.reset": "Repor", "subscribers.selectAll": "Selecionar todos os {num}", + "subscribers.sendOptinConfirm": "Send opt-in confirmation", + "subscribers.sentOptinConfirm": "Opt-in confirmation sent", "subscribers.status.blocklisted": "Bloqueados", "subscribers.status.confirmed": "Confirmado", "subscribers.status.enabled": "Ativo", diff --git a/i18n/ro.json b/i18n/ro.json index d863c2f..f9fb478 100644 --- a/i18n/ro.json +++ b/i18n/ro.json @@ -479,6 +479,8 @@ "subscribers.queryPlaceholder": "Email sau nume", "subscribers.reset": "Reset", "subscribers.selectAll": "Selectează tot {număr}", + "subscribers.sendOptinConfirm": "Send opt-in confirmation", + "subscribers.sentOptinConfirm": "Opt-in confirmation sent", "subscribers.status.blocklisted": "În lista neagră", "subscribers.status.confirmed": "Confirmat", "subscribers.status.enabled": "Activfat", diff --git a/i18n/ru.json b/i18n/ru.json index 1fd3b3e..7d773ae 100644 --- a/i18n/ru.json +++ b/i18n/ru.json @@ -479,6 +479,8 @@ "subscribers.queryPlaceholder": "E-mail или имя", "subscribers.reset": "Сброс", "subscribers.selectAll": "Выбрать все {num}", + "subscribers.sendOptinConfirm": "Send opt-in confirmation", + "subscribers.sentOptinConfirm": "Opt-in confirmation sent", "subscribers.status.blocklisted": "Заблокирован", "subscribers.status.confirmed": "Подтверждён", "subscribers.status.enabled": "Включён", diff --git a/i18n/tr.json b/i18n/tr.json index c30566f..52b909f 100644 --- a/i18n/tr.json +++ b/i18n/tr.json @@ -479,6 +479,8 @@ "subscribers.queryPlaceholder": "E-posta veya isim", "subscribers.reset": "Sıfırla", "subscribers.selectAll": "Select all {num}", + "subscribers.sendOptinConfirm": "Send opt-in confirmation", + "subscribers.sentOptinConfirm": "Opt-in confirmation sent", "subscribers.status.blocklisted": "Engellenmiş", "subscribers.status.confirmed": "Doğrulanmış", "subscribers.status.enabled": "Etkinleştirildi",