Skip to content

Commit

Permalink
working with auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Bishwas-py committed Feb 27, 2024
1 parent 168c962 commit 95fe10e
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 110 deletions.
4 changes: 2 additions & 2 deletions djapy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .core import djapy_method, djapy_login_required, openapi, djapify
from .core import djapy_method, djapy_auth, openapi, djapify
from .core.mid import UHandleErrorMiddleware
from .schema import Schema

__all__ = ['djapify', 'openapi', 'djapy_login_required', 'djapy_method', 'Schema', 'UHandleErrorMiddleware']
__all__ = ['djapify', 'openapi', 'djapy_auth', 'djapy_method', 'Schema', 'UHandleErrorMiddleware']
4 changes: 2 additions & 2 deletions djapy/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__all__ = ['djapify', 'djapy_login_required', 'djapy_method', 'openapi']
__all__ = ['djapify', 'djapy_auth', 'djapy_method', 'openapi']

from .auth_dec import djapy_login_required, djapy_method
from .auth import djapy_auth, djapy_method
from .dec import djapify
from .openapi import openapi
Binary file modified djapy/core/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file removed djapy/core/__pycache__/auth_dec.cpython-311.pyc
Binary file not shown.
Binary file modified djapy/core/__pycache__/dec.cpython-311.pyc
Binary file not shown.
49 changes: 0 additions & 49 deletions djapy/core/auth.py

This file was deleted.

57 changes: 0 additions & 57 deletions djapy/core/auth_dec.py

This file was deleted.

8 changes: 8 additions & 0 deletions djapy/core/dec.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,19 @@ def djapify(view_func: Callable = None,
auth_mechanism = in_app_auth_mechanism or BaseAuthMechanism()

def decorator(view_func):
permissions = getattr(view_func, 'permissions', None)
print("permissions", permissions)

@wraps(view_func)
def _wrapped_view(request: HttpRequest, *args, **view_kwargs):
message_json_returned = auth_mechanism.authenticate(request, *args, **view_kwargs)

if message_json_returned:
return JsonResponse(message_json_returned, status=401)
if permissions:
message_json_returned = auth_mechanism.authorize(request, permissions, *args, **view_kwargs)
if message_json_returned:
return JsonResponse(message_json_returned, status=403)

djapy_allowed_method = getattr(_wrapped_view, 'djapy_allowed_method', None)
djapy_message_response = getattr(view_func, 'djapy_message_response', None)
Expand Down
Binary file modified djapy/core/openapi/__pycache__/openapi_path.cpython-311.pyc
Binary file not shown.

0 comments on commit 95fe10e

Please sign in to comment.