Skip to content

Commit

Permalink
Place /stats routes behind login check, for performance reasons (publ…
Browse files Browse the repository at this point in the history
…iclab#9536)

* Place /stats routes behind login check, for performance reasons

await approval in publiclab#9002, but this is a pretty simple change!

* Update public_pages_test.rb

* Update stats_controller_test.rb

* Update stats_controller_test.rb

* fix failing tests

Co-authored-by: Cess <cessmbuguar@gmail.com>
  • Loading branch information
2 people authored and reginaalyssa committed Oct 16, 2021
1 parent 5e07fc7 commit 29989fe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class StatsController < ApplicationController
before_action :require_user, only: %i(index range notes wikis users questions comments tags)

def subscriptions
@tags = Rails.cache.fetch("stats-subscriptions-query", expires_in: 24.hours) do
TagSelection
Expand Down
7 changes: 7 additions & 0 deletions test/functional/stats_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ def setup
@start = 1.month.ago
@end = Date.today
@stats = [:notes, :comments, :users, :wikis, :questions, :answers, :tags, :node_tags]
activate_authlogic
end

test 'should assign correct value to graph_notes on GET stats' do
UserSession.create(users(:bob)) # we now require login for this page for load reasons
Node.delete_all
Node.create!(type: 'note', title:'blah', uid: 1, status: 1)
get :index, params: { start: @start.to_s, end: @end.to_s }
assert_kind_of Hash, Node.contribution_graph_making('note', @start.to_time, @end.to_time)
end

test 'should assign correct value to graph_wikis on GET stats' do
UserSession.create(users(:bob)) # we now require login for this page for load reasons
Node.delete_all
Node.create(type: 'note', title: 'blah', uid: 1, status: 1)
Node.create(type: 'page', title: 'blahblah', uid: 1, status: 1)
Expand All @@ -24,6 +27,7 @@ def setup
end

test 'should assign correct value to graph_comments on GET stats' do
UserSession.create(users(:bob)) # we now require login for this page for load reasons
Comment.delete_all
Comment.create!(comment: 'blah', timestamp: Time.now - 1)
get :index, params: { start: @start.to_s, end: @end.to_s }
Expand All @@ -32,6 +36,7 @@ def setup
end

test 'should load stats range query' do
UserSession.create(users(:bob)) # we now require login for this page for load reasons
get :index
assert_response :success
assert_not_nil assigns(:notes)
Expand All @@ -48,6 +53,7 @@ def setup
end

def csv_stats_download
UserSession.create(users(:bob)) # we now require login for this page for load reasons
@stats.each do |action|
test "should download #{action} as csv" do
get action, params: { format: 'csv' }
Expand All @@ -59,6 +65,7 @@ def csv_stats_download
end

def json_stats_downloads
UserSession.create(users(:bob)) # we now require login for this page for load reasons
@stats.each do |action|
test "should download #{action} as json" do
get action, params: { format: 'json' }
Expand Down
10 changes: 10 additions & 0 deletions test/integration/I18n_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,16 @@ class I18nTest < ActionDispatch::IntegrationTest
available_testing_locales.each do |lang|
get '/change_locale/' + lang.to_s
follow_redirect!

post '/user_sessions',
params: {
user_session: {
username: users(:jeff).username,
password: 'secretive'
}
}
follow_redirect!

start_time = 1.month.ago
end_time = Date.today
@graph_notes = Node.contribution_graph_making('note', start_time.to_time, end_time.to_time)
Expand Down
5 changes: 0 additions & 5 deletions test/integration/public_pages_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ def setup
assert_redirected_to '/search?q=foo'
end

test 'browse /stats' do
get '/stats'
assert_response :success
end

test 'browse redirected node' do
get nodes(:redirect).path
assert_response :redirect
Expand Down

0 comments on commit 29989fe

Please sign in to comment.