Skip to content

Commit

Permalink
Rename required_authentication view flag to authentication_required
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrisan committed Jul 24, 2019
1 parent 9e12dab commit b06004a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions colibris/authentication/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@

def require_authentication(required=True):
def decorator(handler):
handler.required_authentication = required
handler.authentication_required = required

return handler

return decorator


def get_required_authentication(handler):
return getattr(handler, 'required_authentication', None)
def get_authentication_required(handler):
return getattr(handler, 'authentication_required', None)


def authenticate(request):
Expand Down
18 changes: 9 additions & 9 deletions colibris/middleware/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ async def handle_auth(request, handler):
original_handler = request.match_info.handler

# First look for auth info in the view handler itself (class or function)
required_authentication = authentication.get_required_authentication(original_handler)
authentication_required = authentication.get_authentication_required(original_handler)
required_permissions = authorization.get_required_permissions(original_handler)

# Then, if we've got a class-based view, look for required permissions in method function
if inspect.isclass(original_handler) and issubclass(original_handler, views.View):
method_func = getattr(original_handler, method.lower(), None)
if method_func:
method_func_required_authentication = authentication.get_required_authentication(method_func)
method_func_authentication_required = authentication.get_authentication_required(method_func)
method_func_required_permissions = authorization.get_required_permissions(method_func)

if method_func_required_permissions and required_permissions:
Expand All @@ -39,17 +39,17 @@ async def handle_auth(request, handler):
else:
required_permissions = required_permissions or method_func_required_permissions

if method_func_required_authentication is not None:
required_authentication = method_func_required_authentication
if method_func_authentication_required is not None:
authentication_required = method_func_authentication_required

# A value of None for required_authentication indicates decision based on permissions
if required_authentication is None:
required_authentication = bool(required_permissions)
# A value of None for authentication_required indicates decision based on permissions
if authentication_required is None:
authentication_required = bool(required_permissions)

if not required_authentication and required_permissions:
if not authentication_required and required_permissions:
raise authorization.AuthorizationException('view requires permissions but does not require authentication')

if required_authentication:
if authentication_required:
try:
account = authentication.authenticate(request)

Expand Down
2 changes: 1 addition & 1 deletion colibris/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ def __init__(cls, name, bases, attrs):


class View(web.View, metaclass=ViewMeta):
required_authentication = None
authentication_required = None
required_permissions = None

0 comments on commit b06004a

Please sign in to comment.