I have Workbench setup to use a Content Editor (writes and edits content) and a Content Moderator (approves and publishes). Work flows from Draft to Needs Review to Published. Nothing fancy. Everything works fine for all the content types except for the book pages. The Content Editor can go to a book page and click the tab that says "New Draft" and then make changes, but once they save the changes the page is basically in limbo. There is no way for the Content Editor to change the page status to "Needs Review." If you go to the "My Workbench" area the page shows up as being in draft mode, but you can't edit it further or change the state. All you can do is create another new draft that also ends up in limbo. I have enabled "create new revision" and "Enable moderation of revisions " in my Book Page settings and the Content Editor has permission to create and edit book pages.
I could really use some help.

Comments

ericras’s picture

Component: User interface » Code
Category: support » bug
Priority: Normal » Major
StatusFileSize
new68.68 KB
new86.81 KB
new71.67 KB

I can confirm this with a fresh 7.12 install with Workbench Moderation 7.x-1.1+9-dev (Apr10).

It affects any node assigned to a book. (Pages of the "Book" content type that are not assigned to a book are fine.)

Attached screenshots show two pages, each created by an admin and immediately published, then edited and saved by a content editor that can only save to the Draft state:

- First attachment (Basic Page 1) shows what we should get.
- Second attachment (Book Page 1) shows what happens when a page is part of a book. Revision 19 should not exist (it was published by Anonymous????) and revision 18 should be shaded red and awaiting moderation.

Revision 19 (vid=19) exists errantly in the node_revision DB table and it's log message is a dupe of 17's. The workbench_moderation_node_history table is ok, it has no entry for vid=19 hence Anonymous is listed as the user who made the moderation change.

ericras’s picture

Title: Extra revision generated for Book pages » Permissions issue with Book pages
Assigned: ericras » Unassigned
Status: Reviewed & tested by the community » Active

I've traced the meat of the problem to book_node_presave() which declares "Always save a revision for non-administrators" and sets $node->revision=1. Related: #261319: Book page update always creates revision?

I'm thinking about undoing that in workbench_moderation_node_presave() which appears to be called after book_node_presave() but I'm not knowledgeable about call order of hook functions i.e. will workbench_moderation_node_presave always be called later than book_node_presave? is it alphabetically??

Edit: I see it looks like module_invoke_all call order is based on weight in the system table. Book:0, WBM: 5.

ericras’s picture

Title: Permissions issue with Book pages » Extra revision generated for Book pages
Assigned: Unassigned » ericras
Status: Active » Needs review
StatusFileSize
new513 bytes

Here's a patch that solves the problem for me.

ComboPrime’s picture

Just want to confirm that the patch solved this issue for me as well. Thank you!

rosk0’s picture

solved this issue for me as well.

lodey’s picture

This worked for me too - using latest dev version

tamasd’s picture

I can confirm this working with the 7.x-1.2 version.

jhedstrom’s picture

Status: Needs review » Reviewed & tested by the community

I can also confirm that #3 works for book pages.

ericras’s picture

Title: Permissions issue with Book pages » Extra revision generated for Book pages
Status: Active » Reviewed & tested by the community
stevector’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Workbench Sprint

Tagging for this week's Workbench sprint. This patch should include a test.

kbentham’s picture

Status: Needs work » Postponed (maintainer needs more info)

I am having trouble reproducing this error. Can you please give more detailed steps as to how to reproduce the error, as well as the version numbers of Workbench Moderation and Drupal core that you are using?

hazah’s picture

Hey there, same issue, patch works!

WBM: 7.x-1.3
Core: 7.19

  1. Enable book & WB Moderation
  2. Create a book page and assign it to a book (this is critical, does not happen when not assigned to any book)
  3. publish
  4. Attempt to create new draft & save

Revision history shows your draft *second*, with another, newer, draft by anonymous which is set to be the current published version.

There is no tab to edit the draft you have attempted to create in step 4. Only option is to create another new draft (which ends up repeating the problem again).

There is no moderation options to place the draft as published.

