Problem/Motivation

Workflow is a very robust and powerful module. Part of what makes it so powerful is the Workflow Access module that comes built in with Workflow.

At present the benefit of Workflow field being compatible with ECK entities is limited because of the lack of access control support. It would be tremendously beneficial to have entity (particularly ECK entity) support for Workflow Access.

Proposed resolution

Add support for ECK entities in Workflow Access.

Remaining tasks

User interface changes

API changes

https://www.drupal.org/docs/8/api/entity-api/working-with-the-entity-api
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...

Comments

rbrownell’s picture

Title: Workflow Access for Entities » Workflow Access Support for Entities
rbrownell’s picture

Issue summary: View changes
Zekvyrin’s picture

This is an issue I would also like to have it solved.

Unfortunately I haven't found a generic way to affect all entities, because (other) entities are defined using hook_entity_info and they may set their custom 'access callback'.

Fortunately (kinda) for my case (entityform) there is a hook_entityorm_access_alter and by using that in a custom module I made my installation support workflow access for entityform.

The code I used is below:

/**
 * Implements hook_entityform_access_alter().
 */
function mymodule_entityform_access_alter(&$access, $op, $context) {

  if (!in_array($op, array('view', 'edit', 'delete'))) {
    return $access;
  }

  // if (!$access) {
    $entityform = $context['entityform'];
    $user = $context['account'];
    $workflow_fields = _workflow_info_fields($entityform, 'entityform');

    if (count($workflow_fields) > 0) {

      reset($workflow_fields);
      $workflow_field_name = array_pop($workflow_fields)['field_name'];
      $sid = workflow_node_current_state($entityform, 'entityform', $workflow_field_name);

      $user_roles = array_keys($user->roles);
      if ( !empty($entityform->is_new) || (isset($entityform->uid) && ($user->uid == $entityform->uid))) {
        $user_roles[] = WORKFLOW_FIELDS_AUTHOR_ROLE;
      }

      $grants = workflow_access_get_workflow_access_by_sid($sid);
      $access = FALSE;

      foreach ($grants as $grant) {
        if (in_array($grant->rid, $user_roles)) {
          if ($op == 'view' && $grant->grant_view) {
            $access = TRUE;
          }
          if ($op == 'edit' && $grant->grant_update) {
            $access = TRUE;
          }
          if ($op == 'delete' && $grant->grant_delete) {
            $access = TRUE;
          }
        }
      }
    }

  // }

}

Note that I wanted to override previous access set by entityform_access if there is a workflow field in it.
In case that you want to grant access to someone who previously didn't have, you may uncomment the if (!$access) clause (and possibly comment "$access = FALSE;" because it would be already set to FALSE so it won't be needed for this case).

Hope it saved some time to someone, until a better solution is found.

johnv’s picture

Version: 7.x-2.5 » 7.x-2.x-dev
johnv’s picture

Version: 7.x-2.x-dev » 8.x-1.x-dev

workflow_access is now ported to D8, so, this issue is moved to the highest version.

bradflewelling’s picture

Has there been any development for this issue over the last couple years? I'm using custom entities and workflow access doesn't seem to be enforcing the permissions that i set for them. Any suggestions?

johnv’s picture

Issue summary: View changes
johnv’s picture

Issue summary: View changes
mhmd’s picture

I have the same issue on latest drupal 8 release of that module

johnv’s picture

Title: Workflow Access Support for Entities » Workflow Access Support for non-Node Entities
johnv’s picture

Title: Workflow Access Support for non-Node Entities » Permissions: Workflow Access Support for non-Node Entities