Scenario: The unpublish date required setting is turned on. A node has gone through the publish and unpublish cycle and is now unpublished. On editing, the unpublish-on field is not required, which is correct. Enter just a publishing date and save. This node is now in an incorrect state because it will published and could remain that way, which contraditcts the 'unpublishing date required' setting. Also on subsequent editing before being published the unpublish-on 'required' marker is set, but the unpublish-on field is blank.
The fault is during editing of the unpublished node. The node can be edited and remain unpublished with both fields being left blank (this is ok). However if a publish-on date is entered then validation should enforce that an unpublish-on date is also entered.
The validation is simple to do, but I will also try to write a test to prove it is working as expected.
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | 2365707-18.validation_for_unpublish_on.7x.patch | 7.16 KB | jonathan1055 |
| #16 | 2365707_16.validation_for_unpublish_on.8x.patch | 11.64 KB | jonathan1055 |
Comments
Comment #1
jonathan1055 commentedComment #2
jonathan1055 commentedHere's the new test, but without the new validation. This patch should fail one test.
Comment #4
jonathan1055 commentedHere's the patch with the new validation and the test. Also removed two debug messages from the tests, which do not need to be there.
Comment #5
pfrenssenNice catch, this validation was indeed omitted. Thanks for adding a test too!
Comment #8
AlexKirienko commentedHi.
I still have an issue with unpublish_on validation.
In my case only unpublish_on is required. On node creation unpublish_on validation works fine. But when node has gone through the publish and unpublish cycle and become unpublished. Then user can publish node without filling unpublish_on date.
#4 patch works well if published_on is required, but not in my case.
Please check attached patch. Validation for unpublish_on date will work when user try to publish node.
I also have changed test case for this validation.
But changes in validation will break testScheduledNodeDelete(). Nodes with Published checked and without unpublish_on date can't pass validation and be removed.
Maybe we need to check on validation if clicked button not Delete. This situation need to be discussed.
Anyway unpublish_on date need to be validated if it set to be required.
Comment #10
jonathan1055 commentedHi AlexKirienko,
Yes, you are right. If the 'unpublishing required' option is turned on, then publishing the node directly should come under the same validation rules as setting a publish-on date. In both cases the user should enter an unpublish-on date. The code change you made in sheduler_node_validate() is not quite right because you have altered the existing validation. We need to retain the check for
!empty($node->publish_on)but also add the new check against$form_state['values']['status']The changes for removing validation when deleting a node have already been fixed in other issues, so that should be OK.
This extra validation needs to be changed at 8.x first. Here's a patch with an updated test to check for it - the class testValidationDuringEdit should now fail one assertion.
Comment #12
jonathan1055 commentedAs expected the new assertion fails. Here's a patch with the additional constraint and the new test. This should pass.
[By the way, it's really nice to be able to test patches at a selected version, and not have to change the issue version. I think this is a relatively new feature]
Comment #14
jonathan1055 commentedThat is a bit strange. The new test class passed, but the failure was in a completely different class which was not altered by the patch.
That shows the benefit in having a good test coverage. More investigation is required ...
Comment #15
jonathan1055 commentedOK, I can see what has happened. The new constraint has prevented a user from creating a published node if the user does not have scheduling permissions but the 'unpublishing required' option is enabled. That is good! If a user cannot set an unpublish date because they have not been granted scheduler permissions then it is correct that they should not be able to create a published node, as that node will not have an unpublish-on date.
I think the correct result in this case is that the user should only be allowed to create an unpublished node. Other user roles would then be able to schedule the node. This may require a change to the message text, as the user would see
"To publish this node you must also set an 'unpublish-on' date"but they would not have access to the unpublish-on field. But the principle of not letting them create/save a published node is correct.Comment #16
jonathan1055 commentedUpdated patch with the following changes:
SchedulerValidationTest, as well as checking the validation message text, I added additional assertions to check that the node is not savedSchedulerUnpublishOnConstraintValidatorSchedulerPermissionsTestso that it does not test with the 'required' options setComment #18
jonathan1055 commentedNow a patch for D7 with the new validation (as per 8.x), updated
testValidationDuringEdit()and a new test functiontestPermissions()which we did not have at 7.x before.Comment #20
jonathan1055 commented