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 admin logout bug #211

Merged
merged 3 commits into from
Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ Optional settings include:
* ``CAS_LOGIN_URL_NAME``: Name of the login url, defaults to ``'cas_ng_login'``.
This is only necessary if you use the middleware and want to use some other
name for the login url (e.g. ``'my_app:cas_login'``).
* ``CAS_LOGOUT_URL_NAME``: Name of the logout url, defaults to
``'cas_ng_logout'``. This is only necessary if you use the middleware and
want to use some other name for the logout url (e.g. ``'my_app:cas_logout'``).
* ``CAS_EXTRA_LOGIN_PARAMS``: Extra URL parameters to add to the login URL
when redirecting the user. Example::

Expand Down Expand Up @@ -194,8 +197,9 @@ and later:
]


If you use the middleware, the ``login`` url must be given the name ``cas_ng_login``
or it will create redirection issues, unless you set the ``CAS_LOGIN_URL_NAME`` setting.
If you use the middleware, the ``login`` and ``logout`` url must be given the
name ``cas_ng_login`` and ``cas_ng_logout`` or it will create redirection
issues, unless you set the ``CAS_LOGIN_URL_NAME`` and ``CAS_LOGOUT_URL_NAME`` setting.

You should also add an URL mapping for the ``CAS_PROXY_CALLBACK`` setting, if you have this
configured:
Expand Down
1 change: 1 addition & 0 deletions django_cas_ng/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'CAS_ADMIN_PREFIX': None,
'CAS_CREATE_USER': True,
'CAS_LOGIN_URL_NAME': 'cas_ng_login',
'CAS_LOGOUT_URL_NAME': 'cas_ng_logout',
'CAS_EXTRA_LOGIN_PARAMS': None,
'CAS_RENEW': False,
'CAS_IGNORE_REFERER': False,
Expand Down
3 changes: 3 additions & 0 deletions django_cas_ng/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def process_view(self, request, view_func, view_args, view_kwargs):
elif not view_func.__module__.startswith('django.contrib.admin.'):
return None

if view_func.__name__ == 'logout':
return HttpResponseRedirect(reverse(settings.CAS_LOGOUT_URL_NAME))

if request.user.is_authenticated:
if request.user.is_staff:
return None
Expand Down
4 changes: 2 additions & 2 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def mock_verify(ticket, service):
request, ticket='fake-ticket', service='fake-service',
)

assert "CAS_CREATE_USER_WITH_ID is True, but `'id'` is not part of attributes." in str(excinfo)
assert "CAS_CREATE_USER_WITH_ID is True, but `'id'` is not part of attributes." in str(excinfo.value)


@pytest.mark.django_db
Expand Down Expand Up @@ -420,7 +420,7 @@ def mock_verify(ticket, service):
request, ticket='fake-ticket', service='fake-service',
)

assert "CAS_CREATE_USER_WITH_ID is True, but no attributes were provided" in str(excinfo)
assert "CAS_CREATE_USER_WITH_ID is True, but no attributes were provided" in str(excinfo.value)


@pytest.mark.django_db
Expand Down