File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -47,9 +47,10 @@ def ready(self):
4747 """
4848 # pylint: disable=import-outside-toplevel
4949 from django .contrib .auth import get_user_model
50- from dauthz .core import enforcer
5150
52- enforcer .enable_auto_save (True )
51+ from openedx_authz .custom_enforcer import get_enforcer
52+
53+ enforcer = get_enforcer ()
5354
5455 # Add minimum policies for anonymous users
5556 anonymous_policies = [
@@ -68,8 +69,6 @@ def ready(self):
6869 if not enforcer .has_policy ("anonymous" , resource , action ):
6970 enforcer .add_policy ("anonymous" , resource , action )
7071
71- print ("\n \n Added minimum policies for anonymous users!" )
72-
7372 # Ensure admin users have access to all resources
7473 User = get_user_model ()
7574
@@ -78,4 +77,4 @@ def ready(self):
7877 for user in admin_users :
7978 enforcer .add_role_for_user (user .username , "admin" )
8079
81- print ("Added admin users to the authorization policy !\n \n " )
80+ print ("\n \n Added default policies !\n \n " )
Original file line number Diff line number Diff line change 1+ """
2+ Enforcer instance for openedx_authz.
3+ """
4+
5+ from dauthz .core import enforcer
6+ from redis_watcher import WatcherOptions , new_watcher
7+
8+
9+ def callback_function (event ):
10+ """
11+ Callback function for the enforcer.
12+ """
13+ print ("\n \n Update for remove filtered policy callback, event: {}" .format (event ))
14+
15+
16+ def get_enforcer ():
17+ """
18+ Get the enforcer instance.
19+ """
20+ enforcer .enable_auto_save (True )
21+ watcher_options = WatcherOptions ()
22+ watcher_options .host = "redis"
23+ watcher_options .port = 6379
24+ watcher_options .optional_update_callback = callback_function
25+ watcher = new_watcher (watcher_options )
26+ enforcer .set_watcher (watcher )
27+ return enforcer
Original file line number Diff line number Diff line change 22Views for openedx_authz DRF API.
33"""
44
5- from dauthz .core import enforcer
65from django .shortcuts import get_object_or_404
76from rest_framework import status , viewsets
87from rest_framework .response import Response
98
9+ from openedx_authz .custom_enforcer import get_enforcer
10+
1011from .models import Library
1112from .serializers import LibrarySerializer
1213
13- enforcer . enable_auto_save ( True )
14+ enforcer = get_enforcer ( )
1415
1516
1617class LibraryViewSet (viewsets .ViewSet ):
You can’t perform that action at this time.
0 commit comments