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
56 lines (44 loc) · 2.31 KB
/
common.py
File metadata and controls
56 lines (44 loc) · 2.31 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
50
51
52
53
54
55
56
"""
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
casbin_adapter_app = "openedx_authz.engine.apps.CasbinAdapterConfig"
if casbin_adapter_app not in settings.INSTALLED_APPS:
settings.INSTALLED_APPS.append(casbin_adapter_app)
# Casbin settings for model and policy synchronization
# Set default CASBIN_MODEL if not already set, this points to the model.conf file
# which defines the access control model for Casbin.
if not hasattr(settings, "CASBIN_MODEL"):
settings.CASBIN_MODEL = os.path.join(ROOT_DIRECTORY, "engine", "config", "model.conf")
# Set default CASBIN_AUTO_LOAD_POLICY_INTERVAL if not already set.
# This setting defines how often (in seconds) the Casbin enforcer should
# automatically reload policies from the database.
# By default, we set it to 0, which disables the auto-reload.
# As it shouldn't be needed thanks to cache invalidation.
if not hasattr(settings, "CASBIN_AUTO_LOAD_POLICY_INTERVAL"):
settings.CASBIN_AUTO_LOAD_POLICY_INTERVAL = 0
# Set default CASBIN_AUTO_SAVE_POLICY if not already set.
# This setting defines whether the Casbin enforcer should automatically
# save policy changes back to the database.
if not hasattr(settings, "CASBIN_AUTO_SAVE_POLICY"):
settings.CASBIN_AUTO_SAVE_POLICY = True
# Set default ContentLibrary model for swappable dependency
if not hasattr(settings, "OPENEDX_AUTHZ_CONTENT_LIBRARY_MODEL"):
settings.OPENEDX_AUTHZ_CONTENT_LIBRARY_MODEL = "content_libraries.ContentLibrary"
# Set default CourseOverview model for swappable dependency
if not hasattr(settings, "OPENEDX_AUTHZ_COURSE_OVERVIEW_MODEL"):
settings.OPENEDX_AUTHZ_COURSE_OVERVIEW_MODEL = "course_overviews.CourseOverview"
# Set default CASBIN_LOG_LEVEL if not already set.
# This setting defines the logging level for the Casbin enforcer.
if not hasattr(settings, "CASBIN_LOG_LEVEL"):
settings.CASBIN_LOG_LEVEL = "WARNING"