Current state always allowed logic issue

Created on 10 June 2016, over 8 years ago
Updated 25 March 2024, 8 months ago

Hello again, this time I'm coming with a buglike issue.
In StateItem class there is the following class.

protected function getAllowedStates($value) {
    $workflow = $this->getWorkflow();
    if (!$workflow) {
      // The workflow is not known yet, the field is probably being created.
      return [];
    }
    $allowed_states = [
      // The current state is always allowed.
      $value => $workflow->getState($value),
    ];
    $transitions = $workflow->getAllowedTransitions($value, $this->getEntity());
    foreach ($transitions as $transition) {
      $state = $transition->getToState();
      $allowed_states[$state->getId()] = $state;
    }

    return $allowed_states;

I do not get why the current state is always allowed. This isn't normal in terms of business logic.
Even if this is not exactly a bug because it is declared as desired behaviour, I don't think that forcing it there is really working.

To give an example, we have a case where the content entity goes through a workflow. When the state is in a validated state, a simple user cannot edit and leave it in the validate state. The only thing it can do, is request a modification or report it. But a moderator of course can do that.
Of course it can be removed with the hook, but it is really weird that there is no other way especially given the fact that you cannot block it from the Guard class as well.

There are also many simple ways to solve this. The simplest is blocking access to the edit screen which for me it would make the best sense for a workflow.

Feature request
Status

RTBC

Version

1.0

Component

Code

Created by

🇬🇷Greece idimopoulos

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024