Skip to content

Commit

Permalink
Add all to subscriber deletion by query which broke with query va…
Browse files Browse the repository at this point in the history
…lidation. Ref: #2122.
  • Loading branch information
knadh committed Dec 4, 2024
1 parent a129111 commit 7bfbd6a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 4 additions & 1 deletion cmd/subscribers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))
}

Expand Down
9 changes: 5 additions & 4 deletions docs/docs/content/apis/subscribers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/views/Subscribers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7bfbd6a

Please sign in to comment.