MCPcopy
hub / github.com/knadh/listmonk / SelfExportSubscriberData

Method SelfExportSubscriberData

cmd/public.go:616–667  ·  view source on GitHub ↗

SelfExportSubscriberData pulls the subscriber's profile, list subscriptions, campaign views and clicks and produces a JSON report that is then e-mailed to the subscriber. This is a privacy feature and the data that's exported is dependent on the configuration.

(c echo.Context)

Source from the content-addressed store, hash-verified

614// to the subscriber. This is a privacy feature and the data that's exported
615// is dependent on the configuration.
616func (a *App) SelfExportSubscriberData(c echo.Context) error {
617 // Is export allowed?
618 if !a.cfg.Privacy.AllowExport {
619 return c.Render(http.StatusBadRequest, tplMessage,
620 makeMsgTpl(a.i18n.T("public.errorTitle"), "", a.i18n.Ts("public.invalidFeature")))
621 }
622
623 // Get the subscriber's data. A single query that gets the profile,
624 // list subscriptions, campaign views, and link clicks. Names of
625 // private lists are replaced with "Private list".
626 subUUID := c.Param("subUUID")
627 data, b, err := a.exportSubscriberData(0, subUUID, a.cfg.Privacy.Exportable)
628 if err != nil {
629 a.log.Printf("error exporting subscriber data: %s", err)
630 return c.Render(http.StatusInternalServerError, tplMessage,
631 makeMsgTpl(a.i18n.T("public.errorTitle"), "", a.i18n.Ts("public.errorProcessingRequest")))
632 }
633
634 // Prepare the attachment e-mail.
635 var msg bytes.Buffer
636 if err := notifs.Tpls.ExecuteTemplate(&msg, notifs.TplSubscriberData, data); err != nil {
637 a.log.Printf("error compiling notification template '%s': %v", notifs.TplSubscriberData, err)
638 return c.Render(http.StatusInternalServerError, tplMessage,
639 makeMsgTpl(a.i18n.T("public.errorTitle"), "", a.i18n.Ts("public.errorProcessingRequest")))
640 }
641
642 // TODO: GetTplSubject should be moved to a utils package.
643 subject, body := notifs.GetTplSubject(a.i18n.Ts("email.data.title"), msg.Bytes())
644
645 // E-mail the data as a JSON attachment to the subscriber.
646 const fname = "data.json"
647 if err := a.emailMsgr.Push(models.Message{
648 From: a.cfg.FromEmail,
649 To: []string{data.Email},
650 Subject: subject,
651 Body: body,
652 Attachments: []models.Attachment{
653 {
654 Name: fname,
655 Content: b,
656 Header: manager.MakeAttachmentHeader(fname, "base64", "application/json"),
657 },
658 },
659 }); err != nil {
660 a.log.Printf("error e-mailing subscriber profile: %s", err)
661 return c.Render(http.StatusInternalServerError, tplMessage,
662 makeMsgTpl(a.i18n.T("public.errorTitle"), "", a.i18n.Ts("public.errorProcessingRequest")))
663 }
664
665 return c.Render(http.StatusOK, tplMessage,
666 makeMsgTpl(a.i18n.T("public.dataSentTitle"), "", a.i18n.T("public.dataSent")))
667}
668
669// WipeSubscriberData allows a subscriber to delete their data. The
670// profile and subscriptions are deleted, while the campaign_views and link

Callers

nothing calls this directly

Calls 8

exportSubscriberDataMethod · 0.95
GetTplSubjectFunction · 0.92
MakeAttachmentHeaderFunction · 0.92
makeMsgTplFunction · 0.85
TMethod · 0.80
TsMethod · 0.80
PushMethod · 0.65
RenderMethod · 0.45

Tested by

no test coverage detected