nextcloud / files_lock

GNU Affero General Public License v3.0
25 stars 8 forks source link

Allow collaboratively work on locked file #51

Closed tobiasKaminsky closed 2 years ago

tobiasKaminsky commented 2 years ago
juliusknorr commented 2 years ago

Things to expose from the DAV perspective:

juliusknorr commented 2 years ago

Copying over notes from #45 to avoid having multiple issues about the same topic:

For collaborative editing with Text, Nextcloud Office or ONLYOFFICE it would be useful if the collaborative editing app could lock a file on behalf of the editing session rather than per-user based. This way sync clients and the web UI could indicate the file lock while the app itself which handles changes can properly write to it.

The basic idea would be that the app can issue a lock/unlock through some kind of exposed API, similar to the user one in https://github.com/nextcloud/files_lock/blob/master/lib/Service/LockService.php#L237

Then when performing write actions the app would need to have a method to exclude further detection of locks for operation, so that any follow up filesystem actions would not trigger the locking in https://github.com/nextcloud/files_lock/blob/master/lib/Storage/LockWrapper.php#L110

From the app perspective I imagine something like this:

public function openFile($fileId) {
    $this->lockService->lockFileForApp($fileId, 'text');
}

public function writeFile($content) {
    $this->lockService->enableAppScope('text');
    $file->putContents($content); // does not throw a LockedException if the lock is owned by the same app id
}

public function closeFile($fileId) {
    $this->lockService->unlockFileForApp($fileId, 'text');
}