forked from openedx/openedx-authz
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.py
More file actions
49 lines (41 loc) · 1.37 KB
/
common.py
File metadata and controls
49 lines (41 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
Common settings for openedx_authz plugin.
"""
import os
from openedx_authz import ROOT_DIRECTORY
def plugin_settings(settings):
"""
Configure plugin settings for Open edX.
This function is called by the Open edX plugin system to configure
the Django settings for this plugin.
Args:
settings: The Django settings object
"""
# Add external third-party apps to INSTALLED_APPS
external_apps = [
"casbin_adapter.apps.CasbinAdapterConfig", # Casbin Adapter
"dauthz.apps.DauthzConfig", # Django Authorization library
]
for app in external_apps:
if app not in settings.INSTALLED_APPS:
settings.INSTALLED_APPS.append(app)
# Add middleware for authorization
middleware_class = "dauthz.middlewares.request_middleware.RequestMiddleware"
settings.MIDDLEWARE = settings.MIDDLEWARE + [middleware_class]
# Add authorization configuration
settings.CASBIN_MODEL = os.path.join(ROOT_DIRECTORY, "model.conf")
settings.DAUTHZ = {
"DEFAULT": {
"MODEL": {
"CONFIG_TYPE": "file",
"CONFIG_FILE_PATH": settings.CASBIN_MODEL,
"CONFIG_TEXT": "",
},
"ADAPTER": {
"NAME": "casbin_adapter.adapter.Adapter",
},
"LOG": {
"ENABLED": True,
},
},
}