Edit/Revert/Delete are gone, only user can only view.

Let me know if any step is not clear.

ericras’s picture

Status: Needs review » Postponed (maintainer needs more info)
StatusFileSize
new676.46 KB

To reproduce:
Latest core 7.x dev from git (e01afb83bc7bffc84ddda0d3b3da7b505aedeed7)
Latest workbench (16a8fff3c80a10102711d5c92625e67879e333dd)
and workbench_moderation (d19698957c76d236b0967151b689a23b4f766ad0)
from git 7.x-1.x

Attached is the permissions for my 'content editor' role - the limited access user that needs their edits moderated.

1. Enable Book and Workbench Moderation and enable moderation of revisions on the Book Page content type.
2. Create 'Content Editor' role and set permissions according to screenshot
3. Administrator creates a new Book Page and on the node/add/book form:
- Book outline: select 'create a new book'
- Publishing options: Moderation State: Published
- Save
4. User with only 'Content Editor' role creates a new draft of that page and saves.

The result is the 'wrong' screen shot in comment #1 where the Content Editor user is able to publish and moderation actions are attributed to Anonymous. The result should be the 'correct' screen shot.

jhedstrom’s picture

Status: Postponed (maintainer needs more info) » Needs review
waako’s picture

This is still a requirement for Workbench Moderation to work with Book.

Issue still exists with latest version of dev release (2013-Jun-13)

Patch worked a treat thank you ericras

ewlyn’s picture

Version: 7.x-1.x-dev » 7.x-1.3
StatusFileSize
new128.93 KB
new152.85 KB

I am running Workbench Moderator 7x-1.3 and running into almost the same issue ericras did.

Workbench is working fine everywhere else on the site, but if I access a book child page, there is only the option to view. Revert and delete have vanished. Also, if a user creates a new draft, it creates duplicates which have no moderation actions and, when one tries to view them, one is shown the current published version. One can publish the draft to get it to show up on the site, but saving it as a draft or in need of review puts it in limbo.

Curiously, if I go to moderate the content page for the book, everything works as it should.

I tried applying the patch, but can't seem to get it to work with 7x.1-3. (It either causes zero change to the site or throws errors at me... but this might partly be my lack of experience with coding/my guessing where it might go in the 7x-1.3 code.)

Attached are two screen shots. One showing the content page view with everything working and one showing the child page view with all the missing options and the strange phantom ghost pages.

Any help would be much appreciated. Thank you!

Please let me know if there is any other information I can provide.

hass’s picture

Version: 7.x-1.3 » 7.x-1.x-dev
ewlyn’s picture

One additional bit of wonkiness I have noticed while trying to find a way to resolve this.

When a user with complete access edits a book page, that page begins behaving correctly. The revert and delete options reappear and the extra limbo pages vanish and become pages which either require moderation or can be reverted depending on if they have previously been published. All users with access to that page can now view the moderation queue as it should be.

However, once a user with a more limited access role creates a new draft, that page of the book immediately begins acting oddly again with their draft going back into limbo and the revert and delete options vanish again. All users with access to that page now view the wonky moderation queue again.

I've upgraded to the dev version 7.x-1.3+6-dev. Still having these problems.

jojonaloha’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Needs work

I've also experienced this issue and noticed it only when the user didn't have the 'Administer content' permission. As ericras said, it is caused by an incompatibility with book.module.

If we look at the relevant code in book_node_presave(), we can see that this is caused when the book module is enabled and the user does not have the 'administer nodes' ('Administer content' in the UI) permission.

  // Always save a revision for non-administrators.
  if (!empty($node->book['bid']) && !user_access('administer nodes')) {
    $node->revision = 1;
    // The database schema requires a log message for every revision.
    if (!isset($node->log)) {
      $node->log = '';
    }
  }

The patch in #3 works for me using 7.x-1.3.

@ewlyn it sounds like you are having trouble applying the patch, for me it applied clean to 7.x-1.3 though. Try https://drupal.org/node/60108

