Content rule to redirect to page (Plone 6 Classic)

So, I managed to make a content rule for 'first login' ( Content rules for first login )

Question: Could it be possible to have a content rule that redirects the user to another page ( similar to what c.onlogin once did), or would this be impossible 'due to how content rules work/that several rules (theoretically) might get triggered for same event)

Yes it should be possible. Events run after the main response has been made but before that has been sent back. So you should be able to modify the response I believe.

1 Like

Update: I made the action, but there is something 'is preventing it from working'.

To test, I added a (default) 'User logged in' content rule.
For this, I used action 'Notify user'.

  • If I go to front page and log in, no message is shown to the user.
  • If I go to another page and log in from there, no message is shown to the user.
  • If I go to (for example) /news/edit (and log in when asked for username/password), the message is show (correctly).

UPDATE: This only happens on 'localhost', if I have a 'proper URL' it the message is shown.

1 Like

UPDATE: The above is NOT true. I think this depends on Plone version. For version the same error occurs. That is also true with the default 'logged in message': In other words: the message Info: Welcome! You are now logged in. is not shown anymore

UPDATE: This is not true too.
The events / rules fires if the user logs in from '/login'. If the user logs in via the pop up login form, it does not. The (current) workaround is to disable/remove 'modal = {}' in portal_actions

Could something like this work (I dont think it does)

@adapter(Interface, IRedirectAction, Interface)
class RedirectActionExecutor:
    """The executor for this action.
    This is registered as an adapter in configure.zcml

    def __init__(self, context, element, event):
        self.context = context
        self.element = element
        self.event = event

    def __call__(self):
        request = self.context.REQUEST
        rel_url = _(self.element.rel_url)
        #import pdb; pdb.set_trace()
        url = "{}/{}".format(api.portal.get().absolute_url(), rel_url)
        return True