mirror of
https://github.com/publiclab/mapknitter.git
synced 2025-12-05 16:00:00 +01:00
feat: 🎸 fetch maps on spam management dashboard (#1809)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user