Skip to content

Commit

Permalink
fix: Allow to unlock through separate endpoint for edit locally
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliushaertl committed Mar 26, 2024
1 parent ba917a4 commit 82200ed
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
'ocs' => [
// Public pages: new file creation
['name' => 'documentAPI#create', 'url' => '/api/v1/file', 'verb' => 'POST'],
['name' => 'documentAPI#openLocal', 'url' => '/api/v1/local', 'verb' => 'POST'],

// Client API endpoints
['name' => 'OCS#createDirect', 'url' => '/api/v1/document', 'verb' => 'POST'],
Expand Down
30 changes: 29 additions & 1 deletion lib/Controller/DocumentAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@
use OCA\Richdocuments\Helper;
use OCA\Richdocuments\TemplateManager;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\Lock\ILock;
use OCP\Files\Lock\ILockManager;
use OCP\Files\Lock\LockContext;
use OCP\Files\Lock\NoLockProviderException;
use OCP\IL10N;
use OCP\IRequest;
use OCP\PreConditionNotMetException;
use OCP\Share\IManager;
use Psr\Log\LoggerInterface;
use Throwable;
Expand All @@ -45,15 +51,17 @@ class DocumentAPIController extends \OCP\AppFramework\OCSController {
private $templateManager;
private $l10n;
private $logger;
private $lockManager;
private $userId;

public function __construct(IRequest $request, IRootFolder $rootFolder, IManager $shareManager, TemplateManager $templateManager, IL10N $l10n, LoggerInterface $logger, $userId) {
public function __construct(IRequest $request, IRootFolder $rootFolder, IManager $shareManager, TemplateManager $templateManager, IL10N $l10n, LoggerInterface $logger, ILockManager $lockManager, $userId) {
parent::__construct(Application::APPNAME, $request);
$this->rootFolder = $rootFolder;
$this->shareManager = $shareManager;
$this->templateManager = $templateManager;
$this->l10n = $l10n;
$this->logger = $logger;
$this->lockManager = $lockManager;
$this->userId = $userId;
}

Expand Down Expand Up @@ -147,4 +155,24 @@ public function create(string $mimeType, string $fileName, string $directoryPath
'data' => \OCA\Files\Helper::formatFileInfo($file->getFileInfo())
]);
}

/**
* @NoAdminRequired
*/
public function openLocal(int $fileId): DataResponse {
try {
$files = $this->rootFolder->getUserFolder($this->userId)->getById($fileId);
$file = array_shift($files);
$this->lockManager->unlock(new LockContext(
$file,
ILock::TYPE_APP,
Application::APPNAME
));
return new DataResponse([]);
} catch (NoLockProviderException|PreConditionNotMetException $e) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
} catch (\Exception $e) {
return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
}
}
}
6 changes: 1 addition & 5 deletions src/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,11 +591,7 @@ const documentsMain = {
},

unlockFile() {
const unlockUrl = getRootUrl() + '/index.php/apps/richdocuments/wopi/files/' + documentsMain.fileId
const unlockConfig = {
headers: { 'X-WOPI-Override': 'UNLOCK' },
}
return axios.post(unlockUrl, { access_token: documentsMain.token }, unlockConfig)
return axios.post(generateOcsUrl('apps/richdocuments/api/v1/local'), { fileId: this.fileid })
},

openLocally() {
Expand Down
4 changes: 2 additions & 2 deletions src/view/Office.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ import { loadState } from '@nextcloud/initial-state'
import ZoteroHint from '../components/Modal/ZoteroHint.vue'
import { basename, dirname } from 'path'
import { getDocumentUrlForFile, getDocumentUrlForPublicFile } from '../helpers/url.js'
import { getDocumentUrlForFile, getDocumentUrlForPublicFile, getNextcloudUrl } from '../helpers/url.js'
import PostMessageService from '../services/postMessage.tsx'
import FilesAppIntegration from './FilesAppIntegration.js'
import { LOADING_ERROR, checkCollaboraConfiguration, checkProxyStatus } from '../services/collabora.js'
import { enableScrollLock, disableScrollLock } from '../helpers/safariFixer.js'
import { imagePath } from '@nextcloud/router'
const FRAME_DOCUMENT = 'FRAME_DOCUMENT'
const PostMessages = new PostMessageService({
FRAME_DOCUMENT: () => document.getElementById('collaboraframe').contentWindow,
Expand Down

0 comments on commit 82200ed

Please sign in to comment.