feat: 🎸 fetch maps on spam management dashboard (#1809)

This commit is contained in:
PeculiarE
2022-08-05 23:40:50 +01:00
committed by GitHub
parent 7ffc9accd4
commit b1b7e9c3f5
5 changed files with 72 additions and 0 deletions

View File

@@ -76,4 +76,9 @@ class ApplicationController < ActionController::Base
true
end
end
def paginate_results(results)
params[:limit] ||= 30
results.page(params[:page]).per_page(params[:limit].to_i)
end
end

View File

@@ -142,4 +142,17 @@ class SpamController < ApplicationController
flash[:notice] = helpers.pluralize(unbanned_authors, 'author') + ' unbanned.'
redirect_back(fallback_location: root_path)
end
def filter_maps
@maps = case params[:type]
when 'spammed'
paginate_results(Map.where(status: 0).order('updated_at DESC'))
when 'published'
paginate_results(Map.where(status: 1).order('updated_at DESC'))
when 'created'
paginate_results(Map.order('created_at DESC'))
else
paginate_results(Map.order('updated_at DESC'))
end
end
end

View File

@@ -135,6 +135,10 @@ Mapknitter::Application.routes.draw do
%w(batch_delete_maps).each do |action|
delete action + '/:ids', action: action, as: action
end
%w(filter_maps).each do |action|
get action + '/:type', action: action, as: action
end
end
# See how all your routes lay out with 'rails routes'

View File

@@ -491,4 +491,50 @@ class SpamControllerTest < ActionController::TestCase
assert_equal '0 authors unbanned.', flash[:notice]
assert_redirected_to root_path
end
test 'should filter maps and show only published maps' do
@map.spam
assert_equal Map::Status::BANNED, @map.status
assert_equal 'Saugus Landfill Incinerator', @map.name
session[:user_id] = 2
post(:filter_maps, params: { type: 'published' })
@maps = assigns(:maps)
assert_equal 5, Map.count
assert_equal 4, @maps.length
assert @maps.all? { |map| map.status == Map::Status::NORMAL }
assert @maps.collect(&:name).exclude?('Saugus Landfill Incinerator')
end
test 'should filter maps and show only spammed maps' do
@map.spam
session[:user_id] = 2
post(:filter_maps, params: { type: 'spammed' })
@maps = assigns(:maps)
assert_equal 5, Map.count
assert_equal 1, @maps.length
assert @maps.all? { |map| map.status == Map::Status::BANNED && map.name == 'Saugus Landfill Incinerator'}
end
test 'should show first 3 recently created maps' do
session[:user_id] = 2
post(:filter_maps, params: { type: 'created', limit: 3 })
@maps = assigns(:maps)
assert_equal 5, Map.count
assert_equal 3, @maps.length
end
test 'should show the most recently updated map' do
session[:user_id] = 2
post(:filter_maps, params: { type: 'updated', limit: 1 })
@maps = assigns(:maps)
assert_equal 5, Map.count
assert_equal 1, @maps.length
end
end

View File

@@ -37,4 +37,8 @@ class RoutesTest < ActionDispatch::IntegrationTest
test "test batch-unban-users route" do
assert_routing({ path: '/moderate/batch_unban_users/1,2', method: :patch }, { controller: 'spam', action: 'batch_unban_users', ids: '1,2' })
end
test "test filter-maps route" do
assert_routing({ path: '/moderate/filter_maps/created', method: :get }, { controller: 'spam', action: 'filter_maps', type: 'created' })
end
end