SubscriptionPrefs renders the subscription management page and s unsubscriptions. This is the view that {{ UnsubscribeURL }} in campaigns link to.
(c echo.Context)
| 251 | // s unsubscriptions. This is the view that {{ UnsubscribeURL }} in |
| 252 | // campaigns link to. |
| 253 | func (a *App) SubscriptionPrefs(c echo.Context) error { |
| 254 | // Read the form. |
| 255 | var req struct { |
| 256 | Name string `form:"name" json:"name"` |
| 257 | ListUUIDs []string `form:"l" json:"list_uuids"` |
| 258 | Blocklist bool `form:"blocklist" json:"blocklist"` |
| 259 | Manage bool `form:"manage" json:"manage"` |
| 260 | } |
| 261 | if err := c.Bind(&req); err != nil { |
| 262 | return c.Render(http.StatusBadRequest, tplMessage, |
| 263 | makeMsgTpl(a.i18n.T("public.errorTitle"), "", a.i18n.T("globals.messages.invalidData"))) |
| 264 | } |
| 265 | |
| 266 | // Simple unsubscribe. |
| 267 | var ( |
| 268 | campUUID = c.Param("campUUID") |
| 269 | subUUID = c.Param("subUUID") |
| 270 | blocklist = a.cfg.Privacy.AllowBlocklist && req.Blocklist |
| 271 | ) |
| 272 | if !req.Manage || blocklist { |
| 273 | if err := a.core.UnsubscribeByCampaign(subUUID, campUUID, blocklist); err != nil { |
| 274 | return c.Render(http.StatusInternalServerError, tplMessage, |
| 275 | makeMsgTpl(a.i18n.T("public.errorTitle"), "", a.i18n.T("public.errorProcessingRequest"))) |
| 276 | } |
| 277 | |
| 278 | return c.Render(http.StatusOK, tplMessage, |
| 279 | makeMsgTpl(a.i18n.T("public.unsubbedTitle"), "", a.i18n.T("public.unsubbedInfo"))) |
| 280 | } |
| 281 | |
| 282 | // Is preference management enabled? |
| 283 | if !a.cfg.Privacy.AllowPreferences { |
| 284 | return c.Render(http.StatusBadRequest, tplMessage, |
| 285 | makeMsgTpl(a.i18n.T("public.errorTitle"), "", a.i18n.T("public.invalidFeature"))) |
| 286 | } |
| 287 | |
| 288 | // Manage preferences. |
| 289 | req.Name = strings.TrimSpace(req.Name) |
| 290 | if req.Name == "" || len(req.Name) > 256 { |
| 291 | return c.Render(http.StatusBadRequest, tplMessage, |
| 292 | makeMsgTpl(a.i18n.T("public.errorTitle"), "", a.i18n.T("subscribers.invalidName"))) |
| 293 | } |
| 294 | |
| 295 | // Get the subscriber from the DB. |
| 296 | sub, err := a.core.GetSubscriber(0, subUUID, "") |
| 297 | if err != nil { |
| 298 | return c.Render(http.StatusInternalServerError, tplMessage, |
| 299 | makeMsgTpl(a.i18n.T("public.errorTitle"), "", a.i18n.Ts("globals.messages.pFound", |
| 300 | "name", a.i18n.T("globals.terms.subscriber")))) |
| 301 | } |
| 302 | sub.Name = req.Name |
| 303 | |
| 304 | // Update the subscriber properties in the DB. |
| 305 | if _, err := a.core.UpdateSubscriber(sub.ID, sub); err != nil { |
| 306 | return c.Render(http.StatusInternalServerError, tplMessage, |
| 307 | makeMsgTpl(a.i18n.T("public.errorTitle"), "", a.i18n.T("public.errorProcessingRequest"))) |
| 308 | } |
| 309 | |
| 310 | // Get the subscriber's lists and whatever is not sent in the request (unchecked), |
nothing calls this directly
no test coverage detected