@@ -1422,7 +1422,7 @@ void FolderMan::setDirtyNetworkLimits()
14221422 }
14231423}
14241424
1425- void FolderMan::editFileLocally (const QString &accountDisplayName, const QString &relPath)
1425+ void FolderMan::editFileLocally (const QString &accountDisplayName, const QString &relPath, const QString &token )
14261426{
14271427 const auto showError = [this ](const OCC ::AccountStatePtr accountState, const QString &errorMessage, const QString &subject) {
14281428 if (accountState && accountState->account ()) {
@@ -1447,6 +1447,12 @@ void FolderMan::editFileLocally(const QString &accountDisplayName, const QString
14471447 messageBox->raise ();
14481448 };
14491449
1450+ if (token.isEmpty ()) {
1451+ qCWarning (lcFolderMan) << " Edit locally request is missing a valid token. Impossible to open the file." ;
1452+ showError ({}, tr (" Edit locally request is not valid. Opening the file is forbidden." ), accountDisplayName);
1453+ return ;
1454+ }
1455+
14501456 const auto accountFound = AccountManager::instance ()->account (accountDisplayName);
14511457
14521458 if (!accountFound) {
@@ -1488,23 +1494,38 @@ void FolderMan::editFileLocally(const QString &accountDisplayName, const QString
14881494 showError (accountFound, tr (" Could not find a file for local editing. Make sure its path is valid and it is synced locally." ), relPath);
14891495 return ;
14901496 }
1491- folderForFile->startSync ();
1492- _localFileEditingSyncFinishedConnections.insert (localFilePath, QObject::connect (folderForFile, &Folder::syncFinished, this ,
1493- [this , localFilePath](const OCC ::SyncResult &result) {
1494- Q_UNUSED (result);
1495- const auto foundConnectionIt = _localFileEditingSyncFinishedConnections.find (localFilePath);
1496- if (foundConnectionIt != std::end (_localFileEditingSyncFinishedConnections) && foundConnectionIt.value ()) {
1497- QObject::disconnect (foundConnectionIt.value ());
1498- _localFileEditingSyncFinishedConnections.erase (foundConnectionIt);
1499- }
1500- // In case the VFS mode is enabled and a file is not yet hydrated, we must call QDesktopServices::openUrl
1501- // from a separate thread, or, there will be a freeze. To avoid searching for a specific folder and checking
1502- // if the VFS is enabled - we just always call it from a separate thread.
1503- QtConcurrent::run ([localFilePath]() {
1504- QDesktopServices::openUrl (QUrl::fromLocalFile (localFilePath));
1497+
1498+ const auto checkTokenForEditLocally = new SimpleApiJob (accountFound->account (), QStringLiteral (" /ocs/v2.php/apps/files/api/v1/openlocaleditor/%1" ).arg (token));
1499+ checkTokenForEditLocally->setVerb (SimpleApiJob::Verb::Post);
1500+ checkTokenForEditLocally->setBody (QByteArray{" path=/" }.append (relPath.toUtf8 ()));
1501+ connect (checkTokenForEditLocally, &SimpleApiJob::resultReceived, checkTokenForEditLocally, [this , folderForFile, localFilePath, showError, accountFound, relPath] (int statusCode) {
1502+ constexpr auto HTTP_OK_CODE = 200 ;
1503+ if (statusCode != HTTP_OK_CODE ) {
15051504 Systray::instance ()->destroyEditFileLocallyLoadingDialog ();
1506- });
1507- }));
1505+ showError (accountFound, tr (" Could not validate the request to open a file from server." ), relPath);
1506+ qCInfo (lcFolderMan ()) << " token check result" << statusCode;
1507+ return ;
1508+ }
1509+
1510+ folderForFile->startSync ();
1511+ _localFileEditingSyncFinishedConnections.insert (localFilePath, QObject::connect (folderForFile, &Folder::syncFinished, this ,
1512+ [this , localFilePath](const OCC ::SyncResult &result) {
1513+ Q_UNUSED (result);
1514+ const auto foundConnectionIt = _localFileEditingSyncFinishedConnections.find (localFilePath);
1515+ if (foundConnectionIt != std::end (_localFileEditingSyncFinishedConnections) && foundConnectionIt.value ()) {
1516+ QObject::disconnect (foundConnectionIt.value ());
1517+ _localFileEditingSyncFinishedConnections.erase (foundConnectionIt);
1518+ }
1519+ // In case the VFS mode is enabled and a file is not yet hydrated, we must call QDesktopServices::openUrl
1520+ // from a separate thread, or, there will be a freeze. To avoid searching for a specific folder and checking
1521+ // if the VFS is enabled - we just always call it from a separate thread.
1522+ QtConcurrent::run ([localFilePath]() {
1523+ QDesktopServices::openUrl (QUrl::fromLocalFile (localFilePath));
1524+ Systray::instance ()->destroyEditFileLocallyLoadingDialog ();
1525+ });
1526+ }));
1527+ });
1528+ checkTokenForEditLocally->start ();
15081529}
15091530
15101531void FolderMan::trayOverallStatus (const QList<Folder *> &folders,
0 commit comments