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
This commit is contained in:
Kailash Nadh 2019-07-21 19:43:43 +05:30
parent 3b7902802e
commit 3fddd78ebf
4 changed files with 38 additions and 49 deletions

View File

@ -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

View File

@ -37,6 +37,7 @@ type constants struct {
}
type privacyOptions struct {
AllowBlacklist bool `koanf:"allow_blacklist"`
AllowExport bool `koanf:"allow_export"`
AllowWipe bool `koanf:"allow_wipe"`
Exportable map[string]bool `koanf:"-"`

View File

@ -40,8 +40,7 @@ type publicTpl struct {
type unsubTpl struct {
publicTpl
SubUUID string
Unsubscribe bool
Blacklist bool
AllowBlacklist bool
AllowExport bool
AllowWipe bool
}
@ -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)

View File

@ -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>
<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 }}
<p>
<button type="submit" class="button" id="btn-unsub">Unsubscribe</button>
</div>
</p>
</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>
{{ end }}
{{ end }}
</section>
{{ if or .Data.AllowExport .Data.AllowWipe }}