diff --git a/seahub/role_permissions/settings.py b/seahub/role_permissions/settings.py index 52221c1286..d62753abba 100644 --- a/seahub/role_permissions/settings.py +++ b/seahub/role_permissions/settings.py @@ -3,12 +3,13 @@ from copy import deepcopy import logging from django.conf import settings -from seahub.constants import DEFAULT_USER, GUEST_USER, DEFAULT_ORG, \ +from seahub.constants import DEFAULT_USER, GUEST_USER, \ DEFAULT_ADMIN, SYSTEM_ADMIN, DAILY_ADMIN, AUDIT_ADMIN # Get an instance of a logger logger = logging.getLogger(__name__) + def merge_roles(default, custom): """Merge custom dict into the copy of default dict, and return the copy.""" copy = deepcopy(default) @@ -22,6 +23,7 @@ def merge_roles(default, custom): return copy + DEFAULT_ENABLED_ROLE_PERMISSIONS = { DEFAULT_USER: { 'can_add_repo': True, @@ -122,6 +124,7 @@ try: except AttributeError: pass # ignore error if ENABLED_ADMIN_ROLE_PERMISSIONS is not set in settings.py + def get_enabled_admin_role_permissions(): permissions = {} for role, perms in admin_role_permissions.items(): @@ -140,4 +143,5 @@ def get_enabled_admin_role_permissions(): return permissions + ENABLED_ADMIN_ROLE_PERMISSIONS = get_enabled_admin_role_permissions() diff --git a/seahub/role_permissions/utils.py b/seahub/role_permissions/utils.py index c65a6eda01..28da1942fc 100644 --- a/seahub/role_permissions/utils.py +++ b/seahub/role_permissions/utils.py @@ -3,15 +3,17 @@ import logging from .settings import ENABLED_ROLE_PERMISSIONS, ENABLED_ADMIN_ROLE_PERMISSIONS -from seahub.constants import DEFAULT_USER, DEFAULT_ADMIN +from seahub.constants import DEFAULT_USER, DEFAULT_ADMIN, AUDIT_ADMIN logger = logging.getLogger(__name__) + def get_available_roles(): """Get available roles defined in `ENABLED_ROLE_PERMISSIONS`. """ return list(ENABLED_ROLE_PERMISSIONS.keys()) + def get_enabled_role_permissions_by_role(role): """Get permissions dict(perm_name: bool) of a role. """ @@ -24,11 +26,13 @@ def get_enabled_role_permissions_by_role(role): return ENABLED_ROLE_PERMISSIONS[role] + def get_available_admin_roles(): """Get available admin roles defined in `ENABLED_ADMIN_ROLE_PERMISSIONS`. """ return list(ENABLED_ADMIN_ROLE_PERMISSIONS.keys()) + def get_enabled_admin_role_permissions_by_role(role): """Get permissions dict(perm_name: bool) of a admin role. """ @@ -37,7 +41,7 @@ def get_enabled_admin_role_permissions_by_role(role): role = DEFAULT_ADMIN if role not in list(ENABLED_ADMIN_ROLE_PERMISSIONS.keys()): - logger.warn('%s is not a valid admin role, use default admin role.' % role) - role = DEFAULT_ADMIN + logger.warn('%s is not a valid admin role, use audit admin role.' % role) + role = AUDIT_ADMIN return ENABLED_ADMIN_ROLE_PERMISSIONS[role]