Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
keithbauer committed Jan 10, 2018
2 parents df618e6 + dc03368 commit dcd2c50
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 1.4.0
- Compatibility with Django 2.0 (https://github.com/kstateome/django-cas/pull/72)

### 1.3.0
- Compatibility with Django 1.10 Middleware (https://github.com/kstateome/django-cas/pull/69)
- Add support for protocol-rooted URL as "next_page" argument for _logout_url constructor (https://github.com/kstateome/django-cas/pull/67)
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ bryankaplan
cordmata
bltravis
JordanReiter
balsdorf
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

CAS client for Django. This library requires Django 1.5 or above, and Python 2.6, 2.7, 3.4

Current version: 1.3.0
Current version: 1.4.0

This is [K-State's fork](https://github.com/kstateome/django-cas) of [the original](https://bitbucket.org/cpcc/django-cas/overview) and includes [several additional features](https://github.com/kstateome/django-cas/#additional-features) as well as features merged from

Expand All @@ -14,7 +14,7 @@ This is [K-State's fork](https://github.com/kstateome/django-cas) of [the or

This project is registered on PyPi as django-cas-client. To install::

pip install django-cas-client==1.3.0
pip install django-cas-client==1.4.0


### Add to URLs
Expand Down
17 changes: 15 additions & 2 deletions cas/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ def user_passes_test(test_func, login_url=None, redirect_field_name=REDIRECT_FIE
def decorator(view_func):
@wraps(view_func)
def wrapper(request, *args, **kwargs):

try:
# use callable for pre-django 2.0
is_authenticated = request.user.is_authenticated()
except TypeError:
is_authenticated = request.user.is_authenticated

if test_func(request.user):
return view_func(request, *args, **kwargs)
elif request.user.is_authenticated():
elif is_authenticated:
return HttpResponseForbidden('<h1>Permission denied</h1>')
else:
path = '%s?%s=%s' % (login_url, redirect_field_name,
Expand Down Expand Up @@ -65,7 +72,13 @@ def wrapped_f(*args):
from cas.views import login
request = args[0]

if request.user.is_authenticated():
try:
# use callable for pre-django 2.0
is_authenticated = request.user.is_authenticated()
except TypeError:
is_authenticated = request.user.is_authenticated

if is_authenticated:
# Is Authed, fine
pass
else:
Expand Down
13 changes: 11 additions & 2 deletions cas/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth import logout as do_logout
from django.contrib.auth.views import login, logout
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, HttpResponseForbidden
from django.core.exceptions import ImproperlyConfigured
try:
from django.urls import reverse
except ImportError:
from django.core.urlresolvers import reverse
try:
from django.utils.deprecation import MiddlewareMixin
except ImportError:
Expand Down Expand Up @@ -60,7 +63,13 @@ def process_view(self, request, view_func, view_args, view_kwargs):
elif not view_func.__module__.startswith('django.contrib.admin.'):
return None

if request.user.is_authenticated():
try:
# use callable for pre-django 2.0
is_authenticated = request.user.is_authenticated()
except TypeError:
is_authenticated = request.user.is_authenticated

if is_authenticated:
if request.user.is_staff:
return None
else:
Expand Down
14 changes: 12 additions & 2 deletions cas/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
from django.conf import settings
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib import auth
from django.core.urlresolvers import reverse

try:
from django.urls import reverse
except ImportError:
from django.core.urlresolvers import reverse

from cas.models import PgtIOU

Expand Down Expand Up @@ -166,7 +170,13 @@ def login(request, next_page=None, required=False, gateway=False):
if not next_page:
next_page = _redirect_url(request)

if request.user.is_authenticated():
try:
# use callable for pre-django 2.0
is_authenticated = request.user.is_authenticated()
except TypeError:
is_authenticated = request.user.is_authenticated

if is_authenticated:
return HttpResponseRedirect(next_page)

ticket = request.GET.get('ticket')
Expand Down
4 changes: 4 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

1.4.0
------------------
- Compatibility with Django 2.0 (https://github.com/kstateome/django-cas/pull/72)

1.3.0
------------------

Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
# built documents.
#
# The short X.Y version.
version = '1.3.0'
version = '1.4.0'
# The full version, including alpha/beta/rc tags.
release = '1.3.0'
release = '1.4.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup, find_packages

version = '1.3.0'
version = '1.4.0'


def read(fname):
Expand Down

0 comments on commit dcd2c50

Please sign in to comment.