[AdamPS] Updated text

Problem/Motivation

I can confirm the following bug:

  1. Set up 2 newsletters: A = silent, hidden; B = double,none
  2. Create a user
  3. As admin, edit this user's subscription using page admin/people/simplenews/edit/{simplenews_subscriber}. Click save without changing anything.
  4. Bug: the hidden newsletter is unsubscribed.

Proposed resolution

I found that this bug is solved by just part of the supplied patch, by changing simplenews_newsletter_get_visible to simplenews_newsletter_get_all.

User interface changes

None.

API changes

None.

[andrewbelcher] original text

Problem/Motivation

SubscriptionsFormBase has some special handling to preserve existing subscription information. This has only partial code implementation in SubscriberForm that results in all data being overwritten and lost. It also only processes visible subscriptions, but the form includes all subscriptions.

Proposed resolution

Quick solution would be to copy the handling over from SubscriptionsFormBase.

The better and longer term fix would probably be to move the process into SubscriptionWidget::extractFormValues which is where I think it should live and will mean any usage of the subscription widget will behave properly.

User interface changes

None.

API changes

Short term - fix the form. Longer term, move the processing logic to the widget for consistency.

Comments

andrewbelcher created an issue. See original summary.

andrewbelcher’s picture

Here's a patch for the quick fix in case anyone needs it. Might be worth committing and doing another release as this is causing data loss currently.

andrewbelcher’s picture

Assigned: andrewbelcher » Unassigned
Status: Active » Needs review
adamps’s picture

Priority: Critical » Normal

See description of priority field - this issue does not make the module completely unusable.

andrewbelcher’s picture

Priority: Normal » Critical

But it does cause data loss:

Cause loss/corruption of stored data.

Feel free to downgrade again if you still disagree.

adamps’s picture

To me it's not clear that the "better and longer term fix" is much more complex that the short term fix. Might it make sense to put the better fix in straight away?

You are right there is data loss, but only in specific conditions something like this:

  • there is at least one subscription that is hidden
  • there is at least one subscription that is visible
  • an admin edits the visible subscription of another user
  • the other user had the hidden subscription enabled
adamps’s picture

Issue summary: View changes

The issue summary does not actually describe the exact symptoms of the bug. I can confirm there is a bug and have added IS text to describe it. The bug that I found seems to be solved by just part of the supplied patch, by changing simplenews_newsletter_get_visible to simplenews_newsletter_get_all.

@andrewbelcher Please can you confirm, or let me know if you think I have missed anything?

I have added some tests and I will upload a new patch.

The last submitted patch, 8: simplenews.overwrite-data.ONLYTESTS.3013721-8.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

adamps’s picture

Issue tags: +Plan to commit

The failure was the ONLYTESTS patch as expected, so this looks ready.

adamps’s picture

Wait a moment.....

I am surprised that the hidden newsletters are visible even on the admin page - that seems like a bug to me.

I have raised #3035521: Admin should not be able to modify subscriptions for hidden newsletters. We need to get that resolved before going any further here.

adamps’s picture

Status: Postponed » Needs review
StatusFileSize
new10.59 KB

Status: Needs review » Needs work

The last submitted patch, 12: simplenews.overwrite-data.3013721-12.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

adamps’s picture

Both this bug and #3035521: Admin should not be able to modify subscriptions for hidden newsletters are caused by SubscriberForm missing important code in SubscriptionsFormBase. The solution is to update the base class of SubscriberForm to be SubscriptionsFormBase matching the other three subscription forms.

Then I had some confusion trying to understand and update the way these forms work. Here is the explanation of what I did:

  • SubscriberForm delete a lot of code that is in the new base class.
  • SubscriberForm delete code for isNew because it is wrong and not hittable until #3037036: Create button to add a single subscriber.
  • Update SubscriptionsFormBase::actions to work with SubscriberForm. This is a rewrite as I found the old code very difficult to understand/update. New code calls the parent function which reduces duplication. New code gets ready for #3031919: Bugs if user has blank email address.
  • SubscriptionsBlockForm::actions is not needed - the base class already has the same code.
  • static::SUBMIT_UPDATE keep the default button text of 'Save' except override it in SubscriptionsPageForm.
adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new10.5 KB
new1.14 KB

Status: Needs review » Needs work

The last submitted patch, 15: simplenews.overwrite-data.3013721-15.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

adamps’s picture

Status: Needs work » Needs review
Issue tags: -Plan to commit
StatusFileSize
new11.44 KB
new1.65 KB

