Skip to content

Commit

Permalink
Added test to block normal user from updating wiki, fixes #397 (#1155)
Browse files Browse the repository at this point in the history
* Test to block normal user from updating wiki

* Update wiki_controller_test.rb
  • Loading branch information
500swapnil authored and jywarren committed Jan 3, 2017
1 parent 940286e commit ecabc0a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/controllers/wiki_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ def update
title: params[:title],
body: params[:body]
})
if @revision.valid?
if @node.has_tag('locked') && (current_user.role != "admin" && current_user.role != "moderator")
flash[:warning] = "This page is <a href='/wiki/power-tags#Locking'>locked</a>, and only <a href='/wiki/moderators'>moderators</a> can update it."
redirect_to @node.path

elsif @revision.valid?
ActiveRecord::Base.transaction do
@revision.save
@node.vid = @revision.vid
Expand Down
10 changes: 10 additions & 0 deletions test/functional/wiki_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ def teardown
assert_redirected_to node(:organizers).path
end

test "basic user blocked from updating a locked wiki page" do
node(:organizers).add_tag('locked', rusers(:admin)) # lock the page with a tag
# then try editing it
assert_difference 'DrupalNodeRevision.count', 0 do
post :update,
id: 'organizers'
end
assert_equal flash[:warning] , "This page is <a href='/wiki/power-tags#Locking'>locked</a>, and only <a href='/wiki/moderators'>moderators</a> can update it."
assert_redirected_to node(:organizers).path
end

test "updating wiki with bad title" do

Expand Down

0 comments on commit ecabc0a

Please sign in to comment.