mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
fix site unblocking
This commit is contained in:
parent
b54b2a4818
commit
6ea07df6a8
5 changed files with 39 additions and 13 deletions
|
@ -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
|
||||
|
||||
|
|
12
app/site.rb
12
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
|
|
@ -74,6 +74,9 @@ class Site < Sequel::Model
|
|||
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']
|
||||
THUMBNAIL_RESOLUTIONS = ['210x158']
|
||||
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -105,7 +105,7 @@
|
|||
<div class="report">
|
||||
<% if signed_in? %>
|
||||
<% if current_site && current_site.is_blocking?(site) %>
|
||||
<a href="#">Unblock</a>
|
||||
<a href="/site/<%= site.username %>/unblock">Unblock</a>
|
||||
<% else %>
|
||||
<a href="#block" data-toggle="modal">Block Site</a>
|
||||
<% end %>
|
||||
|
|
Loading…
Add table
Reference in a new issue