Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

Add `all` to subscriber deletion by query which broke with `query` validation. Ref: #2122.

Kailash Nadh7bfbd6a85612
diff --git a/cmd/subscribers.go b/cmd/subscribers.go
index 5497cbb4..1f65b38e 100644
--- a/cmd/subscribers.go
+++ b/cmd/subscribers.go
@@ -30,6 +30,7 @@ type subQueryReq struct {
Action string `json:"action"`
Status string `json:"status"`
SubscriptionStatus string `json:"subscription_status"`
+ All bool `json:"all"`
}
// subProfileData represents a subscriber's collated data in JSON
@@ -439,7 +440,9 @@ func handleDeleteSubscribersByQuery(c echo.Context) error {
return err
}
- if req.Query == "" {
+ if req.All {
+ req.Query = ""
+ } else if req.Query == "" {
return echo.NewHTTPError(http.StatusBadRequest, app.i18n.Ts("globals.messages.invalidFields", "name", "query"))
}
diff --git a/docs/docs/content/apis/subscribers.md b/docs/docs/content/apis/subscribers.md
index 2ac6529f..c22c61d9 100644
--- a/docs/docs/content/apis/subscribers.md
+++ b/docs/docs/content/apis/subscribers.md
@@ -604,10 +604,11 @@ Delete subscribers based on SQL expression.
##### Parameters
-| Name | Type | Required | Description |
-|:---------|:---------|:---------|:--------------------------------------------|
-| query | string | Yes | SQL expression to filter subscribers with. |
-| list_ids | []number | No | Optional list IDs to limit the filtering to.|
+| Name | Type | Required | Description |
+|:---------|:---------|:---------|:-------------------------------------------------------------------|
+| query | string | No | SQL expression to filter subscribers with. |
+| list_ids | []number | No | Optional list IDs to limit the filtering to. |
+| all | bool | No | When set to `true`, ignores any query and deletes all subscribers. |
##### Example Request
diff --git a/frontend/src/views/Subscribers.vue b/frontend/src/views/Subscribers.vue
index 1c8d1c38..5b25cde8 100644
--- a/frontend/src/views/Subscribers.vue
+++ b/frontend/src/views/Subscribers.vue
@@ -423,6 +423,9 @@ export default Vue.extend({
// 'All' is selected, delete by query.
fn = () => {
this.$api.deleteSubscribersByQuery({
+ // If the query expression is empty, explicitly pass `all=true`
+ // so that the backend deletes all records in the DB with an empty query string.
+ all: this.queryParams.queryExp.trim() === '',
query: this.queryParams.queryExp,
list_ids: this.queryParams.listID ? [this.queryParams.listID] : null,
subscription_status: this.queryParams.subStatus,