diff --git a/cmd/public.go b/cmd/public.go index e78f57d9..38db934c 100644 --- a/cmd/public.go +++ b/cmd/public.go @@ -740,7 +740,7 @@ func (a *App) processSubForm(c echo.Context) (bool, error) { Name: req.Name, Email: req.Email, Status: models.SubscriberStatusEnabled, - }, nil, listUUIDs, false) + }, nil, listUUIDs, false, true) if err == 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. - _, 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 { return hasOptin, nil } diff --git a/cmd/subscribers.go b/cmd/subscribers.go index 8beb2640..5820029b 100644 --- a/cmd/subscribers.go +++ b/cmd/subscribers.go @@ -217,7 +217,7 @@ func (a *App) CreateSubscriber(c echo.Context) error { listIDs := user.FilterListsByPerm(auth.PermTypeManage, req.Lists) // 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 { return err } @@ -256,7 +256,7 @@ func (a *App) UpdateSubscriber(c echo.Context) error { // Update the subscriber in the DB. 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 { return err } diff --git a/frontend/cypress/e2e/users.cy.js b/frontend/cypress/e2e/users.cy.js index 74c769c2..ad8ded15 100644 --- a/frontend/cypress/e2e/users.cy.js +++ b/frontend/cypress/e2e/users.cy.js @@ -171,7 +171,7 @@ describe('Login ', () => { 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-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-delete]').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('exist'); }); }); diff --git a/internal/core/subscribers.go b/internal/core/subscribers.go index d2285ec1..8d1bd7df 100644 --- a/internal/core/subscribers.go +++ b/internal/core/subscribers.go @@ -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 // it was a new subscriber, and the second bool indicates if the subscriber was sent an optin confirmation. // 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() if err != nil { 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 { // Send a confirmation e-mail (if there are any double opt-in lists). num, err := c.h.SendOptinConfirmation(out, listIDs) - if err != nil { + if assertOptin && err != nil { 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. // If deleteLists is set to true, all existing subscriptions are deleted and only // 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 if preconfirm { subStatus = models.SubscriptionStatusConfirmed @@ -414,7 +414,7 @@ func (c *Core) UpdateSubscriberWithLists(id int, sub models.Subscriber, listIDs if !preconfirm && c.consts.SendOptinConfirmation { // Send a confirmation e-mail (if there are any double opt-in lists). num, err := c.h.SendOptinConfirmation(out, listIDs) - if err != nil { + if assertOptin && err != nil { return out, hasOptin, err } hasOptin = num > 0