Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2022-04-21 12:43:09 +02:00
Родитель 53d1012f7f
Коммит 5c9225e886
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4C614C6ED2CDE6DF
4 изменённых файлов: 47 добавлений и 7 удалений

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

@ -110,6 +110,11 @@ class ApiService {
$content = null;
}
$lockInfo = $this->documentService->getLockInfo($file);
if ($lockInfo && $lockInfo->getType() === ILock::TYPE_APP && $lockInfo->getOwner() === Application::APP_NAME) {
$lockInfo = null;
}
$isLocked = $this->documentService->lock($fileId);
if (!$isLocked) {
$readOnly = true;
@ -119,7 +124,8 @@ class ApiService {
'document' => $document,
'session' => $session,
'readOnly' => $readOnly,
'content' => $content
'content' => $content,
'lock' => $lockInfo,
]);
}

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

@ -30,6 +30,8 @@ use \InvalidArgumentException;
use OCA\Text\AppInfo\Application;
use OCA\Text\Db\Session;
use OCA\Text\Db\SessionMapper;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\DirectEditing\IManager;
use OCP\Files\Lock\ILock;
use OCP\Files\Lock\ILockManager;
@ -256,20 +258,19 @@ class DocumentService {
}
/**
* @param $file
* @param $documentId
* @param $version
* @param $autoaveDocument
* @param bool $force
* @param bool $manualSave
* @param null $shareToken
* @param null $filePath
* @return Document
* @throws DocumentSaveConflictException
* @throws DoesNotExistException
* @throws GenericFileException
* @throws InvalidPathException
* @throws NotFoundException
* @throws NotPermittedException
* @throws ShareNotFound
* @throws \OCP\DB\Exception
*/
public function autosave($file, $documentId, $version, $autoaveDocument, $force = false, $manualSave = false, $shareToken = null, $filePath = null): Document {
/** @var Document $document */
@ -442,7 +443,27 @@ class DocumentService {
} else {
$readOnly = !$file->isUpdateable();
}
return $readOnly;
$lockInfo = $this->getLockInfo($file);
$isTextLock = (
$lockInfo && $lockInfo->getType() === ILock::TYPE_APP && $lockInfo->getOwner() === Application::APP_NAME
);
if ($isTextLock) {
return $readOnly;
}
return $readOnly || $lockInfo !== null;
}
public function getLockInfo($file): ?ILock {
try {
$locks = $this->lockManager->getLocks($file->getId());
} catch (NoLockProviderException|PreConditionNotMetException $e) {
return null;
}
return array_shift($locks);
}
/**

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

@ -32,6 +32,9 @@
<p v-else-if="hasConnectionIssue" class="msg">
{{ t('text', 'File could not be loaded. Please check your internet connection.') }} <a class="button primary" @click="reconnect">{{ t('text', 'Reconnect') }}</a>
</p>
<p v-if="lock" class="msg msg-locked">
<Lock /> {{ t('text', 'This file is opened read-only as it is currently locked by {user}.', { user: lock.displayName }) }}
</p>
</div>
<div v-if="displayed" id="editor-wrapper" :class="{'has-conflicts': hasSyncCollission, 'icon-loading': !contentLoaded && !hasConnectionIssue, 'richEditor': isRichEditor, 'show-color-annotations': showAuthorAnnotations}">
<div v-if="tiptap"
@ -106,7 +109,7 @@ import store from './../mixins/store'
import Tooltip from '@nextcloud/vue/dist/Directives/Tooltip'
import { getVersion, receiveTransaction } from 'prosemirror-collab'
import { Step } from 'prosemirror-transform'
import Lock from 'vue-material-design-icons/Lock'
const EDITOR_PUSH_DEBOUNCE = 200
const IMAGE_MIMES = [
@ -132,6 +135,7 @@ export default {
GuestNameDialog: () => import(/* webpackChunkName: "editor-guest" */'./GuestNameDialog'),
SessionList: () => import(/* webpackChunkName: "editor-collab" */'./SessionList'),
HelpModal: () => import(/* webpackChunkName: "editor-collab" */'./HelpModal'),
Lock,
},
directives: {
Tooltip,
@ -342,6 +346,7 @@ export default {
this.currentSession = session
this.document = document
this.readOnly = document.readOnly
this.lock = this.syncService.lock
localStorage.setItem('nick', this.currentSession.guestName)
this.$store.dispatch('setCurrentSession', this.currentSession)
})
@ -692,6 +697,11 @@ export default {
.button {
margin-left: 8px;
}
&.msg-locked .lock-icon {
padding: 0 10px;
float: left;
}
}
}

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

@ -93,6 +93,8 @@ class SyncService {
this.lastStepPush = Date.now()
this.lock = null
return this
}
@ -102,6 +104,7 @@ class SyncService {
this.document = connectionData.document
this.document.readOnly = connectionData.readOnly
this.session = connectionData.session
this.lock = connectionData.lock
this.emit('opened', {
document: this.document,
session: this.session,