$ cd sites/all/modules/contrib/workbench_moderation/
$ patch -p1 < ~/patches/workbench_moderation-prevent_extra_revision_book_node-1505060.patch 
patching file workbench_moderation.module
Hunk #1 succeeded at 642 (offset -19 lines).

Moving to 'needs work' since it was already RTBC and according to #10 needs tests still.

mparker17’s picture

star-szr’s picture

Status: Needs work » Needs review
StatusFileSize
new2.54 KB
new3.04 KB

Here's a test case, this should pass/fail.

The last submitted patch, 21: workbench_moderation-1505060-21-testonly.patch, failed testing.

star-szr’s picture

Fridays. Fail/pass I mean, and it did! :)

Reviews please.

ben.bunk’s picture

The patch in #21 applied cleanly and fixed the issue for us against 7.x-1.3 but there was a 403 access denied error in the test case trying to access this page: /node/1/moderation/1/change-state/needs_review?token=dSg9nrtNLWZpA62DBRYfIH0HDj5IVW9mHjFBDe66RYk

netsliver’s picture

The patch not work for me, I removed the lines in book.module, work very well.

joegraduate’s picture

StatusFileSize
new3.23 KB

The patches in #3 and #21 no longer apply correctly to the latest released version (7.x-1.4) or the latest dev.

The attached patch is a re-roll of #21 with some minor modifications. It applies cleanly to both the latest dev and released version and fixes the issue for me.

star-szr’s picture

@joegraduate it would be great if you could expand on (or provide an interdiff for) the minor modifications :) thanks!

joegraduate’s picture

@Cottser, sorry about that. The only real difference was that I moved a comment to a different line so that the code block that this patch adds to workbench_moderation_node_presave() fits in better with another code block that has been added to that function since the original patches were created. I didn't change any of the test code added in #21.

star-szr’s picture

No worries, sounds reasonable :) thanks!

agileadam’s picture

The patch in #26 worked for me. Thank you.

cspiker’s picture

#26 tests out for us as well.

Ryan S’s picture

#26 works great! Thank you! Our entire site uses book pages, so this is a very welcome fix.

jojonaloha’s picture

Status: Needs review » Reviewed & tested by the community

Moving to RTBC.

dman’s picture

Way too many hours I lost before I found myself with enough evidence to locate the exact issue was the one reported here!

Issue still present in Workbench Moderation 7.x-1.4
* A 'moderator' user with the correct permissions for workflow stages but not 'administer content'
* tries to save a new draft of already published content
* draft gets saved (according to the watchdog) but is immediately overwritten by the published 'original' with a new revision ID making the reversion the new 'current' version.
* Traced to the $node->revision flag, and subsequently to the func identified back in 2013 by @jojonaloha

 book_node_presave($node) {
  // Always save a revision for non-administrators.

Patch still applies well. Patch resolves problem!

RTBC, and mad frustrating to trace and replicate when it's all about an unrelated permission and an unrelated module that triggers this.

richgerdes’s picture

Verified that this patch still applies to the current head of the 7.x-1.x branch and solves the issue. Patch can be merged.

wildfeed’s picture

Version: 7.x-1.x-dev » 7.x-3.0
Assigned: Unassigned » wildfeed
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new3.79 KB

Here is a patch that can be applied to version 7.x-3.0. workbench_moderation_node_presave is now handled by workbench_moderation_entity_presave. The patch in #27 has been modified so the code is runs when hook_entity_presave runs and modifies $entity instead of $node. Worked for me!

wildfeed’s picture

StatusFileSize
new3.79 KB

Let's try this again as - Same patch but naming it #37

The last submitted patch, 36: extra_revision-1505060-35.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 37: extra_revision-1505060-37.patch, failed testing. View results

richgerdes’s picture

Version: 7.x-3.0 » 7.x-3.x-dev

@wildfeed,

Please ensure that your patch works against the dev version of 3.x, it if you built the patch around 3.0, there have been changes since 3.0 was released.

wildfeed’s picture

StatusFileSize
new3.22 KB

Recreated patch

richgerdes’s picture

Status: Needs work » Needs review

Running tests.