diff --git a/app/browse.rb b/app/browse.rb index 54113d5b..d24d686c 100644 --- a/app/browse.rb +++ b/app/browse.rb @@ -68,28 +68,28 @@ def browse_sites_dataset ds = ds.exclude featured_at: nil ds = ds.order :featured_at.desc when 'hits' - ds = ds.where{views > 100} + ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS} ds = ds.order(:hits.desc, :site_updated_at.desc) when 'views' - ds = ds.where{views > 100} + ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS} ds = ds.order(:views.desc, :site_updated_at.desc) when 'newest' ds = ds.order(:created_at.desc, :views.desc) when 'oldest' - ds = ds.where{views > 100} + ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS} ds = ds.order(:created_at, :views.desc) when 'random' - ds = ds.where{views > 100} + ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS} ds = ds.where 'random() < 0.01' when 'last_updated' - ds = ds.where{views > 100} + ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS} params[:sort_by] = 'last_updated' ds = ds.exclude(site_updated_at: nil) ds = ds.order(:site_updated_at.desc, :views.desc) when 'tipping_enabled' 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{views > 10_000} + ds = ds.where{views > Site::BROWSE_MINIMUM_FOLLOWER_VIEWS} ds = ds.group :sites__id ds = ds.order :follow_count.desc, :views.desc, :updated_at.desc when 'blocks' @@ -100,7 +100,7 @@ def browse_sites_dataset ds = ds.order :total.desc else 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 end diff --git a/app/site.rb b/app/site.rb index 2537155c..18e2ce89 100644 --- a/app/site.rb +++ b/app/site.rb @@ -284,3 +284,15 @@ post '/site/:username/block' do |username| redirect request.referer 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 \ No newline at end of file diff --git a/models/site.rb b/models/site.rb index 55b8d85a..d96eb4a5 100644 --- a/models/site.rb +++ b/models/site.rb @@ -73,6 +73,9 @@ class Site < Sequel::Model ROOT_INDEX_HTML_REGEX = /^\/?index.html$/ MAX_COMMENT_SIZE = 420 # Used to be the limit for Facebook.. no comment (PUN NOT INTENDED). MAX_FOLLOWS = 1000 + + BROWSE_MINIMUM_VIEWS = 100 + BROWSE_MINIMUM_FOLLOWER_VIEWS = 10_000 SCREENSHOT_DELAY_SECONDS = 30 SCREENSHOT_RESOLUTIONS = ['540x405', '210x158', '100x100', '50x50'] @@ -629,6 +632,12 @@ class Site < Sequel::Model add_blocking site: site 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) @blockings ||= blockings !@blockings.select {|b| b.site_id == site.id}.empty? diff --git a/tests/acceptance/site_tests.rb b/tests/acceptance/site_tests.rb index 1368fa2b..1656ddb4 100644 --- a/tests/acceptance/site_tests.rb +++ b/tests/acceptance/site_tests.rb @@ -63,11 +63,10 @@ describe 'site page' do _(page).must_have_content /#{site.username}/ end -=begin - it 'allows site blocking' do - Capybara.default_driver = :poltergeist + + it 'allows site blocking and unblocking' do 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 page.set_rack_session id: site.id @@ -88,8 +87,14 @@ describe 'site page' do site.reload _(site.blockings.length).must_equal 1 _(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 it '404s if site is banned' do site = Fabricate :site diff --git a/views/site.erb b/views/site.erb index d2259eeb..b8df7627 100644 --- a/views/site.erb +++ b/views/site.erb @@ -105,7 +105,7 @@
<% if signed_in? %> <% if current_site && current_site.is_blocking?(site) %> - Unblock + Unblock <% else %> Block Site <% end %>