"Authored on" date has 3 problems

John Morahan - September 14, 2007 - 20:54
Project:Drupal
Version:5.x-dev
Component:node system
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

Log in as a user with 'administer nodes' access. Go to node/add/page (or node/add/anything), fill in any required fields and hit Preview. Then look in the "Authoring information" fieldset. Under the "Authored on" field you see this:

"Format: . Leave blank to use the time of form submission."

instead of the usual e.g.:

"Format: 2007-09-14 21:44:50 +0100. Leave blank to use the time of form submission."

#1

Desbeers - September 15, 2007 - 13:09
Title:No "Authored on" format example when previewing a new node » "Authored on" date has 3 problems
Priority:minor» normal

There are currently 3 problems with the 'authority date':

PROBLEMS:

1 - If a use previews a new node and has no 'administer nodes' access; the 'preview date' will be somewhere in 1970. Very ugly.

2 - If a use previews a new node and has no 'administer nodes' access; part of the help-text disappears as mentioned in this issue.

3 - If a user previews a new node and does have 'administer nodes' access and alters the 'authority date field' the proper date is displayed in the preview and the help-text but the form-field will be empty again.

All these problems are only with -new- nodes!

REASON WHY:

1 - $node->date is empty on previewing for people without administer nodes rights.

2 - On first prepare of the node form default values will be filled in; but after preview $node->date will be empty if nothing is filled-in the 'authority-date-field'. The $node->date is used in the help-text.

3 - The form-field will not be filled-in with a default value because there is no $node->nid yet.

SOLUTION:

None yet :-( I managed to solve the problem but it was ugly and maybe unsafe. It seems that the author/date fields are only available for people with'administer nodes' rights and this is checked on several places. In 'node_form' and 'node_submit' for example.

I don't understand why because it looks double for me. If the access in the form is restricted than it should be safe to add missing values. I suppose... $node->name is set anyway (if not anonymous) so why not $node->date or $node->created as well? It gives notices as well when creating a node without admin rights.

I'll make a patch if I have some more knowledge about the safety concerns.

#2

Desbeers - September 15, 2007 - 13:11

Oeps,

Problem 2 - If a use previews a new node and DOES HAVE 'administer nodes' access; part of the help-text disappears as mentioned in this issue.

#3

JirkaRybka - September 15, 2007 - 18:04

The most serious problem for me is the 1970's date on non-admin's preview, because it's end-user facing (already reported as bug on my site...). I think it may be solved easily, if I only knew where in code, by simply just using current time in case of empty $node->date, just for the sake of preview-rendering. This would be a tiny 6.x bugfixing patch before we proceed to the rest?

#4

Desbeers - September 17, 2007 - 08:00
Status:active» patch (code needs review)

The ‘1970’ is the most visible problem, but nr. 2 is worse because the date field it non-functional for creating new nodes. Anyway, attached a patch to fix all 3 problems and some notices.

ALTERED FUNCTIONS:

node_submit():

  • Always set $node->created. If $node->date is filled in it will be used, else time(). This will keep the ‘preview-date’ up-to-date.

node_object _prepare():

  • Always set $node->created for ‘new’ nodes and $node->date for ‘edit’ nodes; in-depended of access rights. Fixed notices and part of the preview and help problems.
  • Removed access check, moved this to node_form()

node_form():

  • Access-check for ‘administer nodes’
  • Use of $node->created in help-text if $node->date is not set. Fixes nr. 2, ‘incomplete help-text’.
  • Always set default value for date-field if $node->date is set; not just for ‘old’ nodes. This fixes nr. 3, ‘always empty date field’ when creating a new node.

node_preview():

  • Removed $node->date to $node->creation conversion as this is done already in function node_submit(). Also fixed problem that $node->created is ‘reset’ because $node->date is set but empty. This fixes nr. 1, the ‘1970’ problem.
AttachmentSize
date-01.patch5.76 KB

#5

Gábor Hojtsy - September 17, 2007 - 08:15

This is indeed a nasty issue and the missing date problem also blocked one patch around that form field description (but I don't remember the issue ID).

#6

moshe weitzman - September 17, 2007 - 11:27
Priority:normal» critical

#7

JirkaRybka - September 17, 2007 - 17:17

I confirm all the described behaviors (problem 1. even occurs with uid=1 on fresh install).

Tested the patch from #4 on recent 6.x-dev: All mentioned bugs solved, no visible problems for me. I've tested all I can think of (previewing nodes with/-out changing date, removing date from form field, saving nodes straight away with no preview, editing old nodes...), all fine now.

Code reads OK to me, although I'm not much experienced in node module. Deserves RTBC if others agree.

#8

chx - September 18, 2007 - 06:55

While this patch works it's a step back. With #access we were able to make the node form consistent. If you are conditionally adding elements then it's inconsistent again :/

#9

Desbeers - September 18, 2007 - 07:20

I wasn't sure if the #access in the form was enough (it was already there all the time) and moved the user_access just to be on the safe side (see comment #1).

Now removed the conditional statement and access-rights is still working correct so user_access was unneeded and #access in the form is enough.

Attached a new patch.

AttachmentSize
date-02.patch3.26 KB

#10

chx - September 19, 2007 - 17:57
Status:patch (code needs review)» patch (reviewed & tested by the community)

#11

chx - September 19, 2007 - 18:07

So: I tested the issue and problems are fixed and yes the code is very nice.

#12

Gábor Hojtsy - September 19, 2007 - 18:11
Status:patch (reviewed & tested by the community)» fixed

Looks good to me too. Committed.

#13

hunmonk - September 30, 2007 - 13:02
Version:6.x-dev» 5.x-dev
Status:fixed» patch (to be ported)

looks like this is still a problem in Drupal 5. at the very least, users without 'administer nodes' perms are getting the 1970 date as the created time in their previews.

#14

hunmonk - September 30, 2007 - 13:08
Priority:critical» normal

don't think this is critical as it stands for D5.

#15

ryanj - November 16, 2007 - 17:28

Am I the only one who needs a patch for 5.x? I would make one if I knew how, but my PHP knowledge is very limited. Does anyone have any idea when this is going to be done?

#16

Freso - April 16, 2008 - 21:49
Status:patch (to be ported)» patch (code needs review)

Here's a port of the patch. I haven't tested it though, and there are a few differences between D5's and D6's node.module, so this should be tested properly.

AttachmentSize
node.date_.d5.patch2.76 KB

#17

brevity - March 31, 2008 - 11:56

Thanks, works fine!

#18

Damien Tournoud - March 31, 2008 - 13:22

On code review, the patch looks good (it is very similar to the one from D6). It should indeed work as expected.

#19

sethcohn - April 16, 2008 - 17:45
Status:patch (code needs review)» patch (reviewed & tested by the community)

Tested, works to solve the date preview issue(s).

+1

Please add this patch, so it makes it for D5.8, to fix the incorrect previews for those of us who are required to maintain a clean D5 core without non-critical patches.

#20

Damien Tournoud - April 21, 2008 - 10:50

Patch still applies cleanly.

#21

drumm - April 28, 2008 - 07:49
Status:patch (reviewed & tested by the community)» fixed

Committed to 5.x.

#22

Anonymous (not verified) - May 12, 2008 - 07:52
Status:fixed» closed

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

#23

battochir - May 25, 2008 - 11:31

Hello Freso,
Thanks for the patch! Very cool of you to make and share it. This date problem was ugly and a nasty pain in the arse. It's been around awhile and I'm surprised that in a supported version of drupal it's not been taken care of in core. Thanks again...you rock,

cheers,
wim

 
 

Drupal is a registered trademark of Dries Buytaert.