I started using workflow on a project and discovered workflow access not working as expected for me.
I am using workflow field as it is recommended on the modules page, even though I am only using workflow on 1 node content type.
I just need to know if workflow access is working when using workflow field or is it a problem with my site.

Comments

2pha’s picture

upon further investigation, it seems that when saving a node with a workflow field on it, the function workflow_node_current_state($entity, $entity_type = 'node', $field_name = '') is being called twice.
Once with the third argument correctly set as the name of the field, which results in the expected $sid, the second time it is called with the third argument not set which returns the default $sid

2pha’s picture

After some more tinkering I got it working.
This will only work for workflow fields on node entities.
I would usually supply a patch, but am in a hurry.
I changed the workflow_access_node_access_records($node) function to:


function workflow_access_node_access_records($node) {
  $grants = array();
  
  // Allow support for workflow field on nodes
  $fields = field_info_instances('node', $node->type);
  $field_name = '';
  foreach($fields as $fname => $f){
    $field = field_info_field($fname);
    if($field['type'] == 'workflow'){
      $field_name = $field['field_name'];
    }
  }

  if ($current_sid = workflow_node_current_state($node, 'node', $field_name)) {
    // Get 'author' of this entity.
    // - Some entities (e.g, taxonomy_term) do not have a uid.
    // Anonymous ($uid == 0) author is not allowed for role 'author' (== -1).
    $uid = isset($node->uid) ? $node->uid : 0;

    foreach (workflow_access_get_workflow_access_by_sid($current_sid) as $grant) {
      $grants[] = array(
        'realm' => ($uid > 0 && $grant->rid == WORKFLOW_ROLE_AUTHOR_RID) ? 'workflow_access_owner' : 'workflow_access',
        'gid' => ($uid > 0 && $grant->rid == WORKFLOW_ROLE_AUTHOR_RID) ? $node->uid : $grant->rid,
        'grant_view' => $grant->grant_view,
        'grant_update' => $grant->grant_update,
        'grant_delete' => $grant->grant_delete,
        'priority' => variable_get('workflow_access_priority', 0),
      );
    }
  }
  return $grants;
}
wouser’s picture

Another solution is to actually use Workflow Node; I was told that this is the correct module (Not Workflow Field). Apparently the verbiage on the module description is misleading, or so I was told. I spent over a week trying to get the Field module to work when Workflow Node works perfectly (with Workflow Access). Do yourself a favor, start over and use Workflow Node and make sure you are not using any other access modules as they will interfere.

Reference: https://drupal.org/comment/8473529#comment-8473529

(A previous frustrated Workflow Field user)
M

johnv’s picture

Title: workflow access and workflow field » workflow field & workflow access $ other node-centric workflow_modules
Version: 7.x-2.0-beta10 » 7.x-2.0-beta12
Status: Active » Fixed

Hi Wouser, I'm sorry you feel this way. Unfortunately, I was not able to update all submodules on time for you. Until shortly, workflow_vbo was not working, and workflow_access is now solved with 2pha's help. Like all of us, I too need the community to get over my time and knowledge limitations.

So, I took the code above from 2pha (thanks), put it in workflow_node_current_state(), checked some other instances and committed it in this commit.

Now, workflow_access works with workflow_field, too.
Also the third-party module workflow_fields (not the extra S) works, too!

Please download dev release to test this version.

johnv’s picture

Title: workflow field & workflow access $ other node-centric workflow_modules » workflow field & workflow access & other node-centric workflow_modules
wouser’s picture

My apologies John, my intent was not to attack you, Previous to now I was under the impression that Workflow Node was the default Module to use and here I was hearing otherwise, hence my frustration. I would have been able to understand not being able to jump on my problem as soon as it arises, especially when there is a lot of troubleshooting to be done but I am glad to hear that it is now working.

Fortunately for me I have been developing everything except Workflow, hoping something like this would arise and it couldn't have come at a better time.

Please don't misunderstand; what you guys have done here is exceptional; it is a core functionality of the website I'm developing that I plan to use for many years with the strong hope of being able to compensate you developers for all of the time and stress that goes into this. For now I am just another person with a dream..ready to watch everything come together; stress is a known factor to be figured in.

Accept my apology. I will download the dev version and start doing some testing!

Thank you.

johnv’s picture

Hi Wouser, it's OK, I can imagine your frustrations. Good luck!

Status: Fixed » Closed (fixed)

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

Ivan Simonov’s picture

Status: Closed (fixed) » Active

Hi John!
Looks like you did not update "workflow_access/workflow_access.module"
I still not able to use workflow_access for nodes with workflow_filds.

And add, please, clarification of the access setup under "/admin/config/workflow/workflow/access/1" page.
Present warning can not help to find right way of setup.

Warning: Use of the "Edit any," "Edit own," and even "View published content" permissions for the content type may override these access settings.

Thanks,
Ivan.

2pha’s picture

workflow_access has been updated. It is what this thread was originally about.

johnv’s picture

Hi Ivan, you should use 7.x-2.2. Are you?
- If you have problems with the 'weight'/'priority' of the access modules, got to the workflows configurations page. You'll fine 'Workflow access settings', where you can set the weight.
- Perhaps Workflow Access doesn't work for Workflow Field, see #2220065-10: workflow_access_node_access_records() call from node_save() problem with workflow_node
I'll take a look at the help texts.

  • Commit 25ce98a on 7.x-2.x by johnv:
    Issue #2209359 by johnv: Fixed submitting workflow access settings, does...
johnv’s picture

