Skip to content

Commit ad0b926

Browse files
committed
Improve the comment.
1 parent b6f3cc6 commit ad0b926

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

casbin_middleware/middleware.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,21 @@ class CasbinMiddleware:
2424

2525
def __init__(self, get_response):
2626
self.get_response = get_response
27+
# Initialize the Casbin enforcer, executed only on once.
2728
self.enforcer = casbin.Enforcer("casbin_middleware/authz_model.conf", "casbin_middleware/authz_policy.csv")
28-
# One-time configuration and initialization.
2929

3030
def __call__(self, request):
31-
# Code to be executed for each request before
32-
# the view (and later middleware) are called.
33-
31+
# Check the permission for each request.
3432
if not self.check_permission(request):
35-
raise PermissionDenied
33+
# Not authorized, return HTTP 403 error.
34+
self.require_permission()
3635

36+
# Permission passed, go to next module.
3737
response = self.get_response(request)
38-
39-
# Code to be executed for each request/response after
40-
# the view is called.
41-
4238
return response
4339

4440
def check_permission(self, request):
41+
# Customize it based on your authentication method.
4542
user = request.user.username
4643
if request.user.is_anonymous:
4744
user = 'anonymous'

0 commit comments

Comments
 (0)