Skip to content

Commit

Permalink
onlyoffice show user avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
imwhatiam committed May 30, 2024
1 parent 0a7dc93 commit e9f28c3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion seahub/onlyoffice/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from seaserv import seafile_api

from seahub.base.templatetags.seahub_tags import email2nickname
from seahub.avatar.templatetags.avatar_tags import api_avatar_url
from seahub.utils import get_file_type_and_ext, gen_file_get_url, \
get_site_scheme_and_netloc

Expand Down Expand Up @@ -141,6 +142,7 @@ def get_onlyoffice_dict(request, username, repo_id, file_path, file_id='',
onlyoffice_editor_callback_url = reverse('onlyoffice_editor_callback')
callback_url = urllib.parse.urljoin(base_url, onlyoffice_editor_callback_url)

avatar_url, _, _ = api_avatar_url(username, 72)
return_dict = {
'repo_id': repo_id,
'path': file_path,
Expand All @@ -154,6 +156,7 @@ def get_onlyoffice_dict(request, username, repo_id, file_path, file_id='',
'can_edit': can_edit,
'can_download': can_download,
'username': username,
'avatar_url': avatar_url,
'onlyoffice_force_save': ONLYOFFICE_FORCE_SAVE,
'enable_watermark': ENABLE_WATERMARK,
'request_from_onlyoffice_desktop_editor': ONLYOFFICE_DESKTOP_EDITOR_HTTP_USER_AGENT in request.headers.get('user-agent', ''),
Expand Down Expand Up @@ -188,7 +191,8 @@ def get_onlyoffice_dict(request, username, repo_id, file_path, file_id='',
if request.user.is_authenticated:
user_dict = {
"id": username,
"name": email2nickname(username)
"name": email2nickname(username),
"avatar_url": avatar_url,
}
config['editorConfig']['user'] = user_dict
else:
Expand Down
5 changes: 3 additions & 2 deletions seahub/templates/view_file_onlyoffice.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load seahub_tags i18n static %}
{% load seahub_tags avatar_tags i18n static %}

<!DOCTYPE html>
<html>
Expand Down Expand Up @@ -112,7 +112,8 @@
{% if request.user.is_authenticated %}
"user": {
"id": "{{ username|escapejs }}",
"name": "{{ username|email2nickname|escapejs }}"
"name": "{{ username|email2nickname|escapejs }}",
"image": "{{ avatar_url }}",
}
{% endif %}
}
Expand Down

0 comments on commit e9f28c3

Please sign in to comment.