Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plone: intercept a workflow transition and change it to another one programmatically

We have a utility (collective.contentalerts) that checks if the content of an object (say an article) is adequate or not (does not contain bad words).

So far we have been using it together with plone.app.contentrules to send emails when that happens.

Now we want to go one step further:

Regular users can still create their articles but whenever they are trying to make them public, if the utility finds fishy content on it, it should put them in another state (i.e. make another workflow transition instead).

So the question is: is there a way to intercept a workflow transition, and given some logic (our utility) change the intended workflow transition to another one?

Extra nice would be that this transition to the moderation state should not be seen by regular users on the workflow transition drop down.

like image 912
gforcada Avatar asked Dec 07 '25 23:12

gforcada


1 Answers

I don't think it is necessary to intercept a transition: show users the transition "publish" which sends the object to the state "needs_review"

Use an automatic transition from state "needs_review" to "public" that is guarded with a view that checks if the article is ok (does not contain words from your blacklist, etc)

This way users see the "publish" transition (not "send to moderation").

An example on how to configure a guard expression can be found on the Poi add-on.

Think about something like this:

<guard-expression>here/@@myview</guard-expression>

Where myview can be a public view that perform all of the needed check and return True/False.

The trigger type of the transition has to be automatic instead of "initiated by user" (see screenshot)

screenshot of transition configuration

if you follow the [?] questionmark link next to the expression field you get more information on the available variables.

like image 134
fRiSi Avatar answered Dec 09 '25 13:12

fRiSi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!