diff --git a/frontend/src/pages/sys-admin/statistic/statistic-traffic-orgs.js b/frontend/src/pages/sys-admin/statistic/statistic-traffic-orgs.js index 64204c8dbf..b155d96e82 100644 --- a/frontend/src/pages/sys-admin/statistic/statistic-traffic-orgs.js +++ b/frontend/src/pages/sys-admin/statistic/statistic-traffic-orgs.js @@ -74,7 +74,7 @@ class OrgsTraffic extends React.Component { getTrafficList = (month, page) => { const { perPage, sortBy, sortOrder } = this.state; - const orderBy = `${sortBy}_${sortOrder}`; + const orderBy = sortOrder == 'asc' ? sortBy : `${sortBy}_${sortOrder}`; this.setState({isLoading: true, errorMessage: ''}); seafileAPI.sysAdminListOrgTraffic(month, page, perPage, orderBy).then(res => { let orgTrafficList = res.data.org_monthly_traffic_list.slice(0); diff --git a/frontend/src/pages/sys-admin/statistic/statistic-traffic-users.js b/frontend/src/pages/sys-admin/statistic/statistic-traffic-users.js index 8988c64887..8e8ad2cb5c 100644 --- a/frontend/src/pages/sys-admin/statistic/statistic-traffic-users.js +++ b/frontend/src/pages/sys-admin/statistic/statistic-traffic-users.js @@ -74,7 +74,7 @@ class UsersTraffic extends React.Component { getTrafficList = (month, page) => { const { perPage, sortBy, sortOrder } = this.state; - const orderBy = `${sortBy}_${sortOrder}`; + const orderBy = sortOrder == 'asc' ? sortBy : `${sortBy}_${sortOrder}`; this.setState({ isLoading: true, errorMessage: '' diff --git a/thirdpart/shibboleth/middleware.py b/thirdpart/shibboleth/middleware.py index 747ef7a42e..eebda7bd77 100755 --- a/thirdpart/shibboleth/middleware.py +++ b/thirdpart/shibboleth/middleware.py @@ -1,6 +1,8 @@ from collections import OrderedDict from fnmatch import fnmatch import logging +import os +import sys from django.conf import settings from django.contrib.auth.middleware import RemoteUserMiddleware @@ -16,11 +18,21 @@ from seahub.base.accounts import User from seahub.base.sudo_mode import update_sudo_mode_ts from seahub.profile.models import Profile from seahub.utils.file_size import get_quota_from_string -from seahub.utils.user_permissions import get_user_role # Get an instance of a logger logger = logging.getLogger(__name__) +try: + conf_dir = os.environ['SEAFILE_CENTRAL_CONF_DIR'] + sys.path.append(conf_dir) + try: + from seahub_custom_functions import custom_shibboleth_get_user_role + CUSTOM_SHIBBOLETH_GET_USER_ROLE = True + except ImportError: + CUSTOM_SHIBBOLETH_GET_USER_ROLE = False +except KeyError: + CUSTOM_SHIBBOLETH_GET_USER_ROLE = False + class ShibbolethRemoteUserMiddleware(RemoteUserMiddleware): """ @@ -43,15 +55,15 @@ class ShibbolethRemoteUserMiddleware(RemoteUserMiddleware): " 'django.contrib.auth.middleware.AuthenticationMiddleware'" " before the RemoteUserMiddleware class.") - #To support logout. If this variable is True, do not - #authenticate user and return now. + # To support logout. If this variable is True, do not + # authenticate user and return now. if request.session.get(LOGOUT_SESSION_KEY) is True: return else: - #Delete the shib reauth session key if present. + # Delete the shib reauth session key if present. request.session.pop(LOGOUT_SESSION_KEY, None) - #Locate the remote user header. + # Locate the remote user header. # import pprint; pprint.pprint(request.META) try: username = request.META[SHIB_USER_HEADER] @@ -97,10 +109,20 @@ class ShibbolethRemoteUserMiddleware(RemoteUserMiddleware): user.save() # call make profile. self.make_profile(user, shib_meta) - user_role = self.update_user_role(user, shib_meta) + + if CUSTOM_SHIBBOLETH_GET_USER_ROLE: + user_role = custom_shibboleth_get_user_role(shib_meta) + if user_role: + ccnet_api.update_role_emailuser(user.email, user_role) + else: + user_role = self.update_user_role(user, shib_meta) + else: + user_role = self.update_user_role(user, shib_meta) + if user_role: self.update_user_quota(user, user_role) - #setup session. + + # setup session. self.setup_session(request) request.shib_login = True @@ -234,5 +256,6 @@ class ShibbolethRemoteUserMiddleware(RemoteUserMiddleware): error = True return shib_attrs, error + class ShibbolethValidationError(Exception): pass