mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-09 02:42:47 +00:00
Merge branch '7.0'
This commit is contained in:
@@ -2,8 +2,8 @@ import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Utils } from '../../utils/utils';
|
||||
import editorUtilities from '../../utils/editor-utilties';
|
||||
import { siteRoot, gettext } from '../../utils/constants';
|
||||
import { seafileAPI } from '../../utils/seafile-api';
|
||||
import { siteRoot, gettext, appAvatarURL } from '../../utils/constants';
|
||||
|
||||
const propTypes = {
|
||||
isAdminPanel: PropTypes.bool,
|
||||
@@ -21,12 +21,8 @@ class Account extends Component {
|
||||
isStaff: false,
|
||||
isOrgStaff: false,
|
||||
usageRate: '',
|
||||
avatarURL: '',
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount(){
|
||||
this.getAccountInfo();
|
||||
this.isFirstMounted = true;
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
@@ -71,24 +67,23 @@ class Account extends Component {
|
||||
}
|
||||
|
||||
onClickAccount = () => {
|
||||
this.setState({
|
||||
showInfo: !this.state.showInfo,
|
||||
});
|
||||
}
|
||||
|
||||
getAccountInfo = () => {
|
||||
editorUtilities.getAccountInfo().then(resp => {
|
||||
this.setState({
|
||||
userName: resp.data.name,
|
||||
contactEmail: resp.data.email,
|
||||
usageRate: resp.data.space_usage,
|
||||
quotaUsage: Utils.bytesToSize(resp.data.usage),
|
||||
quotaTotal: Utils.bytesToSize(resp.data.total),
|
||||
isStaff: resp.data.is_staff,
|
||||
isOrgStaff: resp.data.is_org_staff === 1 ? true : false,
|
||||
avatarURL: resp.data.avatar_url
|
||||
if (this.isFirstMounted) {
|
||||
seafileAPI.getAccountInfo().then(resp => {
|
||||
this.setState({
|
||||
userName: resp.data.name,
|
||||
contactEmail: resp.data.email,
|
||||
usageRate: resp.data.space_usage,
|
||||
quotaUsage: Utils.bytesToSize(resp.data.usage),
|
||||
quotaTotal: Utils.bytesToSize(resp.data.total),
|
||||
isStaff: resp.data.is_staff,
|
||||
isOrgStaff: resp.data.is_org_staff === 1 ? true : false,
|
||||
showInfo: !this.state.showInfo,
|
||||
});
|
||||
});
|
||||
});
|
||||
this.isFirstMounted = false;
|
||||
} else {
|
||||
this.setState({showInfo: !this.state.showInfo});
|
||||
}
|
||||
}
|
||||
|
||||
renderMenu = () => {
|
||||
@@ -118,21 +113,14 @@ class Account extends Component {
|
||||
}
|
||||
|
||||
renderAvatar = () => {
|
||||
if (this.state.avatarURL) {
|
||||
return (
|
||||
<img src={this.state.avatarURL} width="36" height="36" className="avatar" alt={gettext('Avatar')} />
|
||||
);
|
||||
}
|
||||
return (
|
||||
<img src="" width="36" height="36" className="avatar" alt={gettext('Avatar')} />
|
||||
);
|
||||
return (<img src={appAvatarURL} width="36" height="36" className="avatar" alt={gettext('Avatar')} />);
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div id="account">
|
||||
<a id="my-info" onClick={this.onClickAccount} className="account-toggle no-deco d-none d-md-block" aria-label="View profile and more">
|
||||
<span><img src={this.state.avatarURL} width="36" height="36" className="avatar" alt={gettext('Avatar')} /></span>
|
||||
<span>{this.renderAvatar()}</span>
|
||||
<span className="fas fa-caret-down vam"></span>
|
||||
</a>
|
||||
<span className="account-toggle sf2-icon-more mobile-icon d-md-none" aria-label="View profile and more" onClick={this.onClickAccount}></span>
|
||||
|
@@ -16,6 +16,7 @@ export const lang = window.app.config.lang;
|
||||
export const fileServerRoot = window.app.config.fileServerRoot;
|
||||
export const seafileVersion = window.app.config.seafileVersion;
|
||||
export const serviceURL = window.app.config.serviceURL;
|
||||
export const appAvatarURL = window.app.config.avatarURL;
|
||||
|
||||
//pageOptions
|
||||
export const seafileCollabServer = window.app.pageOptions.seafileCollabServer;
|
||||
|
@@ -4,18 +4,16 @@ import urllib
|
||||
import hashlib
|
||||
|
||||
from django import template
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.html import format_html
|
||||
|
||||
from seahub.base.accounts import User
|
||||
from seahub.base.templatetags.seahub_tags import email2nickname
|
||||
from seahub.views import is_registered_user
|
||||
|
||||
from seahub.avatar.settings import (AVATAR_GRAVATAR_BACKUP, AVATAR_GRAVATAR_DEFAULT,
|
||||
AVATAR_DEFAULT_SIZE)
|
||||
from seahub.avatar.util import get_primary_avatar, get_default_avatar_url, \
|
||||
cache_result, get_default_avatar_non_registered_url
|
||||
from seahub.utils import get_service_url
|
||||
|
||||
# Get an instance of a logger
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -41,13 +39,18 @@ def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
|
||||
|
||||
@cache_result
|
||||
def api_avatar_url(user, size=AVATAR_DEFAULT_SIZE):
|
||||
service_url = get_service_url()
|
||||
service_url = service_url.rstrip('/')
|
||||
|
||||
avatar = get_primary_avatar(user, size=size)
|
||||
if avatar:
|
||||
url = avatar.avatar_url(size)
|
||||
date_uploaded = avatar.date_uploaded
|
||||
return url, False, date_uploaded
|
||||
# /media/avatars/6/9/5011f01afac2a506b9544c5ce21a0a/resized/32/109af9901c0fd38ab39d018f5cd4baf6.png
|
||||
return service_url + url, False, date_uploaded
|
||||
else:
|
||||
return get_default_avatar_url(), True, None
|
||||
# /media/avatars/default.png
|
||||
return service_url + get_default_avatar_url(), True, None
|
||||
|
||||
@cache_result
|
||||
@register.simple_tag
|
||||
|
@@ -24,6 +24,7 @@ from seahub.settings import SEAFILE_VERSION, SITE_TITLE, SITE_NAME, \
|
||||
|
||||
from seahub.constants import DEFAULT_ADMIN
|
||||
from seahub.utils import get_site_name, get_service_url
|
||||
from seahub.avatar.templatetags.avatar_tags import api_avatar_url
|
||||
|
||||
try:
|
||||
from seahub.settings import SEACLOUD_MODE
|
||||
@@ -74,6 +75,8 @@ def base(request):
|
||||
favicon_path = FAVICON_PATH
|
||||
|
||||
# filter ajax/api request out
|
||||
avatar_url = ''
|
||||
username = request.user.username
|
||||
if (not request.is_ajax()) and ("api2/" not in request.path) and \
|
||||
("api/v2.1/" not in request.path):
|
||||
|
||||
@@ -86,6 +89,7 @@ def base(request):
|
||||
custom_favicon_file = os.path.join(MEDIA_ROOT, CUSTOM_FAVICON_PATH)
|
||||
if os.path.exists(custom_favicon_file):
|
||||
favicon_path = CUSTOM_FAVICON_PATH
|
||||
avatar_url, is_default, date_uploaded = api_avatar_url(username, 72)
|
||||
|
||||
result = {
|
||||
'seafile_version': SEAFILE_VERSION,
|
||||
@@ -130,6 +134,7 @@ def base(request):
|
||||
'service_url': get_service_url().rstrip('/'),
|
||||
'enable_file_scan': ENABLE_FILE_SCAN,
|
||||
'enable_work_weixin_departments': ENABLE_WORK_WEIXIN_DEPARTMENTS,
|
||||
'avatar_url': request.build_absolute_uri(avatar_url) if avatar_url else '',
|
||||
}
|
||||
|
||||
if request.user.is_staff:
|
||||
|
@@ -43,6 +43,7 @@
|
||||
fileServerRoot: '{{ FILE_SERVER_ROOT }}',
|
||||
serviceURL: '{{ service_url }}',
|
||||
seafileVersion: '{{ seafile_version }}',
|
||||
avatarURL: '{{ avatar_url }}'
|
||||
},
|
||||
pageOptions: {
|
||||
csrfToken: "{{ csrf_token }}",
|
||||
|
Reference in New Issue
Block a user