diff --git a/frontend/src/components/user-select.js b/frontend/src/components/user-select.js index eabe0a91c2..979fba7366 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/components/user-settings/user-basic-info-form.js b/frontend/src/components/user-settings/user-basic-info-form.js index f9df710f0e..b3f623dda8 100644 --- a/frontend/src/components/user-settings/user-basic-info-form.js +++ b/frontend/src/components/user-settings/user-basic-info-form.js @@ -5,7 +5,8 @@ import { gettext } from '../../utils/constants'; const { nameLabel, enableUpdateUserInfo, - enableUserSetContactEmail + enableUserSetContactEmail, + enableUserSetName } = window.app.pageOptions; class UserBasicInfoForm extends React.Component { @@ -38,9 +39,10 @@ class UserBasicInfoForm extends React.Component { handleSubmit = (e) => { e.preventDefault(); - let data = { - name: this.state.name - }; + let data = {}; + if (enableUserSetName) { + data.name = this.state.name; + } if (enableUserSetContactEmail) { data.contact_email = this.state.contactEmail; } @@ -60,7 +62,7 @@ class UserBasicInfoForm extends React.Component {
- +
diff --git a/frontend/src/utils/constants.js b/frontend/src/utils/constants.js index d77fe24b1d..4ac5f7bb07 100644 --- a/frontend/src/utils/constants.js +++ b/frontend/src/utils/constants.js @@ -78,6 +78,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 d4afbbbbb8..89e4df31f3 100644 --- a/seahub/api2/endpoints/search_user.py +++ b/seahub/api2/endpoints/search_user.py @@ -27,7 +27,7 @@ from seahub.contacts.models import Contact 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 @@ class SearchUser(APIView): 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/api2/endpoints/user.py b/seahub/api2/endpoints/user.py index 24bedba1fe..203a758603 100644 --- a/seahub/api2/endpoints/user.py +++ b/seahub/api2/endpoints/user.py @@ -19,7 +19,8 @@ from seahub.api2.utils import api_error from seahub.base.templatetags.seahub_tags import email2nickname, \ email2contact_email from seahub.profile.models import Profile, DetailedProfile -from seahub.settings import ENABLE_UPDATE_USER_INFO, ENABLE_USER_SET_CONTACT_EMAIL, ENABLE_CONVERT_TO_TEAM_ACCOUNT +from seahub.settings import ENABLE_UPDATE_USER_INFO, ENABLE_USER_SET_CONTACT_EMAIL, ENABLE_CONVERT_TO_TEAM_ACCOUNT, \ + ENABLE_USER_SET_NAME import seaserv from seaserv import ccnet_api, seafile_api @@ -85,6 +86,9 @@ class User(APIView): # argument check for name name = request.data.get("name", None) if name: + if not ENABLE_USER_SET_NAME: + error_msg = _('Feature disabled.') + return api_error(status.HTTP_403_FORBIDDEN, error_msg) name = name.strip() if len(name) > 64: error_msg = _('Name is too long (maximum is 64 characters)') diff --git a/seahub/profile/templates/profile/set_profile_react.html b/seahub/profile/templates/profile/set_profile_react.html index be5467cc6b..d723d48320 100644 --- a/seahub/profile/templates/profile/set_profile_react.html +++ b/seahub/profile/templates/profile/set_profile_react.html @@ -19,6 +19,7 @@ window.app.pageOptions = { enableUpdateUserInfo: {% if ENABLE_UPDATE_USER_INFO %} true {% else %} false {% endif %}, nameLabel: "{% trans "Name:" context "true name" %}", enableUserSetContactEmail: {% if ENABLE_USER_SET_CONTACT_EMAIL %} true {% else %} false {% endif %}, + enableUserSetName: {% if ENABLE_USER_SET_NAME %} true {% else %} false {% endif %}, canUpdatePassword: {% if not is_ldap_user and ENABLE_CHANGE_PASSWORD %} true {% else %} false {% endif %}, {% if not is_ldap_user and ENABLE_CHANGE_PASSWORD %} diff --git a/seahub/profile/views.py b/seahub/profile/views.py index 9587242a99..d01e023b3d 100644 --- a/seahub/profile/views.py +++ b/seahub/profile/views.py @@ -164,6 +164,7 @@ def edit_profile(request): 'enable_dingtalk': enable_dingtalk, 'social_connected_dingtalk': social_connected_dingtalk, 'ENABLE_USER_SET_CONTACT_EMAIL': settings.ENABLE_USER_SET_CONTACT_EMAIL, + 'ENABLE_USER_SET_NAME': settings.ENABLE_USER_SET_NAME, 'user_unusable_password': request.user.enc_password == UNUSABLE_PASSWORD, 'enable_adfs': enable_adfs, 'saml_connected': saml_connected, diff --git a/seahub/settings.py b/seahub/settings.py index 70abb8f427..f6cab4dd86 100644 --- a/seahub/settings.py +++ b/seahub/settings.py @@ -313,6 +313,7 @@ ENABLE_OAUTH = False ENABLE_WATERMARK = False ENABLE_SHOW_CONTACT_EMAIL_WHEN_SEARCH_USER = False +ENABLE_SHOW_LOGIN_ID_WHEN_SEARCH_USER = False # enable work weixin ENABLE_WORK_WEIXIN = False @@ -760,6 +761,7 @@ WEBDAV_SECRET_MIN_LENGTH = 1 WEBDAV_SECRET_STRENGTH_LEVEL = 1 ENABLE_USER_SET_CONTACT_EMAIL = False +ENABLE_USER_SET_NAME = True # SSO to thirdparty website ENABLE_SSO_TO_THIRDPART_WEBSITE = False diff --git a/seahub/templates/base_for_react.html b/seahub/templates/base_for_react.html index b87bf56e8e..37d702162b 100644 --- a/seahub/templates/base_for_react.html +++ b/seahub/templates/base_for_react.html @@ -125,6 +125,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 2f7d1c6c0f..62dc767fda 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,