admin site lookup works for anything

This commit is contained in:
Kyle Drake
2025-12-03 13:10:50 -06:00
parent 0402afafa0
commit 9d0415ad3e
2 changed files with 40 additions and 4 deletions
+17 -4
View File
@@ -404,19 +404,32 @@ get '/admin/masquerade/:username' do
redirect '/'
end
get '/admin/site/:username_or_email_or_domain' do
get %r{/admin/site/(.+)} do |username_or_email_or_domain|
require_admin
ident = params[:username_or_email_or_domain]
ident = request.path_info.sub(%r{\A/admin/site/}, '')
if ident.blank?
flash[:error] = 'username or email or domain required'
redirect '/admin'
end
ident = ident.to_s.strip
ident = ident.sub(%r{\A(https?):/+}, '\1://')
begin
parsed_ident = Addressable::URI.parse(ident)
ident = parsed_ident.host if parsed_ident.host
rescue Addressable::URI::InvalidURIError
end
ident = ident.split('/').first.to_s.downcase
if ident =~ /@/
@site = Site[email: ident]
elsif ident.end_with?('.neocities.org')
@site = Site[username: ident.sub(/\.neocities\.org\z/, '')]
elsif ident =~ /.+\..+$/
@site = Site.where(domain: ident.downcase).first
@site = Site.where(domain: ident).first
else
@site = Site[username: ident]
end
@@ -429,4 +442,4 @@ get '/admin/site/:username_or_email_or_domain' do
@title = "Site Info - #{@site.username}"
erb :'admin/site'
end
end
+23
View File
@@ -201,6 +201,29 @@ describe '/admin' do
end
end
describe 'site info lookup' do
include Capybara::DSL
it 'finds sites by username, email, domain, and urls' do
username_site = Fabricate :site, username: 'plainuser'
email_site = Fabricate :site, username: 'emailuser', email: 'user@gmail.com'
domain_site = Fabricate :site, username: 'domainsite', domain: 'domain.com'
neocities_site = Fabricate :site, username: 'derp'
[
['plainuser', username_site.username],
['user@gmail.com', email_site.username],
['derp.neocities.org', neocities_site.username],
['domain.com', domain_site.username],
['https://domain.com/some/path', domain_site.username],
['https://derp.neocities.org/anything', neocities_site.username]
].each do |input, expected_username|
visit "/admin/site/#{input}"
_(page.body).must_match(/Site Info: #{Regexp.quote(expected_username)}/, "input #{input} current_path #{page.current_path}")
end
end
end
describe 'email blasting' do
before do
EmailWorker.jobs.clear