mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-08-26 12:16:07 +00:00
Display warnings when saving draft if another user is editing the page or if the page was updated since the current user has started editing the page.
This commit is contained in:
parent
c429cf7818
commit
537b1614c4
@ -26,6 +26,7 @@ class PageEditActivity
|
|||||||
*/
|
*/
|
||||||
public function hasActiveEditing(): bool
|
public function hasActiveEditing(): bool
|
||||||
{
|
{
|
||||||
|
$value = $this->activePageEditingQuery(60)->count();
|
||||||
return $this->activePageEditingQuery(60)->count() > 0;
|
return $this->activePageEditingQuery(60)->count() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,6 +44,16 @@ class PageEditActivity
|
|||||||
return trans('entities.pages_draft_edit_active.message', ['start' => $userMessage, 'time' => $timeMessage]);
|
return trans('entities.pages_draft_edit_active.message', ['start' => $userMessage, 'time' => $timeMessage]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the page has been updated since the draft has been saved.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function hasPageBeenUpdatedSinceDraftSaved(PageRevision $draft): bool
|
||||||
|
{
|
||||||
|
return $draft->page->updated_at->timestamp >= $draft->updated_at->timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the message to show when the user will be editing one of their drafts.
|
* Get the message to show when the user will be editing one of their drafts.
|
||||||
*
|
*
|
||||||
|
@ -258,6 +258,23 @@ class PageController extends Controller
|
|||||||
return $this->jsonError(trans('errors.guests_cannot_save_drafts'), 500);
|
return $this->jsonError(trans('errors.guests_cannot_save_drafts'), 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for active editing or time conflict
|
||||||
|
$warnings = [];
|
||||||
|
$jsonResponseWarning = '';
|
||||||
|
$editActivity = new PageEditActivity($page);
|
||||||
|
if ($editActivity->hasActiveEditing()) {
|
||||||
|
$warnings[] = $editActivity->activeEditingMessage();
|
||||||
|
}
|
||||||
|
$userDraft = $this->pageRepo->getUserDraft($page);
|
||||||
|
if ($userDraft !== null) {
|
||||||
|
if ($editActivity->hasPageBeenUpdatedSinceDraftSaved($userDraft)) {
|
||||||
|
$warnings[] = $editActivity->getEditingActiveDraftMessage($userDraft);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count($warnings) > 0) {
|
||||||
|
$jsonResponseWarning = implode("\n", $warnings);
|
||||||
|
}
|
||||||
|
|
||||||
$draft = $this->pageRepo->updatePageDraft($page, $request->only(['name', 'html', 'markdown']));
|
$draft = $this->pageRepo->updatePageDraft($page, $request->only(['name', 'html', 'markdown']));
|
||||||
|
|
||||||
$updateTime = $draft->updated_at->timestamp;
|
$updateTime = $draft->updated_at->timestamp;
|
||||||
@ -265,6 +282,7 @@ class PageController extends Controller
|
|||||||
return response()->json([
|
return response()->json([
|
||||||
'status' => 'success',
|
'status' => 'success',
|
||||||
'message' => trans('entities.pages_edit_draft_save_at'),
|
'message' => trans('entities.pages_edit_draft_save_at'),
|
||||||
|
'warning' => $jsonResponseWarning,
|
||||||
'timestamp' => $updateTime,
|
'timestamp' => $updateTime,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -119,6 +119,9 @@ class PageEditor {
|
|||||||
}
|
}
|
||||||
this.draftNotifyChange(`${resp.data.message} ${Dates.utcTimeStampToLocalTime(resp.data.timestamp)}`);
|
this.draftNotifyChange(`${resp.data.message} ${Dates.utcTimeStampToLocalTime(resp.data.timestamp)}`);
|
||||||
this.autoSave.last = Date.now();
|
this.autoSave.last = Date.now();
|
||||||
|
if (resp.data.warning.length > 0) {
|
||||||
|
window.$events.emit('warning', resp.data.warning);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Save the editor content in LocalStorage as a last resort, just in case.
|
// Save the editor content in LocalStorage as a last resort, just in case.
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user