High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.
JavaScript campaigncampaign-managementemail-marketingemail-subscriptionlistmonkmailing-listnewsletternewsletter-managementnewsletter-softwareself-hostedsms-gatewaysmtptransactional-emails
fix #1950:Export of unsubscribed users exports all users (#1965)
Keshav Guptac334d2e6e181
diff --git a/cmd/subscribers.go b/cmd/subscribers.goindex d586d0a0..353387b7 100644--- a/cmd/subscribers.go+++ b/cmd/subscribers.go@@ -136,8 +136,11 @@ func handleExportSubscribers(c echo.Context) error {return echo.NewHTTPError(http.StatusBadRequest, app.i18n.T("globals.messages.invalidID"))}+ // Filter by subscription status+ subStatus := c.QueryParam("subscription_status")+// Get the batched export iterator.- exp, err := app.core.ExportSubscribers(query, subIDs, listIDs, app.constants.DBBatchSize)+ exp, err := app.core.ExportSubscribers(query, subIDs, listIDs, subStatus, app.constants.DBBatchSize)if err != nil {return err}diff --git a/frontend/src/views/Subscribers.vue b/frontend/src/views/Subscribers.vueindex b4e19388..f05e0559 100644--- a/frontend/src/views/Subscribers.vue+++ b/frontend/src/views/Subscribers.vue@@ -394,6 +394,10 @@ export default Vue.extend({q.append('list_id', this.queryParams.listID);}+ if (this.queryParams.subStatus) {+ q.append('subscription_status', this.queryParams.subStatus);+ }+// Export selected subscribers.if (!this.bulk.all && this.bulk.checked.length > 0) {this.bulk.checked.map((s) => q.append('id', s.id));diff --git a/internal/core/subscribers.go b/internal/core/subscribers.goindex c78acbfa..f2159170 100644--- a/internal/core/subscribers.go+++ b/internal/core/subscribers.go@@ -175,7 +175,7 @@ func (c *Core) GetSubscriberProfileForExport(id int, uuid string) (models.Subscr// on the given criteria in an exportable form. The iterator function returned can be called// repeatedly until there are nil subscribers. It's an iterator because exports can be extremely// large and may have to be fetched in batches from the DB and streamed somewhere.-func (c *Core) ExportSubscribers(query string, subIDs, listIDs []int, batchSize int) (func() ([]models.SubscriberExport, error), error) {+func (c *Core) ExportSubscribers(query string, subIDs, listIDs []int, subStatus string, batchSize int) (func() ([]models.SubscriberExport, error), error) {// There's an arbitrary query condition.cond := ""if query != "" {@@ -219,7 +219,7 @@ func (c *Core) ExportSubscribers(query string, subIDs, listIDs []int, batchSizeid := 0return func() ([]models.SubscriberExport, error) {var out []models.SubscriberExport- if err := tx.Select(&out, pq.Array(listIDs), id, pq.Array(subIDs), batchSize); err != nil {+ if err := tx.Select(&out, pq.Array(listIDs), id, pq.Array(subIDs), subStatus, batchSize); err != nil {c.log.Printf("error exporting subscribers by query: %v", err)return nil, echo.NewHTTPError(http.StatusInternalServerError,c.i18n.Ts("globals.messages.errorFetching", "name", "{globals.terms.subscribers}", "error", pqErrMsg(err)))diff --git a/queries.sql b/queries.sqlindex 9bed63ec..57cab4d4 100644--- a/queries.sql+++ b/queries.sql@@ -349,11 +349,12 @@ SELECT subscribers.id,-- Optional list filtering.(CASE WHEN CARDINALITY($1::INT[]) > 0 THEN true ELSE false END)AND subscriber_lists.subscriber_id = subscribers.id+ AND ($4 = '' OR subscriber_lists.status = $4::subscription_status))WHERE subscriber_lists.list_id = ALL($1::INT[]) AND id > $2AND (CASE WHEN CARDINALITY($3::INT[]) > 0 THEN id=ANY($3) ELSE true END)%query%- ORDER BY subscribers.id ASC LIMIT (CASE WHEN $4 < 1 THEN NULL ELSE $4 END);+ ORDER BY subscribers.id ASC LIMIT (CASE WHEN $5 < 1 THEN NULL ELSE $5 END);-- name: query-subscribers-template-- raw: true