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:
parent
3b7902802e
commit
3fddd78ebf
|
@ -45,6 +45,10 @@ max_send_errors = 1000
|
||||||
|
|
||||||
|
|
||||||
[privacy]
|
[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 subscribers to export data recorded on them?
|
||||||
allow_export = false
|
allow_export = false
|
||||||
|
|
||||||
|
|
1
main.go
1
main.go
|
@ -37,6 +37,7 @@ type constants struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type privacyOptions struct {
|
type privacyOptions struct {
|
||||||
|
AllowBlacklist bool `koanf:"allow_blacklist"`
|
||||||
AllowExport bool `koanf:"allow_export"`
|
AllowExport bool `koanf:"allow_export"`
|
||||||
AllowWipe bool `koanf:"allow_wipe"`
|
AllowWipe bool `koanf:"allow_wipe"`
|
||||||
Exportable map[string]bool `koanf:"-"`
|
Exportable map[string]bool `koanf:"-"`
|
||||||
|
|
27
public.go
27
public.go
|
@ -40,8 +40,7 @@ type publicTpl struct {
|
||||||
type unsubTpl struct {
|
type unsubTpl struct {
|
||||||
publicTpl
|
publicTpl
|
||||||
SubUUID string
|
SubUUID string
|
||||||
Unsubscribe bool
|
AllowBlacklist bool
|
||||||
Blacklist bool
|
|
||||||
AllowExport bool
|
AllowExport bool
|
||||||
AllowWipe bool
|
AllowWipe bool
|
||||||
}
|
}
|
||||||
|
@ -78,10 +77,9 @@ func handleSubscriptionPage(c echo.Context) error {
|
||||||
blacklist, _ = strconv.ParseBool(c.FormValue("blacklist"))
|
blacklist, _ = strconv.ParseBool(c.FormValue("blacklist"))
|
||||||
out = unsubTpl{}
|
out = unsubTpl{}
|
||||||
)
|
)
|
||||||
out.Unsubscribe = unsub
|
|
||||||
out.SubUUID = subUUID
|
out.SubUUID = subUUID
|
||||||
out.Blacklist = blacklist
|
|
||||||
out.Title = "Unsubscribe from mailing list"
|
out.Title = "Unsubscribe from mailing list"
|
||||||
|
out.AllowBlacklist = app.Constants.Privacy.AllowBlacklist
|
||||||
out.AllowExport = app.Constants.Privacy.AllowExport
|
out.AllowExport = app.Constants.Privacy.AllowExport
|
||||||
out.AllowWipe = app.Constants.Privacy.AllowWipe
|
out.AllowWipe = app.Constants.Privacy.AllowWipe
|
||||||
|
|
||||||
|
@ -95,22 +93,19 @@ func handleSubscriptionPage(c echo.Context) error {
|
||||||
|
|
||||||
// Unsubscribe.
|
// Unsubscribe.
|
||||||
if unsub {
|
if unsub {
|
||||||
res, err := app.Queries.Unsubscribe.Exec(campUUID, subUUID, blacklist)
|
// Is blacklisting allowed?
|
||||||
if err != nil {
|
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)
|
app.Logger.Printf("Error unsubscribing : %v", err)
|
||||||
return echo.NewHTTPError(http.StatusBadRequest,
|
return echo.NewHTTPError(http.StatusBadRequest,
|
||||||
"There was an internal error while unsubscribing you.")
|
"There was an internal error while unsubscribing you.")
|
||||||
}
|
}
|
||||||
|
return c.Render(http.StatusOK, "message",
|
||||||
if !blacklist {
|
makeMsgTpl("Unsubscribed", "",
|
||||||
num, _ := res.RowsAffected()
|
`You have been successfully unsubscribed.`))
|
||||||
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, "subscription", out)
|
return c.Render(http.StatusOK, "subscription", out)
|
||||||
|
|
|
@ -1,34 +1,23 @@
|
||||||
{{ define "subscription" }}
|
{{ define "subscription" }}
|
||||||
{{ template "header" .}}
|
{{ template "header" .}}
|
||||||
<section>
|
<section>
|
||||||
{{ if not .Data.Unsubscribe }}
|
|
||||||
<h2>Unsubscribe</h2>
|
<h2>Unsubscribe</h2>
|
||||||
<p>Do you wish to unsubscribe from this mailing list?</p>
|
<p>Do you wish to unsubscribe from this mailing list?</p>
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<div>
|
<p>
|
||||||
<input type="hidden" name="unsubscribe" value="true" />
|
<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>
|
<button type="submit" class="button" id="btn-unsub">Unsubscribe</button>
|
||||||
</div>
|
</p>
|
||||||
</form>
|
</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>
|
</section>
|
||||||
|
|
||||||
{{ if or .Data.AllowExport .Data.AllowWipe }}
|
{{ if or .Data.AllowExport .Data.AllowWipe }}
|
||||||
|
|
Loading…
Reference in New Issue