If a user without the 'Schedule content publication' permission edits a node that has been scheduled, when they save the node the scheduling data is lost.

Example:

User A creates an unpublished node, scheduled to publish in the future.
User B (without schedule permission) edits the unpublished node, makes a change & saves. The publish_on value has now been removed from the node.

Expected behaviour is that the scheduled date would remain, as User B doesn't have permission to change the scheduling settings.

This also happens with published content & the unpublish on setting.

I'm looking into this.

Comments

smaz created an issue. See original summary.

smaz’s picture

Title: Scheduled time lost when users without 'Schedule content publication' permission edit & save content » Scheduled time lost when users without 'Schedule content publication' permission edit & save scheduled content
smaz’s picture

I think this has two related issues:

#2651448: Publish and Unpublish fields are shown for users who do not have the permission
#2326533: The structure of values received in WidgetInterface::massageFormValues() varies depending on #access TRUE/FALSE

When a user doesn't have access to the scheduling fields, TimestampDatetimeNoDefaultWidget::massageFormValues() is given NULL for the values.

I'm guessing that because the user has access to $form['publish_on'] & $form['unpublish_on'] (it's only $form['scheduler_settings'] that has no access), the default value for the field isn't being applied because the user may have chosen to leave/set the fields blank.

Adding the following fixes the issue for me:

$form['publish_on']['#access'] = FALSE;
$form['unpublish_on']['#access'] = FALSE;

The default value (which is the current value) is then passed through to massageFormValues().

Patch attached, but I'm not sure if there are other cases where it won't work due to the comment at https://www.drupal.org/project/scheduler/issues/2651448#comment-10756814.

Cheers

jonathan1055’s picture

Hi Smaz,

Thanks for debuging this and providing a patch. I am surprised that this fault has not been noticed before. Maybe Core behaviour has changed? Or maybe we just never tried this scenario. Anyway we need test coverage for it but if you say it is fixed for you then that's a good start.

Jonathan

jonathan1055’s picture

StatusFileSize
new3.77 KB

I have added a test for this bug. This patch just has the extra test, not the code fix, so should fail.

Status: Needs review » Needs work
jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new4.98 KB

Good, the new test failed. Here's the test plus the code fix from @smaz

  • jonathan1055 committed ef6e445 on 8.x-1.x
    Issue #2989100 by jonathan1055, smaz: Scheduled time lost when users...
jonathan1055’s picture

Status: Needs review » Fixed

Fixed and committed.
Thanks Smaz for providing the initial patch.

smaz’s picture

Thank you!

Sorry, I never got around to adding a test - I've been struggling to get tests running locally for a while now & have been busy with the Umami/Out of the box initiative since.

jonathan1055’s picture

No apology needed! You found the bug and provided the patch to fix it.

Status: Fixed » Closed (fixed)

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