mirror of
https://github.com/neocities/neocities.git
synced 2026-05-29 18:32:32 +00:00
admin site lookup works for anything
This commit is contained in:
+17
-4
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user