Skip to content

Commit

Permalink
Enable user set nickname (#6193)
Browse files Browse the repository at this point in the history
* enableUserSetNickname

* ENABLE_USER_SET_NAME

* enableShowLoginIDWhenSearchUser
  • Loading branch information
SkywalkerSpace authored and stephensu66 committed Sep 27, 2024
1 parent a519985 commit 51ae1c1
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 27 deletions.
33 changes: 15 additions & 18 deletions frontend/src/components/user-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -54,24 +54,21 @@ class UserSelect extends React.Component {
let obj = {};
obj.value = item.name;
obj.email = item.email;
if (enableShowContactEmailWhenSearchUser) {
obj.label = (
<div className="d-flex">
<img src={item.avatar_url} className="avatar" width="24" alt="" />
<div className="ml-2">
<span className="user-option-name">{item.name}</span><br />
<span className="user-option-email">{item.contact_email}</span>
</div>
obj.label = (enableShowContactEmailWhenSearchUser || enableShowLoginIDWhenSearchUser) ? (
<div className="d-flex">
<img src={item.avatar_url} className="avatar" width="24" alt="" />
<div className="ml-2">
<span className="user-option-name">{item.name}</span><br />
{enableShowContactEmailWhenSearchUser && <span className="user-option-email">{item.contact_email}</span>}
{enableShowLoginIDWhenSearchUser && <span className="user-option-email">{item.login_id}</span>}
</div>
);
} else {
obj.label = (
<>
<img src={item.avatar_url} className="select-module select-module-icon avatar" alt=""/>
<span className='select-module select-module-name'>{item.name}</span>
</>
);
}
</div>
) : (
<React.Fragment>
<img src={item.avatar_url} className="select-module select-module-icon avatar" alt=""/>
<span className='select-module select-module-name'>{item.name}</span>
</React.Fragment>
);
this.options.push(obj);
}
callback(this.options);
Expand Down
12 changes: 7 additions & 5 deletions frontend/src/components/user-settings/user-basic-info-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { gettext } from '../../utils/constants';
const {
nameLabel,
enableUpdateUserInfo,
enableUserSetContactEmail
enableUserSetContactEmail,
enableUserSetName
} = window.app.pageOptions;

class UserBasicInfoForm extends React.Component {
Expand Down Expand Up @@ -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;
}
Expand All @@ -60,7 +62,7 @@ class UserBasicInfoForm extends React.Component {
<div className="form-group row">
<label className="col-sm-1 col-form-label" htmlFor="name">{nameLabel}</label>
<div className="col-sm-5">
<input className="form-control" id="name" type="text" name="nickname" value={name} disabled={!enableUpdateUserInfo} onChange={this.handleNameInputChange} />
<input className="form-control" id="name" type="text" name="nickname" value={name} disabled={!enableUpdateUserInfo || !enableUserSetName} onChange={this.handleNameInputChange} />
</div>
</div>

Expand Down
1 change: 1 addition & 0 deletions frontend/src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,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;
Expand Down
12 changes: 9 additions & 3 deletions seahub/api2/endpoints/search_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion seahub/api2/endpoints/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
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
Expand Down Expand Up @@ -91,6 +92,9 @@ def put(self, request):
# 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)')
Expand Down
1 change: 1 addition & 0 deletions seahub/profile/templates/profile/set_profile_react.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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 %}
Expand Down
1 change: 1 addition & 0 deletions seahub/profile/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,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,
Expand Down
2 changes: 2 additions & 0 deletions seahub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@
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
Expand Down Expand Up @@ -758,6 +759,7 @@ def genpassword():
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
Expand Down
1 change: 1 addition & 0 deletions seahub/templates/base_for_react.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,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 %}
Expand Down
1 change: 1 addition & 0 deletions seahub/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,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,
Expand Down

0 comments on commit 51ae1c1

Please sign in to comment.