High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.
JavaScript campaigncampaign-managementemail-marketingemail-subscriptionlistmonkmailing-listnewsletternewsletter-managementnewsletter-softwareself-hostedsms-gatewaysmtptransactional-emails
Refactor "unsubscribe from all" (self-blacklist) behaviour.
Kailash Nadh3fddd78ebf05
diff --git a/config.toml.sample b/config.toml.sampleindex 0a8d02fb..f58b0b93 100644--- a/config.toml.sample+++ b/config.toml.sample@@ -45,6 +45,10 @@ max_send_errors = 1000[privacy]+# Allow subscribers to unsubscribe from all mailing lists and mark themselves+# as blacklisted?+allow_blacklist = false+# Allow subscribers to export data recorded on them?allow_export = falsediff --git a/main.go b/main.goindex 9fa5a605..2dde5c25 100644--- a/main.go+++ b/main.go@@ -37,9 +37,10 @@ type constants struct {}type privacyOptions struct {- AllowExport bool `koanf:"allow_export"`- AllowWipe bool `koanf:"allow_wipe"`- Exportable map[string]bool `koanf:"-"`+ AllowBlacklist bool `koanf:"allow_blacklist"`+ AllowExport bool `koanf:"allow_export"`+ AllowWipe bool `koanf:"allow_wipe"`+ Exportable map[string]bool `koanf:"-"`}// App contains the "global" components that arediff --git a/public.go b/public.goindex 6dd83d29..7d141551 100644--- a/public.go+++ b/public.go@@ -39,11 +39,10 @@ type publicTpl struct {type unsubTpl struct {publicTpl- SubUUID string- Unsubscribe bool- Blacklist bool- AllowExport bool- AllowWipe bool+ SubUUID string+ AllowBlacklist bool+ AllowExport bool+ AllowWipe bool}type msgTpl struct {@@ -78,10 +77,9 @@ func handleSubscriptionPage(c echo.Context) error {blacklist, _ = strconv.ParseBool(c.FormValue("blacklist"))out = unsubTpl{})- out.Unsubscribe = unsubout.SubUUID = subUUID- out.Blacklist = blacklistout.Title = "Unsubscribe from mailing list"+ out.AllowBlacklist = app.Constants.Privacy.AllowBlacklistout.AllowExport = app.Constants.Privacy.AllowExportout.AllowWipe = app.Constants.Privacy.AllowWipe@@ -95,22 +93,19 @@ func handleSubscriptionPage(c echo.Context) error {// Unsubscribe.if unsub {- res, err := app.Queries.Unsubscribe.Exec(campUUID, subUUID, blacklist)- if err != nil {+ // Is blacklisting allowed?+ if !app.Constants.Privacy.AllowBlacklist {+ blacklist = false+ }++ if _, err := app.Queries.Unsubscribe.Exec(campUUID, subUUID, blacklist); err != nil {app.Logger.Printf("Error unsubscribing : %v", err)return echo.NewHTTPError(http.StatusBadRequest,"There was an internal error while unsubscribing you.")}-- if !blacklist {- num, _ := res.RowsAffected()- if num == 0 {- return c.Render(http.StatusBadRequest, "message",- makeMsgTpl("Already unsubscribed", "",- `You are not subscribed to this mailing list.- You may have already unsubscribed.`))- }- }+ return c.Render(http.StatusOK, "message",+ makeMsgTpl("Unsubscribed", "",+ `You have been successfully unsubscribed.`))}return c.Render(http.StatusOK, "subscription", out)diff --git a/public/templates/subscription.html b/public/templates/subscription.htmlindex 84b787c8..dce37ef9 100644--- a/public/templates/subscription.html+++ b/public/templates/subscription.html@@ -1,34 +1,23 @@{{ define "subscription" }}{{ template "header" .}}<section>- {{ if not .Data.Unsubscribe }}- <h2>Unsubscribe</h2>- <p>Do you wish to unsubscribe from this mailing list?</p>- <form method="post">- <div>- <input type="hidden" name="unsubscribe" value="true" />- <button type="submit" class="button" id="btn-unsub">Unsubscribe</button>- </div>- </form>- {{ else }}- <h2>You have been unsubscribed</h2>- {{ if not .Data.Blacklist }}- <div class="unsub-all">- <p>Unsubscribe from all future communications?</p>- <form method="post">- <div>- <input type="hidden" name="unsubscribe" value="true" />- <input type="hidden" name="blacklist" value="true" />- <button type="submit" class="button button-inline" id="btn-unsuball">- Unsubscribe all- </button>- </div>- </form>- </div>- {{ else }}- <p>You've been unsubscribed from all future communications.</p>+ <h2>Unsubscribe</h2>+ <p>Do you wish to unsubscribe from this mailing list?</p>+ <form method="post">+ <p>+ <input type="hidden" name="unsubscribe" value="true" />+ </p>++ {{ if .Data.AllowBlacklist }}+ <p>+ <input id="privacy-blacklist" type="checkbox" name="blacklist" value="true" /> <label for="privacy-blacklist">Also unsubscribe from all future e-mails.</label>+ </p>+{{ end }}- {{ end }}+ <p>+ <button type="submit" class="button" id="btn-unsub">Unsubscribe</button>+ </p>+ </form></section>{{ if or .Data.AllowExport .Data.AllowWipe }}