Implement infrastructure for detecting and handling of simultaneous edits.
This commit is contained in:
+7
-1
@@ -176,6 +176,7 @@ module Precious
|
||||
@page = page
|
||||
@page.version = wiki.repo.log(wiki.ref, @page.path).first
|
||||
@content = page.text_data
|
||||
@etag = Digest::SHA1.hexdigest(@content)
|
||||
mustache :edit
|
||||
else
|
||||
redirect_to("/create/#{encodeURIComponent(@name)}")
|
||||
@@ -278,11 +279,17 @@ module Precious
|
||||
end
|
||||
|
||||
post '/edit/*' do
|
||||
etag = params[:etag]
|
||||
path = "/#{clean_url(sanitize_empty_params(params[:path]))}"
|
||||
page_name = CGI.unescape(params[:page])
|
||||
wiki = wiki_new
|
||||
page = wiki.paged(page_name, path, exact = true)
|
||||
|
||||
return if page.nil?
|
||||
if etag != Digest::SHA1.hexdigest(page.text_data)
|
||||
halt 412, 'For future use: some helpful data for resolving the conflict here.'
|
||||
end
|
||||
|
||||
committer = Gollum::Committer.new(wiki, commit_message)
|
||||
commit = { :committer => committer }
|
||||
|
||||
@@ -292,7 +299,6 @@ module Precious
|
||||
update_wiki_page(wiki, page.sidebar, params[:sidebar], commit) if params[:sidebar]
|
||||
committer.commit
|
||||
|
||||
redirect to("/#{page.escaped_url_path}") unless page.nil?
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -367,6 +367,34 @@ $(document).ready(function() {
|
||||
window.onbeforeunload = function(){ return "Leaving will discard all edits!" };
|
||||
});
|
||||
$.GollumEditor();
|
||||
$("#gollum-editor-submit").click( function(e) {
|
||||
e.preventDefault();
|
||||
// Prevent button from being clicked again
|
||||
$(this).attr('disabled', true);
|
||||
|
||||
var formData = new FormData($('#gollum-editor-form').get(0));
|
||||
var endpoint = $('#gollum-editor-form').attr("action");
|
||||
|
||||
$.ajax({
|
||||
url: endpoint,
|
||||
type: 'POST',
|
||||
data: formData,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: function(data) {
|
||||
window.location = window.location.href.replace(/gollum\/edit\//, '')
|
||||
},
|
||||
error: function(data, textStatus, errorThrown) {
|
||||
if (data.status == 412) {
|
||||
$('#gollum-editor-submit').attr('disabled', false)
|
||||
alert('Someone else has modified this page while you were editing it. Please store your version on disk outside of the browser, reload this page and reapply your modifications.');
|
||||
} else {
|
||||
alert('Error updating page: ' + textStatus + ' ' + errorThrown);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
if( $("#last-edit").length ) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<div id="gollum-editor" data-escaped-name="{{escaped_name}}" class="{{#is_create_page}}create{{/is_create_page}}{{#is_edit_page}}edit{{/is_edit_page}} {{#allow_uploads}}uploads-allowed{{/allow_uploads}}">
|
||||
{{#is_create_page}}
|
||||
<form name="gollum-editor" action="{{create_path}}" method="post">
|
||||
<form id="gollum-editor-form" name="gollum-editor" action="{{create_path}}" method="post">
|
||||
{{/is_create_page}}
|
||||
{{#is_edit_page}}
|
||||
<form name="gollum-editor" action="{{edit_path}}/{{escaped_name}}" method="post">
|
||||
<form id="gollum-editor-form" name="gollum-editor" action="{{edit_path}}/{{escaped_name}}" method="post">
|
||||
{{/is_edit_page}}
|
||||
<fieldset id="gollum-editor-fields">
|
||||
{{#is_create_page}}
|
||||
@@ -17,6 +17,7 @@
|
||||
{{/is_create_page}}
|
||||
{{#is_edit_page}}
|
||||
<input type="hidden" name="page" id="gollum-editor-page-title" value="{{page_name}}">
|
||||
<input type="hidden" name="etag" id="gollum-editor-etag" value="{{etag}}">
|
||||
{{/is_edit_page}}
|
||||
<input type="hidden" name="path" id="gollum-editor-page-path" value="{{path}}">
|
||||
<div id="gollum-editor-function-bar">
|
||||
|
||||
@@ -60,6 +60,9 @@ module Precious
|
||||
true
|
||||
end
|
||||
|
||||
def etag
|
||||
@etag
|
||||
end
|
||||
|
||||
def allow_uploads
|
||||
@allow_uploads
|
||||
|
||||
Reference in New Issue
Block a user