BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
a5521bad
Commit
a5521bad
authored
Mar 04, 2017
by
Hiroyuki Sato
Committed by
Hiroyuki Sato
Mar 08, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent concurrent editing wiki
parent
e78a3669
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
50 additions
and
4 deletions
+50
-4
wikis_controller.rb
app/controllers/projects/wikis_controller.rb
+4
-1
wiki_page.rb
app/models/wiki_page.rb
+8
-1
update_service.rb
app/services/wiki_pages/update_service.rb
+1
-1
_form.html.haml
app/views/projects/wikis/_form.html.haml
+2
-0
edit.html.haml
app/views/projects/wikis/edit.html.haml
+6
-0
1827-prevent-concurrent-editing-wiki.yml
...elogs/unreleased/1827-prevent-concurrent-editing-wiki.yml
+4
-0
user_updates_wiki_page_spec.rb
spec/features/projects/wiki/user_updates_wiki_page_spec.rb
+11
-1
wiki_page_spec.rb
spec/models/wiki_page_spec.rb
+14
-0
No files found.
app/controllers/projects/wikis_controller.rb
View file @
a5521bad
...
@@ -56,6 +56,9 @@ class Projects::WikisController < Projects::ApplicationController
...
@@ -56,6 +56,9 @@ class Projects::WikisController < Projects::ApplicationController
else
else
render
'edit'
render
'edit'
end
end
rescue
WikiPage
::
PageChangedError
@conflict
=
true
render
'edit'
end
end
def
create
def
create
...
@@ -125,6 +128,6 @@ class Projects::WikisController < Projects::ApplicationController
...
@@ -125,6 +128,6 @@ class Projects::WikisController < Projects::ApplicationController
end
end
def
wiki_params
def
wiki_params
params
[
:wiki
].
slice
(
:title
,
:content
,
:format
,
:message
)
params
[
:wiki
].
slice
(
:title
,
:content
,
:format
,
:message
,
:last_commit_sha
)
end
end
end
end
app/models/wiki_page.rb
View file @
a5521bad
class
WikiPage
class
WikiPage
PageChangedError
=
Class
.
new
(
StandardError
)
include
ActiveModel
::
Validations
include
ActiveModel
::
Validations
include
ActiveModel
::
Conversion
include
ActiveModel
::
Conversion
include
StaticModel
include
StaticModel
...
@@ -180,13 +182,18 @@ class WikiPage
...
@@ -180,13 +182,18 @@ class WikiPage
# format - Optional symbol representing the content format.
# format - Optional symbol representing the content format.
# See ProjectWiki::MARKUPS Hash for available formats.
# See ProjectWiki::MARKUPS Hash for available formats.
# message - Optional commit message to set on the new version.
# 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
# Returns the String SHA1 of the newly created page
# or False if the save was unsuccessful.
# 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
[
:content
]
=
new_content
@attributes
[
:format
]
=
format
@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
save
:update_page
,
@page
,
content
,
format
,
message
end
end
...
...
app/services/wiki_pages/update_service.rb
View file @
a5521bad
module
WikiPages
module
WikiPages
class
UpdateService
<
WikiPages
::
BaseService
class
UpdateService
<
WikiPages
::
BaseService
def
execute
(
page
)
def
execute
(
page
)
if
page
.
update
(
@params
[
:content
],
@params
[
:format
],
@params
[
:message
])
if
page
.
update
(
@params
[
:content
],
@params
[
:format
],
@params
[
:message
]
,
@params
[
:last_commit_sha
]
)
execute_hooks
(
page
,
'update'
)
execute_hooks
(
page
,
'update'
)
end
end
...
...
app/views/projects/wikis/_form.html.haml
View file @
a5521bad
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
=
form_errors
(
@page
)
=
form_errors
(
@page
)
=
f
.
hidden_field
:title
,
value:
@page
.
title
=
f
.
hidden_field
:title
,
value:
@page
.
title
-
if
@page
.
persisted?
=
f
.
hidden_field
:last_commit_sha
,
value:
@page
.
commit
.
sha
.form-group
.form-group
=
f
.
label
:format
,
class:
'control-label'
=
f
.
label
:format
,
class:
'control-label'
.col-sm-10
.col-sm-10
...
...
app/views/projects/wikis/edit.html.haml
View file @
a5521bad
...
@@ -2,6 +2,12 @@
...
@@ -2,6 +2,12 @@
-
page_title
"Edit"
,
@page
.
title
.
capitalize
,
"Wiki"
-
page_title
"Edit"
,
@page
.
title
.
capitalize
,
"Wiki"
%div
{
class:
container_class
}
%div
{
class:
container_class
}
-
if
@conflict
.alert.alert-danger
Someone edited the page the same time you did. Please check out
=
link_to
"the page"
,
namespace_project_wiki_path
(
@project
.
namespace
,
@project
,
@page
),
target:
"_blank"
and make sure your changes will not unintentionally remove theirs.
.wiki-page-header.has-sidebar-toggle
.wiki-page-header.has-sidebar-toggle
%button
.btn.btn-default.sidebar-toggle.js-sidebar-wiki-toggle
{
role:
"button"
,
type:
"button"
}
%button
.btn.btn-default.sidebar-toggle.js-sidebar-wiki-toggle
{
role:
"button"
,
type:
"button"
}
=
icon
(
'angle-double-left'
)
=
icon
(
'angle-double-left'
)
...
...
changelogs/unreleased/1827-prevent-concurrent-editing-wiki.yml
0 → 100644
View file @
a5521bad
---
title
:
Prevent concurrent editing wiki
merge_request
:
9707
author
:
Hiroyuki Sato
spec/features/projects/wiki/user_updates_wiki_page_spec.rb
View file @
a5521bad
...
@@ -8,7 +8,7 @@ feature 'Projects > Wiki > User updates wiki page', feature: true do
...
@@ -8,7 +8,7 @@ feature 'Projects > Wiki > User updates wiki page', feature: true do
login_as
(
user
)
login_as
(
user
)
visit
namespace_project_path
(
project
.
namespace
,
project
)
visit
namespace_project_path
(
project
.
namespace
,
project
)
WikiPages
::
CreateService
.
new
(
project
,
user
,
title:
'home'
,
content:
'Home page'
).
execute
@wiki_page
=
WikiPages
::
CreateService
.
new
(
project
,
user
,
title:
'home'
,
content:
'Home page'
).
execute
click_link
'Wiki'
click_link
'Wiki'
end
end
...
@@ -25,6 +25,16 @@ feature 'Projects > Wiki > User updates wiki page', feature: true do
...
@@ -25,6 +25,16 @@ feature 'Projects > Wiki > User updates wiki page', feature: true do
expect
(
page
).
to
have_content
(
"Last edited by
#{
user
.
name
}
"
)
expect
(
page
).
to
have_content
(
"Last edited by
#{
user
.
name
}
"
)
expect
(
page
).
to
have_content
(
'My awesome wiki!'
)
expect
(
page
).
to
have_content
(
'My awesome wiki!'
)
end
end
scenario
'page has been updated since the user opened the edit page'
do
click_link
'Edit'
@wiki_page
.
update
(
"Update"
)
click_button
'Save changes'
expect
(
page
).
to
have_content
'Someone edited the page the same time you did.'
end
end
end
context
'in a group namespace'
do
context
'in a group namespace'
do
...
...
spec/models/wiki_page_spec.rb
View file @
a5521bad
...
@@ -208,6 +208,20 @@ describe WikiPage, models: true do
...
@@ -208,6 +208,20 @@ describe WikiPage, models: true do
expect
(
@page
.
update
(
"more content"
)).
to
be_truthy
expect
(
@page
.
update
(
"more content"
)).
to
be_truthy
end
end
end
end
context
"with same last commit sha"
do
it
"returns true"
do
last_commit_sha
=
@page
.
commit
.
sha
expect
(
@page
.
update
(
"more content"
,
:markdown
,
nil
,
last_commit_sha
)).
to
be_truthy
end
end
context
"with different last commit sha"
do
it
"raises exception"
do
last_commit_sha
=
"xxx"
expect
{
@page
.
update
(
"more content"
,
:markdown
,
nil
,
last_commit_sha
)
}.
to
raise_error
(
WikiPage
::
PageChangedError
)
end
end
end
end
describe
"#destroy"
do
describe
"#destroy"
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment