summaryrefslogtreecommitdiff
path: root/app/models/wiki_page.rb
diff options
context:
space:
mode:
authorHiroyuki Sato <h-sato@ruby-dev.jp>2017-03-04 23:03:14 +0900
committerHiroyuki Sato <sathiroyuki@gmail.com>2017-03-08 18:42:50 +0900
commita5521bad4012a9eea21cb067271c8ec1810c6d8c (patch)
tree3544226812c93e9abfcaceafd939fc4a168ecd61 /app/models/wiki_page.rb
parente78a366925553a1268f8dc6e0d57342053a3240a (diff)
downloadgitlab-ce-a5521bad4012a9eea21cb067271c8ec1810c6d8c.tar.gz
Prevent concurrent editing wiki
Diffstat (limited to 'app/models/wiki_page.rb')
-rw-r--r--app/models/wiki_page.rb17
1 files changed, 12 insertions, 5 deletions
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb
index 2caebb496db..4c5df6937f2 100644
--- a/app/models/wiki_page.rb
+++ b/app/models/wiki_page.rb
@@ -1,4 +1,6 @@
class WikiPage
+ PageChangedError = Class.new(StandardError)
+
include ActiveModel::Validations
include ActiveModel::Conversion
include StaticModel
@@ -176,17 +178,22 @@ class WikiPage
# Updates an existing Wiki Page, creating a new version.
#
- # new_content - The raw markup content to replace the existing.
- # format - Optional symbol representing the content format.
- # See ProjectWiki::MARKUPS Hash for available formats.
- # message - Optional commit message to set on the new version.
+ # new_content - The raw markup content to replace the existing.
+ # format - Optional symbol representing the content format.
+ # See ProjectWiki::MARKUPS Hash for available formats.
+ # message - Optional commit message to set on the new version.
+ # last_commit_sha - Optional last commit sha to validate the page unchanged.
#
# Returns the String SHA1 of the newly created page
# or False if the save was unsuccessful.
- def update(new_content = "", format = :markdown, message = nil)
+ def update(new_content = "", format = :markdown, message = nil, last_commit_sha = nil)
@attributes[:content] = new_content
@attributes[:format] = format
+ if last_commit_sha && last_commit_sha != commit.sha
+ raise PageChangedError.new("You are attempting to update a page that has changed since you started editing it.")
+ end
+
save :update_page, @page, content, format, message
end