diff --git a/js/mindmap.js b/js/mindmap.js index e431262..6dcc601 100644 --- a/js/mindmap.js +++ b/js/mindmap.js @@ -162,7 +162,8 @@ var FilesMindMap = { plugin.encode(data).then(function(data2) { var putObject = { filecontents: data2, - path: path + path: path, + mtime: OCA.FilesMindMap._file.mtime // send modification time of currently loaded file }; if ($('#isPublic').val()){ @@ -180,7 +181,11 @@ var FilesMindMap = { type: 'PUT', url: url, data: putObject - }).done(function(){ + }).done(function(data){ + // update modification time + try { + OCA.FilesMindMap._file.mtime = data.mtime; + } catch(e) {} success(t('files_mindmap', 'File Saved')); }).fail(function(jqXHR){ var message = t('files_mindmap', 'Save failed'); diff --git a/l10n/de.js b/l10n/de.js index d6c319e..07285da 100644 --- a/l10n/de.js +++ b/l10n/de.js @@ -26,6 +26,7 @@ OC.L10N.register( "Unsaved file": "Ungespeicherte Datei", "AutoSave": "AutoSave", "Does not support saving {extension} files.": "Speichern für den Dateityp {extension} nicht unterstützt.", - "Unsupported file type: {mimetype}": "Nicht unterstützter Dateityp: {mimetype}" + "Unsupported file type: {mimetype}": "Nicht unterstützter Dateityp: {mimetype}", + "The file you are working on was updated in the meantime. You cannot save your progress as saving would overwrite these changes. Please reload the page.": "Jemand hat in der Zwischenzeit die Datei aktualisiert, daher kannst du deine Änderungen leider nicht speichern. Bitte lade die Datei neu, um weiteren Datenverlust zu vermeiden." }, "nplurals=1; plural=0;" ); diff --git a/l10n/de.json b/l10n/de.json index 2648ba4..7d3510e 100644 --- a/l10n/de.json +++ b/l10n/de.json @@ -25,7 +25,8 @@ "Unsaved file": "Ungespeicherte Datei", "AutoSave": "AutoSave", "Does not support saving {extension} files.": "Speichern für den Dateityp {extension} nicht unterstützt.", - "Unsupported file type: {mimetype}": "Nicht unterstützter Dateityp: {mimetype}" + "Unsupported file type: {mimetype}": "Nicht unterstützter Dateityp: {mimetype}", + "The file you are working on was updated in the meantime. You cannot save your progress as saving would overwrite these changes. Please reload the page.": "Jemand hat in der Zwischenzeit die Datei aktualisiert, daher kannst du deine Änderungen leider nicht speichern. Bitte lade die Datei neu, um weiteren Datenverlust zu vermeiden." }, "pluralForm": "nplurals=1; plural=0;" } diff --git a/l10n/de_DE.js b/l10n/de_DE.js index d6c319e..07285da 100644 --- a/l10n/de_DE.js +++ b/l10n/de_DE.js @@ -26,6 +26,7 @@ OC.L10N.register( "Unsaved file": "Ungespeicherte Datei", "AutoSave": "AutoSave", "Does not support saving {extension} files.": "Speichern für den Dateityp {extension} nicht unterstützt.", - "Unsupported file type: {mimetype}": "Nicht unterstützter Dateityp: {mimetype}" + "Unsupported file type: {mimetype}": "Nicht unterstützter Dateityp: {mimetype}", + "The file you are working on was updated in the meantime. You cannot save your progress as saving would overwrite these changes. Please reload the page.": "Jemand hat in der Zwischenzeit die Datei aktualisiert, daher kannst du deine Änderungen leider nicht speichern. Bitte lade die Datei neu, um weiteren Datenverlust zu vermeiden." }, "nplurals=1; plural=0;" ); diff --git a/l10n/de_DE.json b/l10n/de_DE.json index 2648ba4..7d3510e 100644 --- a/l10n/de_DE.json +++ b/l10n/de_DE.json @@ -25,7 +25,8 @@ "Unsaved file": "Ungespeicherte Datei", "AutoSave": "AutoSave", "Does not support saving {extension} files.": "Speichern für den Dateityp {extension} nicht unterstützt.", - "Unsupported file type: {mimetype}": "Nicht unterstützter Dateityp: {mimetype}" + "Unsupported file type: {mimetype}": "Nicht unterstützter Dateityp: {mimetype}", + "The file you are working on was updated in the meantime. You cannot save your progress as saving would overwrite these changes. Please reload the page.": "Jemand hat in der Zwischenzeit die Datei aktualisiert, daher kannst du deine Änderungen leider nicht speichern. Bitte lade die Datei neu, um weiteren Datenverlust zu vermeiden." }, "pluralForm": "nplurals=1; plural=0;" } diff --git a/lib/Controller/FileHandlingController.php b/lib/Controller/FileHandlingController.php index 57f0660..b999c58 100644 --- a/lib/Controller/FileHandlingController.php +++ b/lib/Controller/FileHandlingController.php @@ -116,7 +116,7 @@ public function load($dir, $filename) { * @param string $filecontents * @return DataResponse */ - public function save($path, $filecontents) { + public function save($path, $filecontents, $mtime) { try { if($path !== '') { @@ -128,6 +128,10 @@ public function save($path, $filecontents) { } if($file->isUpdateable()) { + if ($mtime != $file->getMTime()) { + $this->logger->error("User cannot save shared mindmap (someone updated it in the meantime): {$mtime} vs. {$file->getMTime()} {$file->getPath()}", ['app' => 'files_mindmap']); + return new DataResponse([ 'message' => $this->l->t('The file you are working on was updated in the meantime. You cannot save your progress as saving would overwrite these changes. Please reload the page.')],Http::STATUS_BAD_REQUEST); + } try { $file->putContent($filecontents); } catch (LockedException $e) { diff --git a/lib/Controller/PublicFileHandlingController.php b/lib/Controller/PublicFileHandlingController.php index e622d80..8a40428 100644 --- a/lib/Controller/PublicFileHandlingController.php +++ b/lib/Controller/PublicFileHandlingController.php @@ -30,6 +30,7 @@ use OCP\Files\GenericFileException; use OCP\Files\NotFoundException; use OCP\IL10N; +use OCP\ILogger; use OCP\IRequest; use OCP\ISession; use OCP\Lock\LockedException; @@ -41,6 +42,9 @@ class PublicFileHandlingController extends Controller{ /** @var IL10N */ private $l; + /** @var ILogger */ + private $logger; + /** @var ShareManager */ private $shareManager; @@ -58,10 +62,12 @@ class PublicFileHandlingController extends Controller{ public function __construct($AppName, IRequest $request, IL10N $l10n, + ILogger $logger, ShareManager $shareManager, ISession $session) { parent::__construct($AppName, $request); $this->l = $l10n; + $this->logger = $logger; $this->shareManager = $shareManager; $this->session = $session; } @@ -155,7 +161,7 @@ public function load($token) { * @throws \OCP\Files\InvalidPathException * @throws \OCP\Files\NotPermittedException */ - public function save($token, $filecontents, $path) { + public function save($token, $filecontents, $path, $mtime) { try { $share = $this->shareManager->getShareByToken($token); } catch (ShareNotFound $e) { @@ -193,6 +199,10 @@ public function save($token, $filecontents, $path) { } if($file->isUpdateable()) { + if ($mtime != $file->getMTime()) { + $this->logger->error("Anonymous cannot save shared mindmap (someone updated it in the meantime): {$mtime} vs. {$file->getMTime()} {$file->getPath()}", ['app' => 'files_mindmap']); + return new DataResponse([ 'message' => $this->l->t('The file you are working on was updated in the meantime. You cannot save your progress as saving would overwrite these changes. Please reload the page.')],Http::STATUS_BAD_REQUEST); + } try { $file->putContent($filecontents); } catch (LockedException $e) { diff --git a/templates/viewer.php b/templates/viewer.php index fbfc455..53b4d8b 100644 --- a/templates/viewer.php +++ b/templates/viewer.php @@ -23,9 +23,9 @@ - - + " /> +