mirror of
https://github.com/knadh/listmonk.git
synced 2025-12-05 16:00:03 +01:00
Suppress optin e-mail send errors on subscriber insert/edit APIs.
This commit is contained in:
@@ -740,7 +740,7 @@ func (a *App) processSubForm(c echo.Context) (bool, error) {
|
|||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
Email: req.Email,
|
Email: req.Email,
|
||||||
Status: models.SubscriberStatusEnabled,
|
Status: models.SubscriberStatusEnabled,
|
||||||
}, nil, listUUIDs, false)
|
}, nil, listUUIDs, false, true)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return hasOptin, nil
|
return hasOptin, nil
|
||||||
}
|
}
|
||||||
@@ -757,7 +757,7 @@ func (a *App) processSubForm(c echo.Context) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update the subscriber's subscriptions in the DB.
|
// Update the subscriber's subscriptions in the DB.
|
||||||
_, hasOptin, err := a.core.UpdateSubscriberWithLists(sub.ID, sub, nil, listUUIDs, false, false)
|
_, hasOptin, err := a.core.UpdateSubscriberWithLists(sub.ID, sub, nil, listUUIDs, false, false, true)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return hasOptin, nil
|
return hasOptin, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ func (a *App) CreateSubscriber(c echo.Context) error {
|
|||||||
listIDs := user.FilterListsByPerm(auth.PermTypeManage, req.Lists)
|
listIDs := user.FilterListsByPerm(auth.PermTypeManage, req.Lists)
|
||||||
|
|
||||||
// Insert the subscriber into the DB.
|
// Insert the subscriber into the DB.
|
||||||
sub, _, err := a.core.InsertSubscriber(req.Subscriber, listIDs, nil, req.PreconfirmSubs)
|
sub, _, err := a.core.InsertSubscriber(req.Subscriber, listIDs, nil, req.PreconfirmSubs, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -256,7 +256,7 @@ func (a *App) UpdateSubscriber(c echo.Context) error {
|
|||||||
|
|
||||||
// Update the subscriber in the DB.
|
// Update the subscriber in the DB.
|
||||||
id := getID(c)
|
id := getID(c)
|
||||||
out, _, err := a.core.UpdateSubscriberWithLists(id, req.Subscriber, listIDs, nil, req.PreconfirmSubs, true)
|
out, _, err := a.core.UpdateSubscriberWithLists(id, req.Subscriber, listIDs, nil, req.PreconfirmSubs, true, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ describe('Login ', () => {
|
|||||||
cy.get('tbody tr').should('have.length', 2);
|
cy.get('tbody tr').should('have.length', 2);
|
||||||
cy.get('tbody tr:nth-child(1) [data-cy=btn-edit]').should('exist');
|
cy.get('tbody tr:nth-child(1) [data-cy=btn-edit]').should('exist');
|
||||||
cy.get('tbody tr:nth-child(1) [data-cy=btn-delete]').should('exist');
|
cy.get('tbody tr:nth-child(1) [data-cy=btn-delete]').should('exist');
|
||||||
cy.get('tbody tr:nth-child(2) [data-cy=btn-edit]').should('not.exist');
|
cy.get('tbody tr:nth-child(2) [data-cy=btn-edit]').should('exist');
|
||||||
cy.get('tbody tr:nth-child(2) [data-cy=btn-delete]').should('not.exist');
|
cy.get('tbody tr:nth-child(2) [data-cy=btn-delete]').should('exist');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ func (c *Core) ExportSubscribers(searchStr, query string, subIDs, listIDs []int,
|
|||||||
// InsertSubscriber inserts a subscriber and returns the ID. The first bool indicates if
|
// InsertSubscriber inserts a subscriber and returns the ID. The first bool indicates if
|
||||||
// it was a new subscriber, and the second bool indicates if the subscriber was sent an optin confirmation.
|
// it was a new subscriber, and the second bool indicates if the subscriber was sent an optin confirmation.
|
||||||
// bool = optinSent?
|
// bool = optinSent?
|
||||||
func (c *Core) InsertSubscriber(sub models.Subscriber, listIDs []int, listUUIDs []string, preconfirm bool) (models.Subscriber, bool, error) {
|
func (c *Core) InsertSubscriber(sub models.Subscriber, listIDs []int, listUUIDs []string, preconfirm, assertOptin bool) (models.Subscriber, bool, error) {
|
||||||
uu, err := uuid.NewV4()
|
uu, err := uuid.NewV4()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.log.Printf("error generating UUID: %v", err)
|
c.log.Printf("error generating UUID: %v", err)
|
||||||
@@ -325,7 +325,7 @@ func (c *Core) InsertSubscriber(sub models.Subscriber, listIDs []int, listUUIDs
|
|||||||
if !preconfirm && c.consts.SendOptinConfirmation {
|
if !preconfirm && c.consts.SendOptinConfirmation {
|
||||||
// Send a confirmation e-mail (if there are any double opt-in lists).
|
// Send a confirmation e-mail (if there are any double opt-in lists).
|
||||||
num, err := c.h.SendOptinConfirmation(out, listIDs)
|
num, err := c.h.SendOptinConfirmation(out, listIDs)
|
||||||
if err != nil {
|
if assertOptin && err != nil {
|
||||||
return out, hasOptin, err
|
return out, hasOptin, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,7 +372,7 @@ func (c *Core) UpdateSubscriber(id int, sub models.Subscriber) (models.Subscribe
|
|||||||
// UpdateSubscriberWithLists updates a subscriber's properties.
|
// UpdateSubscriberWithLists updates a subscriber's properties.
|
||||||
// If deleteLists is set to true, all existing subscriptions are deleted and only
|
// If deleteLists is set to true, all existing subscriptions are deleted and only
|
||||||
// the ones provided are added or retained.
|
// the ones provided are added or retained.
|
||||||
func (c *Core) UpdateSubscriberWithLists(id int, sub models.Subscriber, listIDs []int, listUUIDs []string, preconfirm, deleteLists bool) (models.Subscriber, bool, error) {
|
func (c *Core) UpdateSubscriberWithLists(id int, sub models.Subscriber, listIDs []int, listUUIDs []string, preconfirm, deleteLists, assertOptin bool) (models.Subscriber, bool, error) {
|
||||||
subStatus := models.SubscriptionStatusUnconfirmed
|
subStatus := models.SubscriptionStatusUnconfirmed
|
||||||
if preconfirm {
|
if preconfirm {
|
||||||
subStatus = models.SubscriptionStatusConfirmed
|
subStatus = models.SubscriptionStatusConfirmed
|
||||||
@@ -414,7 +414,7 @@ func (c *Core) UpdateSubscriberWithLists(id int, sub models.Subscriber, listIDs
|
|||||||
if !preconfirm && c.consts.SendOptinConfirmation {
|
if !preconfirm && c.consts.SendOptinConfirmation {
|
||||||
// Send a confirmation e-mail (if there are any double opt-in lists).
|
// Send a confirmation e-mail (if there are any double opt-in lists).
|
||||||
num, err := c.h.SendOptinConfirmation(out, listIDs)
|
num, err := c.h.SendOptinConfirmation(out, listIDs)
|
||||||
if err != nil {
|
if assertOptin && err != nil {
|
||||||
return out, hasOptin, err
|
return out, hasOptin, err
|
||||||
}
|
}
|
||||||
hasOptin = num > 0
|
hasOptin = num > 0
|
||||||
|
|||||||
Reference in New Issue
Block a user