Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 1154 Add LOGOUT_REDIRECT_URL setting #1749

Merged
merged 10 commits into from
Dec 9, 2021
4 changes: 3 additions & 1 deletion docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ Use config.py to configure the following parameters. By default it will use SQLL
| | the existing languages with the countries | |
| | name and flag | |
+----------------------------------------+--------------------------------------------+-----------+
| LOGOUT_REDIRECT_URL | The location to redirect to after logout | No |
+-----------------------------------+--------------------------------------------+-----------+
blag marked this conversation as resolved.
Show resolved Hide resolved
| FAB_API_SHOW_STACKTRACE | Sends api stack trace on uncaught | No |
| | exceptions. (Boolean) | |
+----------------------------------------+--------------------------------------------+-----------+
Expand Down Expand Up @@ -331,4 +333,4 @@ causes users 1 and 2 to be registered with role ``Admin`` and rest with the role
JMESPath expression allow more groups to be evaluated:
``email == 'user1@domain.com' && 'Admin' || (email == 'user2@domain.com' && 'Op' || 'Viewer')``

For more example, see `specification <https://jmespath.org/specification.html>`_.
For more example, see `specification <https://jmespath.org/specification.html>`_.
6 changes: 5 additions & 1 deletion flask_appbuilder/security/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,11 @@ def login(self):
@expose("/logout/")
def logout(self):
logout_user()
return redirect(self.appbuilder.get_url_for_index)
return redirect(
self.appbuilder.app.config.get(
"LOGOUT_REDIRECT_URL", self.appbuilder.get_url_for_index
)
)


class AuthDBView(AuthView):
Expand Down
22 changes: 22 additions & 0 deletions flask_appbuilder/tests/test_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,25 @@ def test_menu_api_public(self):
role = self.appbuilder.sm.find_role("Public")
role.permissions = []
self.appbuilder.get_session.commit()

def test_redirect_after_logout(self):
"""
REST Api: Test redirect after logout
"""
limited_user = "user1"
limited_password = "user1"

client = self.app.test_client()

self.login(client, limited_user, limited_password)
rv = self.browser_logout(client)

# make sure that browser is redirected to /
self.assertEqual(rv.headers["Location"].split("/")[-1], "")

self.login(client, limited_user, limited_password)
self.app.config["LOGOUT_REDIRECT_URL"] = "/logged_out"
rv = self.browser_logout(client)

# make sure that browser is redirected to LOGOUT_REDIRECT_URL
self.assertEqual(rv.headers["Location"].split("/")[-1], "logged_out")