From b1f6d0630ec11afae4606fafa6d960a732fa8dee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 8 Feb 2022 18:11:54 +0100 Subject: [PATCH 1/3] Move lock/unlock API endpoints to OCS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- appinfo/info.xml | 3 +-- appinfo/routes.php | 2 +- js/files.js | 4 ++-- lib/Controller/LockController.php | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index a2b8c119..33221228 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -37,7 +37,6 @@ Allow your users to temporary lock their files to avoid conflicts while working - + - diff --git a/appinfo/routes.php b/appinfo/routes.php index 351bfa8b..1770ab1b 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -28,7 +28,7 @@ return [ - 'routes' => [ + 'ocs' => [ ['name' => 'Lock#locking', 'url' => '/lock/{fileId}', 'verb' => 'PUT'], ['name' => 'Lock#unlocking', 'url' => '/lock/{fileId}', 'verb' => 'DELETE'], ] diff --git a/js/files.js b/js/files.js index 29049e6f..947993ff 100644 --- a/js/files.js +++ b/js/files.js @@ -116,7 +116,7 @@ if (locked !== undefined && locked) { $.ajax({ method: 'DELETE', - url: OC.generateUrl('/apps/files_lock/lock/' + fileId) + url: OC.linkToOCS('/apps/files_lock/lock', 2) + fileId }).done(function(res) { model.set('locked', false) }).fail(function(res) { @@ -125,7 +125,7 @@ } else { $.ajax({ method: 'PUT', - url: OC.generateUrl('/apps/files_lock/lock/' + fileId) + url: OC.linkToOCS('/apps/files_lock/lock', 2) + fileId }).done(function(res) { model.set('locked', true) model.set('lockOwner', OC.getCurrentUser().uid) diff --git a/lib/Controller/LockController.php b/lib/Controller/LockController.php index ed869a07..6f039dea 100644 --- a/lib/Controller/LockController.php +++ b/lib/Controller/LockController.php @@ -35,9 +35,9 @@ use OCA\FilesLock\Service\FileService; use OCA\FilesLock\Service\LockService; use OCA\FilesLock\Tools\Traits\TLogger; -use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\OCSController; use OCP\IRequest; use OCP\IUserSession; @@ -47,7 +47,7 @@ * * @package OCA\FilesLock\Controller */ -class LockController extends Controller { +class LockController extends OCSController { use TLogger; From 2f26726fe06aca365cfaf12aa1862bb587620823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 8 Feb 2022 18:23:42 +0100 Subject: [PATCH 2/3] Update README with current API state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- README.md | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d9702acb..8f1407ab 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -### the Files Lock app - +# Temporary files lock ![](screenshots/0.7.0.png) @@ -25,3 +24,88 @@ Administrators can also lock files using the `./occ` command: ![](screenshots/cli.png) +## API + +### Fetching lock details + +WebDAV returns the following additional properties if requests through a `PROPFIND`: + +- `{http://nextcloud.org/ns}lock`: `true` if the file is locked, otherwise `false` +- `{http://nextcloud.org/ns}lock-owner`: User id of the lock owner +- `{http://nextcloud.org/ns}lock-owner-displayname`: Display name of the lock owner +- `{http://nextcloud.org/ns}lock-time`: Timestamp of the log creation time + +### Locking a file + +`PUT /apps/files_lock/lock/{fileId}` + +```bash +curl -X PUT 'http://admin:admin@nextcloud.local/ocs/v2.php/apps/files_lock/lock/123' -H 'OCS-APIREQUEST: true'` +``` + +#### Success +``` + + + + ok + 200 + OK + + +``` + +#### Failure +``` + + + + failure + 500 + + + + -1 + OCA\FilesLock\Exceptions\AlreadyLockedException + File is already locked by admin + + +``` + + +### Unlocking a file + +`DELETE /apps/files_lock/lock/{fileId}` + +```bash +curl -X DELETE 'http://admin:admin@nextcloud.local/ocs/v2.php/apps/files_lock/lock/123' -H 'OCS-APIREQUEST: true' +``` + +#### Success +``` + + + + ok + 200 + OK + + +``` + +#### Failure +``` + + + + failure + 500 + + + + -1 + OCA\FilesLock\Exceptions\LockNotFoundException + + + +``` From c211bbeab508b54c5d36fdd5808573210bd00f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 8 Feb 2022 18:27:05 +0100 Subject: [PATCH 3/3] Expose capability for locking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- README.md | 13 +++++++++++++ lib/AppInfo/Application.php | 2 ++ lib/Capability.php | 17 +++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 lib/Capability.php diff --git a/README.md b/README.md index 8f1407ab..70eab09d 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,19 @@ Administrators can also lock files using the `./occ` command: ## API +### Capability + +If locking is available the app will expose itself through the capabilties endpoint under the files key: +``` +curl http://admin:admin@nextcloud.local/ocs/v1.php/cloud/capabilities\?format\=json -H 'OCS-APIRequest: true' \ + | jq .ocs.data.capabilities.files +{ + ... + "locking": "1.0", + ... +} +``` + ### Fetching lock details WebDAV returns the following additional properties if requests through a `PROPFIND`: diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 7fac78f0..7feadf6e 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -35,6 +35,7 @@ use OCA\DAV\Connector\Sabre\CachingTree; use OCA\DAV\Connector\Sabre\ObjectTree; use OCA\Files\Event\LoadAdditionalScriptsEvent; +use OCA\FilesLock\Capability; use OCA\FilesLock\Listeners\LoadAdditionalScripts; use OCA\FilesLock\Plugins\FilesLockPlugin; use OCA\FilesLock\Service\FileService; @@ -91,6 +92,7 @@ public function __construct(array $params = array()) { * @param IRegistrationContext $context */ public function register(IRegistrationContext $context): void { + $context->registerCapability(Capability::class); $context->registerEventListener( LoadAdditionalScriptsEvent::class, LoadAdditionalScripts::class diff --git a/lib/Capability.php b/lib/Capability.php new file mode 100644 index 00000000..ccae5296 --- /dev/null +++ b/lib/Capability.php @@ -0,0 +1,17 @@ + [ + 'locking' => '1.0', + ] + ]; + } + +}