Ivan Simonov was right in #9: when saving the Workflow Access data, no access_rebuild was triggered for Workflow Field, only for Workflow Node. This is now fixed with the above commit.

  • Commit 37e94c0 on 7.x-2.x by johnv:
    Issue #2209359 by johnv: Fixed better UX for workflow_access pages, and...
johnv’s picture

Version: 7.x-2.0-beta12 » 7.x-2.2

@Ivan Simonov , the commit in #14 shuffles the pages and the help texts.
I cannot clarify the help texts, since they exist already for years, and I am no expert in access module. Please contribute om improvements once you have figured thins out, or create a sub-page under https://drupal.org/node/872876.

Close the issue if you ae happy now.

Ivan Simonov’s picture

John, thanks for fast reply.
Ufter last updates (dev version) I am still have troubles.

I have "story" type of nodes with attached workflow field. Field can be "draft" and others.
I need to block changes of node when status is not "draft"

So workflow access is:
- read allowed in any state for author
- edit allowed (checked) for author only in "draft" state
other roles unchecked

This settings do not work with any priority for workflow access (-10...0...+10)
Access rebuild does not help.

If role has right "story:edit own material" - it can edit own nodes in any states.
If role "story:edit own material" unchecked - it can not edit own nodes in any states.

What I doing wrong?

Ivan Simonov’s picture

May be it helps:

function workflow_access_node_access_records($node) {
  $grants = array();
  // Only relevant for content with Workflow.
  if (!isset($node->workflow_transitions)) {
    if (isset($node->workflow)) {
       // FALSE
    }
    else {
      return $grants; // <---- exit !! (100% when rebuilding permissions)
    }
  }

// so next code never used and priority can not help
//'priority' => variable_get('workflow_access_priority', 0),
johnv’s picture

Hi Ivan, the code you mentioned has changed the last 48 hours. The new dev version should be better

Ivan Simonov’s picture

drush dl workflow --dev -y
Comment #16 still true.

Ivan Simonov’s picture

I just download dev version from drupal.org
7.x-2.x-dev gz (115.16 KB) | zip (157.5 KB) 2014-Mar-31 Notes

For this version comment #17 true too.
Line 133: return $grants; // <---- exit !!

johnv’s picture

Yes, but the lines above have changed, and some code from the other recent node_access issues, regarding "$node->workflow_transitions", so none of the node with a workflow should go to that line.

Ivan Simonov’s picture

Ok, forgot my messages about code. I try to help.
Workflow access fail in my scenario. All settings ignored. Drupal standard permissions works instead.
New clean Drupal installation just show the fact: workflow access for fields not works.
Please read #16 and test commit. Thanks.

  • Commit 5af027a on 7.x-2.x by johnv:
    Issue #2209359 by johnv: Fixed workflow_access_node_access_records() in...
johnv’s picture

Indeed, grants were not calculated when rebuilding access.
Please try again with latest dev.

johnv’s picture

Title: workflow field & workflow access & other node-centric workflow_modules » workflow access & workflow field
Ivan Simonov’s picture

Yes! Much better!
Deny edit own content for some roles (drupal permissions).
Allow edit own content in "draft" state for this roles (WF Access).
Rebuild permissions. After this it works as expected.
Thank you.

johnv’s picture

Status: Active » Fixed

☺ please reopen or open a new issue if follow up problems arise.

Ivan Simonov’s picture

Status: Fixed » Active

After last update can not add new node.

Got white screen and fatal errors in log:
PHP Fatal error: Class 'WorkflowTransitionController' not found in .../includes/common.inc on line 7837, referer: .../node/add/article

Warnings in database:
Warning: class_implements() [function.class-implements]: Class WorkflowTransitionController does not exist and could not be loaded в функции entity_crud_get_info() (строка 721 в файле .../sites/all/modules/entity/entity.module).
Warning: in_array() expects parameter 2 to be array, boolean given в функции entity_crud_get_info() (строка 721 в файле .../sites/all/modules/entity/entity.module).

johnv’s picture

Did you refresh cache, run update.php?

johnv’s picture

It seems this happens when both workflow_field and workflow_access and workflow_actions are enabled.
See #1421518: PDOException: SQLSTATE[23000]: Duplicate entry in {node_access} table: when assigning a workflow to the node.
For the time being, I have the following 4 work-arounds:
- disable workflow_actions (everybody uses Rules)
- in workflow_actions.module, function workflow_access_workflow(), remove the call to node_access_acquire_grants();
- in workflow_actions.module, remove 'workflow_actions_entity_update()' from the code.
- in workflow_access.workflow.inc, remove the call to node_access_acquire_grants($entity)

Ivan Simonov’s picture

Status: Active » Fixed

refreshing cache, and update.php helps.
If I will see this error again, I`ll use your recommendations.

In my case workflow_field and workflow_access and workflow_actions was enabled.
Now workflow_actions is disabled.

  • Commit 231aafc on 7.x-2.x by johnv:
    Issue #2209359 by johnv: Fixed error message in workflow_access.
    

  • Commit 049e89e on 7.x-2.x by johnv:
    Issue #2209359 by johnv: Fixed error message in workflow_access.
    
johnv’s picture

The above 2 commits tackle the root cause: an extra hook_workflow('post transition') was triggered, which was not necessary.

  • Commit 069501b on 7.x-2.x by johnv:
    Issue #2209359 by johnv: Fixed WorkflowState is not an Entity, too.
    
johnv’s picture

Status: Fixed » Closed (fixed)