Skip to content

Commit

Permalink
Don't let newcomers edit wiki pages (controller-level) (publiclab#8250)
Browse files Browse the repository at this point in the history
* Don't let newcomers edit wiki pages (controller-level)

* Update wiki_controller.rb

* Update wiki_controller_test.rb

* Update wiki_controller_test.rb

* Update wiki_controller_test.rb

* Update wiki_controller_test.rb

* Update wiki_controller.rb

* Update wiki_controller.rb

* Update wiki_controller_test.rb

* Update wiki_controller_test.rb
  • Loading branch information
jywarren authored and reginaalyssa committed Oct 16, 2021
1 parent d0e8da6 commit f1531f1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/controllers/wiki_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ def edit
if @node.has_tag('locked') && !current_user.can_moderate?
flash[:warning] = "This page is <a href='/wiki/power-tags#Locking'>locked</a>, and only <a href='/wiki/moderators'>moderators</a> can edit it."
redirect_to @node.path
elsif current_user &.first_time_poster
flash[:notice] = "Please post a question or other content before editing the wiki. Click <a href='https://publiclab.org/notes/tester/04-23-2016/new-moderation-system-for-first-time-posters'>here</a> to learn why."
redirect_to Node.find_wiki(params[:id]).path
return
end
if ((Time.now.to_i - @node.latest.timestamp) < 5.minutes.to_i) && @node.latest.author.uid != current_user.uid
flash.now[:warning] = I18n.t('wiki_controller.someone_clicked_edit_5_minutes_ago')
Expand Down
18 changes: 17 additions & 1 deletion test/functional/wiki_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,33 @@ def teardown
end

test 'viewing edit wiki page' do
UserSession.find.destroy if UserSession.find
UserSession.create(users(:jeff)) # jeff user fixture is not a first-time-poster

get :edit,
params: {
id: 'organizers'
}

assert_not users(:jeff).first_time_poster
assert_response :success
assert_template 'wiki/edit'
assert_not_nil assigns(:title)
assert_not_nil assigns(:node)
assert_response :success
end

test 'disallow viewing edit wiki page for first-timers' do
# default bob user fixure is a first-time-poster
assert users(:bob).first_time_poster
get :edit,
params: {
id: 'chicago'
}

assert_equal flash[:notice], "Please post a question or other content before editing the wiki. Click <a href='https://publiclab.org/notes/tester/04-23-2016/new-moderation-system-for-first-time-posters'>here</a> to learn why."
assert_redirected_to nodes(:place).path
end

test 'updating wiki' do
wiki = nodes(:organizers)
newtitle = 'New Title'
Expand Down

0 comments on commit f1531f1

Please sign in to comment.