fix: Allow to unlock through separate endpoint for edit locally

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2024-02-21 12:48:08 +01:00
Родитель 5570aa7b91
Коммит 3c583055e7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4C614C6ED2CDE6DF
3 изменённых файлов: 31 добавлений и 7 удалений

Просмотреть файл

@ -77,6 +77,7 @@ return [
'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'],

Просмотреть файл

@ -30,11 +30,17 @@ use OCA\Richdocuments\AppInfo\Application;
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;
@ -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;
}
@ -147,4 +155,23 @@ class DocumentAPIController extends \OCP\AppFramework\OCSController {
'data' => \OCA\Files\Helper::formatFileInfo($file->getFileInfo())
]);
}
#[Http\Attribute\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);
}
}
}

Просмотреть файл

@ -23,7 +23,7 @@ import { getCurrentUser } from '@nextcloud/auth'
import axios from '@nextcloud/axios'
import { spawnDialog } from '@nextcloud/dialogs'
import { encodePath } from '@nextcloud/paths'
import { getRootUrl, generateOcsUrl } from '@nextcloud/router'
import { generateOcsUrl } from '@nextcloud/router'
import { getNextcloudUrl } from '../helpers/url.js'
import Confirmation from '../components/Modal/Confirmation.vue'
@ -93,11 +93,7 @@ export default {
},
unlockFile() {
const unlockUrl = getRootUrl() + '/index.php/apps/richdocuments/wopi/files/' + this.fileid
const unlockConfig = {
headers: { 'X-WOPI-Override': 'UNLOCK' },
}
return axios.post(unlockUrl, { access_token: this.formData.accessToken }, unlockConfig)
return axios.post(generateOcsUrl('apps/richdocuments/api/v1/local'), { fileId: this.fileid })
},
openLocally() {