verbb / workflow

A Craft CMS plugin to create a workflow for publishing entries.
Other
140 stars 27 forks source link

Manually applying a draft or creating an entry from a draft leaves the submission in pending state #187

Open MoritzLost opened 1 year ago

MoritzLost commented 1 year ago

Describe the bug

When a publisher reviews a submission, they get the options to approve or reject the submission. Approving it will automatically apply the draft, or create an entry if it's an unpublished draft for a new entry. However, the publishers also have the regular buttons to apply the draft (or Create entry for unpublished drafts). Using those will leave the submission in Pending state. In this case, the interface for approving or rejecting the submission is still displayed:

Screenshot 2023-04-05 at 12 07 54

However, trying to approve or reject the submission will result in an error:

HTTP 400 – Bad Request – yii\web\BadRequestHttpException No draft was identified by the request.

This makes sense, since the draft the submission was referencing doesn't exist any more. But from a user's perspective, this is an error and is hard to understand.

I think the best solution would be to automatically set the submission to Approved in this case. If the draft is manually applied, this means the submission was accepted, so this makes sense from the publisher's perspective. This would also mean that the email notification to the editor is sent as well, which is currently impossible, since the submission can't be approved once the draft has been applied.

Steps to reproduce

  1. As an editor, create a draft for a new entry and submit it.
  2. As the publisher, go to the draft and click on Create entry.
  3. After the entry is created, click on Approve and publish, this will cause the error mentioned above.

Craft CMS version

4.4.5

Plugin version

2.0.4

Multi-site?

No

Additional context

No response

engram-design commented 1 year ago

Hmmm, it's a big assumption to make that if a draft that was linked to the submission that now doesn't exist means that it's been approved. But I suppose short of a draft being outright deleted, there's not too many other scenarios that could happen.

I'll give it some further thought.

MoritzLost commented 1 year ago

@engram-design Can't this be done with entry save hooks? When an entry is saved, the plugin can hook into the save process and check if the draft being saved is associated with any pending submission and approve that submission. This leaves out any guesswork. Or am I missing something?

engram-design commented 1 year ago

All of workflows actions are already on the save events, but only if they “opt in” to a workflow action. In theory what you propose should be okay, but I feel like I might be missing something (I can’t think of immediately) so I’ll test out a few scenarios.

MoritzLost commented 1 year ago

@engram-design Got it, thanks!