From 74ef597f6e302ada98d6dc9f49c4fc997dc8ad89 Mon Sep 17 00:00:00 2001 From: skywalker Date: Mon, 17 Jun 2024 17:38:38 +0800 Subject: [PATCH] enableShowLoginIDWhenSearchUser --- frontend/src/components/user-select.js | 7 ++++--- frontend/src/utils/constants.js | 1 + seahub/api2/endpoints/search_user.py | 12 +++++++++--- seahub/settings.py | 4 +--- seahub/templates/base_for_react.html | 1 + seahub/views/__init__.py | 1 + 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/frontend/src/components/user-select.js b/frontend/src/components/user-select.js index eabe0a91c2d..979fba7366d 100644 --- a/frontend/src/components/user-select.js +++ b/frontend/src/components/user-select.js @@ -2,7 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import AsyncSelect from 'react-select/async'; import { seafileAPI } from '../utils/seafile-api'; -import { gettext, enableShowContactEmailWhenSearchUser } from '../utils/constants'; +import { gettext, enableShowContactEmailWhenSearchUser, enableShowLoginIDWhenSearchUser } from '../utils/constants'; import { Utils } from '../utils/utils'; import toaster from './toast'; import { UserSelectStyle } from './common/select'; @@ -49,12 +49,13 @@ class UserSelect extends React.Component { let obj = {}; obj.value = item.name; obj.email = item.email; - obj.label = enableShowContactEmailWhenSearchUser ? ( + obj.label = (enableShowContactEmailWhenSearchUser || enableShowLoginIDWhenSearchUser) ? (
{item.name}
- {item.contact_email} + {enableShowContactEmailWhenSearchUser && {item.contact_email}} + {enableShowLoginIDWhenSearchUser && {item.login_id}}
) : ( diff --git a/frontend/src/utils/constants.js b/frontend/src/utils/constants.js index 4fdae8c6529..e8c2139794e 100644 --- a/frontend/src/utils/constants.js +++ b/frontend/src/utils/constants.js @@ -77,6 +77,7 @@ export const canInvitePeople = window.app.pageOptions.canInvitePeople; export const canLockUnlockFile = window.app.pageOptions.canLockUnlockFile; export const customNavItems = window.app.pageOptions.customNavItems; export const enableShowContactEmailWhenSearchUser = window.app.pageOptions.enableShowContactEmailWhenSearchUser; +export const enableShowLoginIDWhenSearchUser = window.app.pageOptions.enableShowLoginIDWhenSearchUser; export const maxUploadFileSize = window.app.pageOptions.maxUploadFileSize; export const maxNumberOfFilesForFileupload = window.app.pageOptions.maxNumberOfFilesForFileupload; export const enableOCM = window.app.pageOptions.enableOCM; diff --git a/seahub/api2/endpoints/search_user.py b/seahub/api2/endpoints/search_user.py index d4afbbbbb83..89e4df31f3d 100644 --- a/seahub/api2/endpoints/search_user.py +++ b/seahub/api2/endpoints/search_user.py @@ -27,7 +27,7 @@ from seahub.avatar.templatetags.avatar_tags import api_avatar_url from seahub.settings import ENABLE_GLOBAL_ADDRESSBOOK, \ - ENABLE_SEARCH_FROM_LDAP_DIRECTLY + ENABLE_SEARCH_FROM_LDAP_DIRECTLY, ENABLE_SHOW_LOGIN_ID_WHEN_SEARCH_USER logger = logging.getLogger(__name__) @@ -175,15 +175,21 @@ def get(self, request, format=None): def format_searched_user_result(request, users, size): results = [] + if ENABLE_SHOW_LOGIN_ID_WHEN_SEARCH_USER: + profile_queryset = Profile.objects.filter(user__in=users) + profile_dict = { p.user: p.login_id for p in profile_queryset if p.login_id } for email in users: url, is_default, date_uploaded = api_avatar_url(email, size) - results.append({ + user_info = { "email": email, "avatar_url": url, "name": email2nickname(email), "contact_email": email2contact_email(email), - }) + } + if ENABLE_SHOW_LOGIN_ID_WHEN_SEARCH_USER: + user_info['login_id'] = profile_dict.get(email, '') + results.append(user_info) return results diff --git a/seahub/settings.py b/seahub/settings.py index b64cd779944..12192488e05 100644 --- a/seahub/settings.py +++ b/seahub/settings.py @@ -311,7 +311,7 @@ ENABLE_WATERMARK = False ENABLE_SHOW_CONTACT_EMAIL_WHEN_SEARCH_USER = False -ENABLE_SHOW_ID_IN_ORG_WHEN_SEARCH_USER = False +ENABLE_SHOW_LOGIN_ID_WHEN_SEARCH_USER = False # enable work weixin ENABLE_WORK_WEIXIN = False @@ -758,8 +758,6 @@ def genpassword(): ENABLE_USER_SET_CONTACT_EMAIL = False ENABLE_USER_SET_NAME = True -ENABLE_SHOW_ID_IN_ORG_WHEN_SEARCH_USER = False - # SSO to thirdparty website ENABLE_SSO_TO_THIRDPART_WEBSITE = False THIRDPART_WEBSITE_SECRET_KEY = '' diff --git a/seahub/templates/base_for_react.html b/seahub/templates/base_for_react.html index 952c0fc9065..db3b35c94a8 100644 --- a/seahub/templates/base_for_react.html +++ b/seahub/templates/base_for_react.html @@ -124,6 +124,7 @@ canInvitePeople: {% if enable_guest_invitation and user.permissions.can_invite_guest %} true {% else %} false {% endif %}, customNavItems: {% if custom_nav_items %} JSON.parse('{{ custom_nav_items | escapejs }}') {% else %} {{'[]'}} {% endif %}, enableShowContactEmailWhenSearchUser: {% if enable_show_contact_email_when_search_user %} true {% else %} false {% endif %}, + enableShowLoginIDWhenSearchUser: {% if enable_show_login_id_when_search_user %} true {% else %} false {% endif %}, {% if max_upload_file_size > 0 %} maxUploadFileSize: {{ max_upload_file_size }}, {% endif %} diff --git a/seahub/views/__init__.py b/seahub/views/__init__.py index 2f7d1c6c0f2..62dc767fda7 100644 --- a/seahub/views/__init__.py +++ b/seahub/views/__init__.py @@ -1081,6 +1081,7 @@ def react_fake_view(request, **kwargs): 'file_audit_enabled': FILE_AUDIT_ENABLED, 'custom_nav_items': json.dumps(CUSTOM_NAV_ITEMS), 'enable_show_contact_email_when_search_user': settings.ENABLE_SHOW_CONTACT_EMAIL_WHEN_SEARCH_USER, + 'enable_show_login_id_when_search_user': settings.ENABLE_SHOW_LOGIN_ID_WHEN_SEARCH_USER, 'additional_share_dialog_note': ADDITIONAL_SHARE_DIALOG_NOTE, 'additional_app_bottom_links': ADDITIONAL_APP_BOTTOM_LINKS, 'additional_about_dialog_links': ADDITIONAL_ABOUT_DIALOG_LINKS,