fix site unblocking

This commit is contained in:
Kyle Drake 2022-11-12 13:07:49 -06:00
parent d1ab1d2292
commit 8d1c97d604
5 changed files with 39 additions and 13 deletions

View file

@ -68,28 +68,28 @@ def browse_sites_dataset
ds = ds.exclude featured_at: nil ds = ds.exclude featured_at: nil
ds = ds.order :featured_at.desc ds = ds.order :featured_at.desc
when 'hits' when 'hits'
ds = ds.where{views > 100} ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS}
ds = ds.order(:hits.desc, :site_updated_at.desc) ds = ds.order(:hits.desc, :site_updated_at.desc)
when 'views' when 'views'
ds = ds.where{views > 100} ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS}
ds = ds.order(:views.desc, :site_updated_at.desc) ds = ds.order(:views.desc, :site_updated_at.desc)
when 'newest' when 'newest'
ds = ds.order(:created_at.desc, :views.desc) ds = ds.order(:created_at.desc, :views.desc)
when 'oldest' when 'oldest'
ds = ds.where{views > 100} ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS}
ds = ds.order(:created_at, :views.desc) ds = ds.order(:created_at, :views.desc)
when 'random' when 'random'
ds = ds.where{views > 100} ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS}
ds = ds.where 'random() < 0.01' ds = ds.where 'random() < 0.01'
when 'last_updated' when 'last_updated'
ds = ds.where{views > 100} ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS}
params[:sort_by] = 'last_updated' params[:sort_by] = 'last_updated'
ds = ds.exclude(site_updated_at: nil) ds = ds.exclude(site_updated_at: nil)
ds = ds.order(:site_updated_at.desc, :views.desc) ds = ds.order(:site_updated_at.desc, :views.desc)
when 'tipping_enabled' when 'tipping_enabled'
ds = ds.where tipping_enabled: true ds = ds.where tipping_enabled: true
ds = ds.where("(tipping_paypal is not null and tipping_paypal != '') or (tipping_bitcoin is not null and tipping_bitcoin != '')") ds = ds.where("(tipping_paypal is not null and tipping_paypal != '') or (tipping_bitcoin is not null and tipping_bitcoin != '')")
ds = ds.where{views > 10_000} ds = ds.where{views > Site::BROWSE_MINIMUM_FOLLOWER_VIEWS}
ds = ds.group :sites__id ds = ds.group :sites__id
ds = ds.order :follow_count.desc, :views.desc, :updated_at.desc ds = ds.order :follow_count.desc, :views.desc, :updated_at.desc
when 'blocks' when 'blocks'
@ -100,7 +100,7 @@ def browse_sites_dataset
ds = ds.order :total.desc ds = ds.order :total.desc
else else
params[:sort_by] = 'followers' params[:sort_by] = 'followers'
ds = ds.where{views > 10_000} ds = ds.where{views > Site::BROWSE_MINIMUM_FOLLOWER_VIEWS}
ds = ds.order :follow_count.desc, :views.desc, :updated_at.desc ds = ds.order :follow_count.desc, :views.desc, :updated_at.desc
end end

View file

@ -284,3 +284,15 @@ post '/site/:username/block' do |username|
redirect request.referer redirect request.referer
end end
end end
get '/site/:username/unblock' do |username|
require_login
site = Site[username: username]
if site.nil? || current_site.id == site.id
redirect request.referer
end
current_site.unblock! site
redirect request.referer
end

View file

@ -73,6 +73,9 @@ class Site < Sequel::Model
ROOT_INDEX_HTML_REGEX = /^\/?index.html$/ ROOT_INDEX_HTML_REGEX = /^\/?index.html$/
MAX_COMMENT_SIZE = 420 # Used to be the limit for Facebook.. no comment (PUN NOT INTENDED). MAX_COMMENT_SIZE = 420 # Used to be the limit for Facebook.. no comment (PUN NOT INTENDED).
MAX_FOLLOWS = 1000 MAX_FOLLOWS = 1000
BROWSE_MINIMUM_VIEWS = 100
BROWSE_MINIMUM_FOLLOWER_VIEWS = 10_000
SCREENSHOT_DELAY_SECONDS = 30 SCREENSHOT_DELAY_SECONDS = 30
SCREENSHOT_RESOLUTIONS = ['540x405', '210x158', '100x100', '50x50'] SCREENSHOT_RESOLUTIONS = ['540x405', '210x158', '100x100', '50x50']
@ -629,6 +632,12 @@ class Site < Sequel::Model
add_blocking site: site add_blocking site: site
end end
def unblock!(site)
block = blockings_dataset.filter(site_id: site.id).first
return true if block.nil?
block.destroy
end
def is_blocking?(site) def is_blocking?(site)
@blockings ||= blockings @blockings ||= blockings
!@blockings.select {|b| b.site_id == site.id}.empty? !@blockings.select {|b| b.site_id == site.id}.empty?

View file

@ -63,11 +63,10 @@ describe 'site page' do
_(page).must_have_content /#{site.username}/ _(page).must_have_content /#{site.username}/
end end
=begin
it 'allows site blocking' do it 'allows site blocking and unblocking' do
Capybara.default_driver = :poltergeist
tag = SecureRandom.hex 10 tag = SecureRandom.hex 10
blocked_site = Fabricate :site, new_tags_string: tag, created_at: 2.weeks.ago, site_changed: true blocked_site = Fabricate :site, new_tags_string: tag, created_at: 2.weeks.ago, site_changed: true, views: Site::BROWSE_MINIMUM_FOLLOWER_VIEWS+1
site = Fabricate :site site = Fabricate :site
page.set_rack_session id: site.id page.set_rack_session id: site.id
@ -88,8 +87,14 @@ describe 'site page' do
site.reload site.reload
_(site.blockings.length).must_equal 1 _(site.blockings.length).must_equal 1
_(site.blockings.first.site_id).must_equal blocked_site.id _(site.blockings.first.site_id).must_equal blocked_site.id
visit "/site/#{blocked_site.username}"
click_link 'Unblock'
visit "/browse?tag=#{tag}"
_(page.find('.website-Gallery .username a')['href']).must_match /\/site\/#{blocked_site.username}/
end end
=end
it '404s if site is banned' do it '404s if site is banned' do
site = Fabricate :site site = Fabricate :site

View file

@ -105,7 +105,7 @@
<div class="report"> <div class="report">
<% if signed_in? %> <% if signed_in? %>
<% if current_site && current_site.is_blocking?(site) %> <% if current_site && current_site.is_blocking?(site) %>
<a href="#">Unblock</a> <a href="/site/<%= site.username %>/unblock">Unblock</a>
<% else %> <% else %>
<a href="#block" data-toggle="modal">Block Site</a> <a href="#block" data-toggle="modal">Block Site</a>
<% end %> <% end %>