mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-19 07:27:56 +00:00
update admin role
if admin role is not a valid role, user audit admin role as default
This commit is contained in:
parent
cf208eea5b
commit
dd18807dae
@ -3,12 +3,13 @@ from copy import deepcopy
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.conf import settings
|
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
|
DEFAULT_ADMIN, SYSTEM_ADMIN, DAILY_ADMIN, AUDIT_ADMIN
|
||||||
|
|
||||||
# Get an instance of a logger
|
# Get an instance of a logger
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def merge_roles(default, custom):
|
def merge_roles(default, custom):
|
||||||
"""Merge custom dict into the copy of default dict, and return the copy."""
|
"""Merge custom dict into the copy of default dict, and return the copy."""
|
||||||
copy = deepcopy(default)
|
copy = deepcopy(default)
|
||||||
@ -22,6 +23,7 @@ def merge_roles(default, custom):
|
|||||||
|
|
||||||
return copy
|
return copy
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_ENABLED_ROLE_PERMISSIONS = {
|
DEFAULT_ENABLED_ROLE_PERMISSIONS = {
|
||||||
DEFAULT_USER: {
|
DEFAULT_USER: {
|
||||||
'can_add_repo': True,
|
'can_add_repo': True,
|
||||||
@ -122,6 +124,7 @@ try:
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass # ignore error if ENABLED_ADMIN_ROLE_PERMISSIONS is not set in settings.py
|
pass # ignore error if ENABLED_ADMIN_ROLE_PERMISSIONS is not set in settings.py
|
||||||
|
|
||||||
|
|
||||||
def get_enabled_admin_role_permissions():
|
def get_enabled_admin_role_permissions():
|
||||||
permissions = {}
|
permissions = {}
|
||||||
for role, perms in admin_role_permissions.items():
|
for role, perms in admin_role_permissions.items():
|
||||||
@ -140,4 +143,5 @@ def get_enabled_admin_role_permissions():
|
|||||||
|
|
||||||
return permissions
|
return permissions
|
||||||
|
|
||||||
|
|
||||||
ENABLED_ADMIN_ROLE_PERMISSIONS = get_enabled_admin_role_permissions()
|
ENABLED_ADMIN_ROLE_PERMISSIONS = get_enabled_admin_role_permissions()
|
||||||
|
@ -3,15 +3,17 @@ import logging
|
|||||||
|
|
||||||
from .settings import ENABLED_ROLE_PERMISSIONS, ENABLED_ADMIN_ROLE_PERMISSIONS
|
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__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def get_available_roles():
|
def get_available_roles():
|
||||||
"""Get available roles defined in `ENABLED_ROLE_PERMISSIONS`.
|
"""Get available roles defined in `ENABLED_ROLE_PERMISSIONS`.
|
||||||
"""
|
"""
|
||||||
return list(ENABLED_ROLE_PERMISSIONS.keys())
|
return list(ENABLED_ROLE_PERMISSIONS.keys())
|
||||||
|
|
||||||
|
|
||||||
def get_enabled_role_permissions_by_role(role):
|
def get_enabled_role_permissions_by_role(role):
|
||||||
"""Get permissions dict(perm_name: bool) of a 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]
|
return ENABLED_ROLE_PERMISSIONS[role]
|
||||||
|
|
||||||
|
|
||||||
def get_available_admin_roles():
|
def get_available_admin_roles():
|
||||||
"""Get available admin roles defined in `ENABLED_ADMIN_ROLE_PERMISSIONS`.
|
"""Get available admin roles defined in `ENABLED_ADMIN_ROLE_PERMISSIONS`.
|
||||||
"""
|
"""
|
||||||
return list(ENABLED_ADMIN_ROLE_PERMISSIONS.keys())
|
return list(ENABLED_ADMIN_ROLE_PERMISSIONS.keys())
|
||||||
|
|
||||||
|
|
||||||
def get_enabled_admin_role_permissions_by_role(role):
|
def get_enabled_admin_role_permissions_by_role(role):
|
||||||
"""Get permissions dict(perm_name: bool) of a admin 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
|
role = DEFAULT_ADMIN
|
||||||
|
|
||||||
if role not in list(ENABLED_ADMIN_ROLE_PERMISSIONS.keys()):
|
if role not in list(ENABLED_ADMIN_ROLE_PERMISSIONS.keys()):
|
||||||
logger.warn('%s is not a valid admin role, use default admin role.' % role)
|
logger.warn('%s is not a valid admin role, use audit admin role.' % role)
|
||||||
role = DEFAULT_ADMIN
|
role = AUDIT_ADMIN
|
||||||
|
|
||||||
return ENABLED_ADMIN_ROLE_PERMISSIONS[role]
|
return ENABLED_ADMIN_ROLE_PERMISSIONS[role]
|
||||||
|
Loading…
Reference in New Issue
Block a user