From 3fddd78ebf0513a41828ffc09fc7a9380510e464 Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Sun, 21 Jul 2019 19:43:43 +0530 Subject: [PATCH] Refactor "unsubscribe from all" (self-blacklist) behaviour. - Add an option to toggle allowing subscribers to blacklist themselves. - Move the "unsubscribe from all" to the subscription management page --- config.toml.sample | 4 +++ main.go | 7 ++--- public.go | 33 ++++++++++------------- public/templates/subscription.html | 43 +++++++++++------------------- 4 files changed, 38 insertions(+), 49 deletions(-) diff --git a/config.toml.sample b/config.toml.sample index 0a8d02f..f58b0b9 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 = false diff --git a/main.go b/main.go index 9fa5a60..2dde5c2 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 are diff --git a/public.go b/public.go index 6dd83d2..7d14155 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 = unsub out.SubUUID = subUUID - out.Blacklist = blacklist out.Title = "Unsubscribe from mailing list" + out.AllowBlacklist = app.Constants.Privacy.AllowBlacklist out.AllowExport = app.Constants.Privacy.AllowExport out.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.html index 84b787c..dce37ef 100644 --- a/public/templates/subscription.html +++ b/public/templates/subscription.html @@ -1,34 +1,23 @@ {{ define "subscription" }} {{ template "header" .}}
- {{ if not .Data.Unsubscribe }} -

Unsubscribe

-

Do you wish to unsubscribe from this mailing list?

-
-
- - -
-
- {{ else }} -

You have been unsubscribed

- {{ if not .Data.Blacklist }} -
-

Unsubscribe from all future communications?

-
-
- - - -
-
-
- {{ else }} -

You've been unsubscribed from all future communications.

+

Unsubscribe

+

Do you wish to unsubscribe from this mailing list?

+
+

+ +

+ + {{ if .Data.AllowBlacklist }} +

+ +

+ {{ end }} - {{ end }} +

+ +

+
{{ if or .Data.AllowExport .Data.AllowWipe }}