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