Hmm tricker than I expected. I've added a detailed comment.

I am keen to avoid checking against empty mail because that breaks in the case of a user account with no email defined - we have another issue for that.

Status: Needs review » Needs work

The last submitted patch, 17: simplenews.overwrite-data.3013721-17.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new11.44 KB
new619 bytes

Apologies to the others following this issue. Hopefully this time.....

Status: Needs review » Needs work

The last submitted patch, 19: simplenews.overwrite-data.3013721-19.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

adamps’s picture

Status: Needs review » Needs work

The last submitted patch, 21: simplenews.overwrite-data.3013721-21.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new12.33 KB
new1.34 KB

So there is another bug relating to missing code from SubscriptionsFormBase. SubscriberForm must not allow edit of email address if the subscriber is a user.

adamps’s picture

Issue tags: +Plan to commit

OK, I plan to commit this in 1 week. Any comments/review before that would be appreciated.

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/src/Form/SubscriptionsFormBase.php
    @@ -132,7 +139,9 @@ abstract class SubscriptionsFormBase extends ContentEntityForm {
         if ($mail = $this->entity->getMail()) {
    -      $form['mail']['#access'] = FALSE;
    +      if ($this->entity->getUserId()) {
    +        $form['mail']['#access'] = FALSE;
    +      }
    

    this overlaps with the access issue, but it is also not quite the same both there and here.

    Right now, the e-mail of an existing subscriber can't be changed, a new e-mail means a new subscription.

    I guess it does make sense to allow that, but I'd suggest to finalize the access issue first and then drop this chunk from the patch?

  2. +++ b/src/Form/SubscriptionsFormBase.php
    @@ -149,34 +158,60 @@ abstract class SubscriptionsFormBase extends ContentEntityForm {
    +    if (!$has_widget) {
    +      $subscribed = $this->entity->isSubscribed($this->getOnlyNewsletterId());
    +    }
    

    $subscribed doesn't get initialized if $has_widget.. I guess it's also never accessed but that's actually not easy to figure out from reading the code. What if we just inline two calls we need into the conditions below? The overhead should be minimal. Thinking about how we could simplify the amount of (nested) ifs, but I can't think of anything obvious.

    Overall, really nice that we fix a bug, add test coverage and extensive comments and still end up with 2 lines of code less than before.

  3. +++ b/src/Form/SubscriptionsFormBase.php
    @@ -149,34 +158,60 @@ abstract class SubscriptionsFormBase extends ContentEntityForm {
    +
    +    // @todo https://www.drupal.org/project/simplenews/issues/3031919
    +    // If an authenticated user has no email address then they can't subscribe.
    +    // Show a message instead of the form.
    +    // if ($this->entity->getUserId() && !$has_mail)
    

    I find it a bit strange to add commented out code with a todo.. doesn't seem like the right place as we are already deep in the form, building the actions. Might be better handled in the access control handler to never allow access to the form in the first place (we can't display a message then, though). My point is just leave this out completely.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new12.09 KB
new2.41 KB

1.

Right now, the e-mail of an existing subscriber can't be changed, a new e-mail means a new subscription.

I don't agree. Right now an admin can use SubscriberForm to change the email of an existing subscriber because right now SubscriberForm does not extend from SubscriptionsFormBase.

A) If the subscriber is also a user, this behaviour is highly undesirable because the User entity still stores the old email. This patch blocks that case.

B) If the subscriber is not a user, this behaviour is useful and is checked in the tests. The alternative of delete and create is tedious and loses important information about the subscription history. This chunk is needed in this patch to ensure that function continues to work.

Yes it overlaps with #3032167: Missing access check for subscriber mail field and both of them fix problem A in slightly different ways. The other issue has the correct long term fix, but is more risky, needs more tidy up and I'd rather leave it to give some time for people to spot problems in dev. This issue is safe and correct as it stands and is Critical due to data loss, so is blocking the next release.

2. Done

3. Done

Status: Needs review » Needs work

The last submitted patch, 26: simplenews.overwrite-data.3013721-26.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

adamps’s picture

Status: Needs work » Needs review

Another test glitch. I really need to fix these soon!

adamps’s picture

@Berdir is it OK if I commit this one now please?

  • abfc5b0 committed on 8.x-1.x
    Issue #3013721 by AdamPS, andrewbelcher, Berdir: SubscriberForm...
adamps’s picture

Status: Needs review » Fixed
Issue tags: -Plan to commit

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.