You are here

function revision_scheduler_operation_access in Revision scheduler 7

1 call to revision_scheduler_operation_access()
revision_scheduler_list_page in ./revision_scheduler.pages.inc
1 string reference to 'revision_scheduler_operation_access'
revision_scheduler_menu in ./revision_scheduler.module
Implements hook_menu().

File

./revision_scheduler.module, line 711

Code

function revision_scheduler_operation_access($op, $operation, $account = NULL) {
  if (!revision_scheduler_entity_type_has_revisions($operation->entity_type)) {
    return FALSE;
  }
  if (!user_access('schedule revisions', $account)) {
    return FALSE;
  }
  $entity = revision_scheduler_entity_revision_load($operation->entity_type, $operation->entity_id, $operation->revision_id);

  // If the revision does not exist, the operation cannot be run or updated.
  if ($op == 'run' || $op == 'update') {
    if (empty($entity)) {
      return FALSE;
    }
  }
  if ($op == 'update') {

    // The user must have the ability to select an operation in order to edit
    // it.
    // @todo Is this actually necessary?
    if (!revision_scheduler_entity_revision_operation_get_options($operation->entity_type, $entity, $account)) {
      return FALSE;
    }
  }
  if ($op == 'run' || $op == 'update' || $op == 'delete') {

    // In order to run, edit, or delete the operation, it must not have already
    // run or been queued for processing.
    return empty($operation->time_executed) && empty($operation->time_queued);
  }

  // Invalid $op.
  return FALSE;
}