diff --git a/frontend/src/components/toolbar/dir-operation-toolbar.js b/frontend/src/components/toolbar/dir-operation-toolbar.js index 2adfc603d0..35497c50db 100644 --- a/frontend/src/components/toolbar/dir-operation-toolbar.js +++ b/frontend/src/components/toolbar/dir-operation-toolbar.js @@ -203,11 +203,19 @@ class DirOperationToolbar extends React.Component { render() { let { path, repoName, userPerm } = this.props; + const { isCustomPermission, customPermission } = Utils.getUserPermission(userPerm); + const isShowDropdownMenu = (userPerm === 'rw' || userPerm === 'admin' || userPerm === 'cloud-edit' || isCustomPermission); + if (!isShowDropdownMenu) { + return ( +
+ {this.props.children} +
+ ); + } let itemType = path === '/' ? 'library' : 'dir'; let itemName = path == '/' ? repoName : Utils.getFolderName(path); - const { isCustomPermission, customPermission } = Utils.getUserPermission(userPerm); let canUpload = true; let canCreate = true; if (isCustomPermission) { @@ -293,7 +301,8 @@ class DirOperationToolbar extends React.Component { data-toggle="dropdown" > {this.props.children} - + + {opList.map((item, index) => { @@ -351,7 +360,8 @@ class DirOperationToolbar extends React.Component { className="path-item" > {this.props.children} - + + {canUpload && ( @@ -370,7 +380,7 @@ class DirOperationToolbar extends React.Component { return ( - {(userPerm === 'rw' || userPerm === 'admin' || userPerm === 'cloud-edit' || isCustomPermission) && ( + {isShowDropdownMenu && (
{content}
diff --git a/frontend/src/css/lib-content-view.css b/frontend/src/css/lib-content-view.css index ed44774ddf..cd90447b79 100644 --- a/frontend/src/css/lib-content-view.css +++ b/frontend/src/css/lib-content-view.css @@ -280,6 +280,10 @@ align-items: center; } +.dir-view-path .dir-operation.dir-operation-no-dropdown { + margin-left: 6px; +} + .dir-view-path .dir-operation .path-item { display: inline-flex; align-items: center; @@ -316,9 +320,14 @@ display: inline-block; } +.dir-view-path .sf3-font-new, .dir-view-path .path-item-dropdown-toggle { color: #666; +} + +.dir-view-path .path-item-dropdown-toggle { margin-top: 2px; + margin-left: 2px; } .dir-view-path .path-item-drop { diff --git a/frontend/src/utils/constants.js b/frontend/src/utils/constants.js index 91eb515d60..c5f5b00831 100644 --- a/frontend/src/utils/constants.js +++ b/frontend/src/utils/constants.js @@ -109,7 +109,10 @@ export const enableTC = window.app.pageOptions.enableTC; export const enableVideoThumbnail = window.app.pageOptions.enableVideoThumbnail; export const enablePDFThumbnail = window.app.pageOptions.enablePDFThumbnail; +export const enableOfficeWebApp = window.app.pageOptions.enableOfficeWebApp || false; +export const officeWebAppEditFileExtension = window.app.pageOptions.officeWebAppEditFileExtension || []; export const enableOnlyoffice = window.app.pageOptions.enableOnlyoffice || false; +export const onlyofficeEditFileExtension = window.app.pageOptions.onlyofficeEditFileExtension || []; export const onlyofficeConverterExtensions = window.app.pageOptions.onlyofficeConverterExtensions || []; export const enableFileTags = window.app.pageOptions.enableFileTags || false; diff --git a/frontend/src/utils/utils.js b/frontend/src/utils/utils.js index 7bb75360ed..021c9233e3 100644 --- a/frontend/src/utils/utils.js +++ b/frontend/src/utils/utils.js @@ -1,5 +1,7 @@ import { mediaUrl, gettext, serviceURL, siteRoot, isPro, fileAuditEnabled, canGenerateShareLink, canGenerateUploadLink, shareLinkPasswordMinLength, username, folderPermEnabled, onlyofficeConverterExtensions, enableSeadoc, enableFileTags, enableRepoSnapshotLabel, - enableResetEncryptedRepoPassword, isEmailConfigured, isSystemStaff } from './constants'; + enableResetEncryptedRepoPassword, isEmailConfigured, isSystemStaff, + enableOnlyoffice, onlyofficeEditFileExtension, + enableOfficeWebApp, officeWebAppEditFileExtension } from './constants'; import TextTranslation from './text-translation'; import React from 'react'; import toaster from '../components/toast'; @@ -209,7 +211,14 @@ export const Utils = { return false; } const file_ext = filename.substr(filename.lastIndexOf('.') + 1).toLowerCase(); - return ['docx', 'pptx', 'xlsx'].includes(file_ext); + + if (enableOnlyoffice) { + return onlyofficeEditFileExtension.includes(file_ext); + } else if (enableOfficeWebApp) { + return officeWebAppEditFileExtension.includes(file_ext); + } else { + return false; + } }, // check if a file is a video diff --git a/seahub/base/context_processors.py b/seahub/base/context_processors.py index 721db067f0..8bfbaa00a4 100644 --- a/seahub/base/context_processors.py +++ b/seahub/base/context_processors.py @@ -29,7 +29,10 @@ from seahub.settings import SEAFILE_VERSION, SITE_DESCRIPTION, \ from seahub.organizations.models import OrgAdminSettings from seahub.organizations.settings import ORG_ENABLE_ADMIN_CUSTOM_LOGO -from seahub.onlyoffice.settings import ENABLE_ONLYOFFICE, ONLYOFFICE_CONVERTER_EXTENSIONS +from seahub.onlyoffice.settings import ENABLE_ONLYOFFICE, \ + ONLYOFFICE_CONVERTER_EXTENSIONS, ONLYOFFICE_EDIT_FILE_EXTENSION +from seahub.wopi.settings import ENABLE_OFFICE_WEB_APP, \ + OFFICE_WEB_APP_EDIT_FILE_EXTENSION 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 @@ -152,8 +155,11 @@ def base(request): 'FILE_SERVER_ROOT': file_server_root, 'USE_GO_FILESERVER': seaserv.USE_GO_FILESERVER if hasattr(seaserv, 'USE_GO_FILESERVER') else False, 'LOGIN_URL': dj_settings.LOGIN_URL, - 'enableOnlyoffice': ENABLE_ONLYOFFICE, - 'onlyofficeConverterExtensions': ONLYOFFICE_CONVERTER_EXTENSIONS, + 'enable_onlyoffice': ENABLE_ONLYOFFICE, + 'onlyoffice_edit_file_extension': list(ONLYOFFICE_EDIT_FILE_EXTENSION), + 'enable_office_web_app': ENABLE_OFFICE_WEB_APP, + 'office_web_app_edit_file_extension': list(OFFICE_WEB_APP_EDIT_FILE_EXTENSION), + 'onlyoffice_converter_extensions': ONLYOFFICE_CONVERTER_EXTENSIONS, 'thumbnail_size_for_original': THUMBNAIL_SIZE_FOR_ORIGINAL, 'thumbnail_size_for_grid': THUMBNAIL_SIZE_FOR_GRID, 'thumbnail_default_size': THUMBNAIL_DEFAULT_SIZE, diff --git a/seahub/onlyoffice/converter.py b/seahub/onlyoffice/converter.py index e4c77f9351..7a6e6dd20b 100644 --- a/seahub/onlyoffice/converter.py +++ b/seahub/onlyoffice/converter.py @@ -1,5 +1,6 @@ import logging import requests +import time from seahub.onlyoffice.converter_utils import get_file_name, get_file_ext from seahub.onlyoffice.settings import ONLYOFFICE_CONVERTER_URL, \ @@ -21,6 +22,7 @@ def get_converter_uri(doc_uri, from_ext, to_ext, doc_key, is_async, file_passwor 'filetype': from_ext.replace('.', ''), 'title': title, 'key': doc_key, + 'exp': int(time.time()) + 300 } if file_password: diff --git a/seahub/onlyoffice/settings.py b/seahub/onlyoffice/settings.py index 56a2842469..1cb69ab524 100644 --- a/seahub/onlyoffice/settings.py +++ b/seahub/onlyoffice/settings.py @@ -63,5 +63,3 @@ if ENABLE_MULTIPLE_OFFICE_SUITE: VERIFY_ONLYOFFICE_CERTIFICATE = office_info.get('VERIFY_ONLYOFFICE_CERTIFICATE', True) ONLYOFFICE_FILE_EXTENSION = OFFICE_SUITE_ENABLED_FILE_TYPES ONLYOFFICE_EDIT_FILE_EXTENSION = OFFICE_SUITE_ENABLED_EDIT_FILE_TYPES - - \ No newline at end of file diff --git a/seahub/onlyoffice/utils.py b/seahub/onlyoffice/utils.py index 534f19c74c..0cf3b3c440 100644 --- a/seahub/onlyoffice/utils.py +++ b/seahub/onlyoffice/utils.py @@ -4,6 +4,7 @@ import logging import urllib.parse import posixpath import json +import time from django.urls import reverse from django.utils.encoding import force_bytes @@ -197,7 +198,8 @@ def get_onlyoffice_dict(request, username, repo_id, file_path, file_id='', "customization": { "forcesave": ONLYOFFICE_FORCE_SAVE, }, - } + }, + 'exp': int(time.time()) + 3 * 24 * 3600 } if request.user.is_authenticated: diff --git a/seahub/onlyoffice/views.py b/seahub/onlyoffice/views.py index 192bcf665f..4acd94c0a3 100644 --- a/seahub/onlyoffice/views.py +++ b/seahub/onlyoffice/views.py @@ -5,6 +5,7 @@ import json import logging import requests import posixpath +import time import email.utils import urllib.parse @@ -433,6 +434,7 @@ class OnlyofficeGetHistoryFileAccessToken(APIView): payload['key'] = obj_id payload['url'] = full_url payload['version'] = obj_id + payload['exp'] = int(time.time()) + 3 * 24 * 3600 jwt_token = jwt.encode(payload, ONLYOFFICE_JWT_SECRET) payload['token'] = jwt_token diff --git a/seahub/templates/base_for_react.html b/seahub/templates/base_for_react.html index 2e5b9e0cb4..113020328a 100644 --- a/seahub/templates/base_for_react.html +++ b/seahub/templates/base_for_react.html @@ -152,8 +152,11 @@ showLogoutIcon: {% if show_logout_icon %} true {% else %} false {% endif %}, additionalShareDialogNote: {% if additional_share_dialog_note %} {{ additional_share_dialog_note|safe }} {% else %} null {% endif %}, additionalAboutDialogLinks: {% if additional_about_dialog_links %} {{ additional_about_dialog_links|safe }} {% else %} null {% endif %}, - enableOnlyoffice: {% if enableOnlyoffice %} true {% else %} false {% endif %}, - onlyofficeConverterExtensions: {% if onlyofficeConverterExtensions %} {{onlyofficeConverterExtensions|safe}} {% else %} null {% endif %}, + enableOnlyoffice: {% if enable_onlyoffice %} true {% else %} false {% endif %}, + onlyofficeEditFileExtension: {% if onlyoffice_edit_file_extension %} {{onlyoffice_edit_file_extension|safe}} {% else %} [] {% endif %}, + onlyofficeConverterExtensions: {% if onlyoffice_converter_extensions %} {{onlyoffice_converter_extensions|safe}} {% else %} null {% endif %}, + enableOfficeWebApp: {% if enable_office_web_app %} true {% else %} false {% endif %}, + officeWebAppEditFileExtension: {% if office_web_app_edit_file_extension %} {{office_web_app_edit_file_extension|safe}} {% else %} [] {% endif %}, enableSeadoc: {% if enable_seadoc %} true {% else %} false {% endif %}, enableWhiteboard: {% if enable_whiteboard %} true {% else %} false {% endif %}, isOrgContext: {% if org is not None %} true {% else %} false {% endif %}, diff --git a/seahub/views/file.py b/seahub/views/file.py index 1a2d5f9b5c..2dc9e20fef 100644 --- a/seahub/views/file.py +++ b/seahub/views/file.py @@ -398,7 +398,9 @@ def can_preview_file(file_name, file_size, repo): filesizeformat(FILE_PREVIEW_MAX_SIZE) return False, error_msg - elif filetype in (DOCUMENT, SPREADSHEET): + elif filetype in (DOCUMENT, SPREADSHEET) or \ + fileext in OFFICE_WEB_APP_FILE_EXTENSION or \ + fileext in ONLYOFFICE_FILE_EXTENSION: if repo.encrypted: error_msg = _('The library is encrypted, can not open file online.') diff --git a/seahub/wopi/settings.py b/seahub/wopi/settings.py index 6d933222da..15b5771429 100644 --- a/seahub/wopi/settings.py +++ b/seahub/wopi/settings.py @@ -13,7 +13,7 @@ OFFICE_WEB_APP_FILE_EXTENSION = getattr(settings, 'OFFICE_WEB_APP_FILE_EXTENSION ENABLE_OFFICE_WEB_APP_EDIT = getattr(settings, 'ENABLE_OFFICE_WEB_APP_EDIT', False) OFFICE_WEB_APP_EDIT_FILE_EXTENSION = getattr(settings, 'OFFICE_WEB_APP_EDIT_FILE_EXTENSION', ()) -## Client certificates ## +# Client certificates ## # path to client.cert when use client authentication OFFICE_WEB_APP_CLIENT_CERT = getattr(settings, 'OFFICE_WEB_APP_CLIENT_CERT', '') @@ -24,7 +24,7 @@ OFFICE_WEB_APP_CLIENT_KEY = getattr(settings, 'OFFICE_WEB_APP_CLIENT_KEY', '') OFFICE_WEB_APP_CLIENT_PEM = getattr(settings, 'OFFICE_WEB_APP_CLIENT_PEM', '') -## Server certificates ## +# Server certificates ## # Path to a CA_BUNDLE file or directory with certificates of trusted CAs OFFICE_WEB_APP_SERVER_CA = getattr(settings, 'OFFICE_WEB_APP_SERVER_CA', True) @@ -46,5 +46,3 @@ if settings.ENABLE_MULTIPLE_OFFICE_SUITE: ENABLE_OFFICE_WEB_APP_EDIT = office_info.get('ENABLE_OFFICE_WEB_APP_EDIT', False) OFFICE_WEB_APP_FILE_EXTENSION = settings.OFFICE_SUITE_ENABLED_FILE_TYPES OFFICE_WEB_APP_EDIT_FILE_EXTENSION = settings.OFFICE_SUITE_ENABLED_EDIT_FILE_TYPES - -