plone / Products.CMFPlone

The core of the Plone content management system
https://plone.org
GNU General Public License v2.0
254 stars 191 forks source link

Adapters providing IRedirectAfterLogin can not redirect to views #2835

Open fulv opened 5 years ago

fulv commented 5 years ago

BUG/PROBLEM REPORT (OR OTHER COMMON ISSUE)

What I did:

In the __call__ method of a IRedirectAfterLogin, returning an arbitrary URL is supposed to redirect to that URL. This works most of the time. But when returning a view name, with or without @@, it redirects to the home page.

See https://github.com/fulv/collective.onlogin/blob/python3/src/collective/onlogin/adapters.py#L119

What I expect to happen:

For example, returning http://localhost:8080/Plone/@@personal-information, I expect to be redirected to the user's "Personal Information" page.

What actually happened:

Instead, I get redirected to the home page.

What version of Plone/ Addons I am using:

5.2 https://github.com/fulv/collective.onlogin/tree/python3

pbauer commented 5 years ago

The redirect works properly when the login-form is not used in the modal, so I guess it is related to the modal-configration in portal_actions. Currently the login-modal uses:

<property name="modal" type="text">
 {"prependContent": ".portalMessage", 
  "title": "Log in", 
  "width": "26em", 
  "actionOptions": {"redirectOnResponse": true}}
</property>
holdenhao commented 3 years ago

In a modal with redirect, the Plone backend correctly processes the response and passes on the URL to the redirectToURL function. The function calls the response and fetches the body attribute data-view-url as the URL to redirect to.

reg = /<body.*data-view-url=[\"'](.*)[\"'].*/im.exec( response );

The data-view-url attribute is set in the view patterns which uses context_state from plone.app.layout.

"data-view-url": context_state.view_url(),

However, the view_url function for non-file and image items, only returns the object url and not the request URL so the value set does not include the view

view_url = self.object_url()

Changing the above line to:

view_url = self.request['URL']

fixes the modal redirect with a view but I am not yet sure if this negatively affects other cases