mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
blocking, tag fixes
This commit is contained in:
parent
e546b22797
commit
447f654435
5 changed files with 125 additions and 13 deletions
55
app.rb
55
app.rb
|
@ -75,25 +75,30 @@ get '/profile_mockup' do
|
|||
erb :'profile_mockup', locals: {site: current_site}
|
||||
end
|
||||
|
||||
get '/site/:sitename.rss' do |sitename|
|
||||
site = Site[username: sitename]
|
||||
get '/site/:username.rss' do |username|
|
||||
site = Site[username: username]
|
||||
content_type :xml
|
||||
site.to_rss.to_xml
|
||||
end
|
||||
|
||||
get '/site/:sitename' do |sitename|
|
||||
site = Site[username: sitename]
|
||||
not_found if(site.nil?)
|
||||
@title = "#{sitename}.neocities.org"
|
||||
get '/site/:username' do |username|
|
||||
site = Site[username: username]
|
||||
not_found if site.nil?
|
||||
if current_site && (site.is_blocking?(current_site) || current_site.is_blocking?(site))
|
||||
not_found
|
||||
end
|
||||
@title = site.title
|
||||
erb :'site', locals: {site: site, is_current_site: site == current_site}
|
||||
end
|
||||
|
||||
post '/site/:sitename/comment' do |sitename|
|
||||
post '/site/:username/comment' do |username|
|
||||
require_login
|
||||
|
||||
redirect "/site/#{sitename}" if params[:message].empty?
|
||||
site = Site[username: username]
|
||||
|
||||
site = Site[username: sitename]
|
||||
if params[:message].empty? || (site.is_blocking?(current_site) || current_site.is_blocking?(site))
|
||||
redirect "/site/#{username}"
|
||||
end
|
||||
|
||||
DB.transaction do
|
||||
site.add_profile_comment(
|
||||
|
@ -102,7 +107,7 @@ post '/site/:sitename/comment' do |sitename|
|
|||
)
|
||||
end
|
||||
|
||||
redirect "/site/#{sitename}"
|
||||
redirect "/site/#{username}"
|
||||
end
|
||||
|
||||
get '/browse_mockup' do
|
||||
|
@ -249,6 +254,18 @@ get '/browse' do
|
|||
|
||||
site_dataset = Site.filter(is_banned: false, is_crashing: false).filter(site_changed: true).paginate(@current_page, 300)
|
||||
|
||||
if current_site
|
||||
if !current_site.blocking_site_ids.empty?
|
||||
site_dataset.where!(Sequel.~(Sequel.qualify(:sites, :id) => current_site.blocking_site_ids))
|
||||
end
|
||||
|
||||
if current_site.blocks_dataset.count
|
||||
site_dataset.where!(
|
||||
Sequel.~(Sequel.qualify(:sites, :id) => current_site.blocks_dataset.select(:actioning_site_id).all.collect {|s| s.actioning_site_id})
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
case params[:sort_by]
|
||||
when 'hits'
|
||||
site_dataset.order!(:hits.desc)
|
||||
|
@ -915,6 +932,9 @@ post '/event/:event_id/comment' do |event_id|
|
|||
require_login
|
||||
content_type :json
|
||||
event = Event[id: event_id]
|
||||
|
||||
return {result: 'error'}.to_json if event.site.is_blocking?(current_site)
|
||||
|
||||
event.add_site_comment current_site, params[:message]
|
||||
{result: 'success'}.to_json
|
||||
end
|
||||
|
@ -971,6 +991,7 @@ post '/site/:username/report' do |username|
|
|||
report = Report.new site_id: site.id, type: params[:type], comments: params[:comments]
|
||||
|
||||
if current_site
|
||||
redirect request.referer if current_site.id == site.id
|
||||
report.reporting_site_id = current_site.id
|
||||
else
|
||||
report.ip = request.ip
|
||||
|
@ -988,6 +1009,20 @@ post '/site/:username/report' do |username|
|
|||
redirect request.referer
|
||||
end
|
||||
|
||||
post '/site/:username/block' do |username|
|
||||
require_login
|
||||
site = Site[username: username]
|
||||
redirect request.referer if current_site.id == site.id
|
||||
|
||||
current_site.block! site
|
||||
|
||||
if request.referer.match /\/site\/#{username}/i
|
||||
redirect '/'
|
||||
else
|
||||
redirect request.referer
|
||||
end
|
||||
end
|
||||
|
||||
def require_admin
|
||||
redirect '/' unless signed_in? && current_site.is_admin
|
||||
end
|
||||
|
|
|
@ -58,6 +58,7 @@ class Site < Sequel::Model
|
|||
|
||||
SCREENSHOT_RESOLUTIONS = ['235x141', '105x63', '270x162', '37x37', '146x88', '302x182', '90x63', '82x62', '348x205']
|
||||
THUMBNAIL_RESOLUTIONS = ['105x63', '90x63']
|
||||
TAG_LENGTH_MAX = 25
|
||||
|
||||
many_to_one :server
|
||||
|
||||
|
@ -195,6 +196,37 @@ class Site < Sequel::Model
|
|||
}
|
||||
end
|
||||
|
||||
def follows_dataset
|
||||
super.where(Sequel.~(site_id: blocking_site_ids))
|
||||
.where(Sequel.~(actioning_site_id: blocking_site_ids))
|
||||
end
|
||||
|
||||
def followings_dataset
|
||||
super.where(Sequel.~(site_id: blocking_site_ids))
|
||||
.where(Sequel.~(actioning_site_id: blocking_site_ids))
|
||||
end
|
||||
|
||||
def events_dataset
|
||||
super.where(Sequel.~(site_id: blocking_site_ids))
|
||||
.where(Sequel.~(actioning_site_id: blocking_site_ids))
|
||||
end
|
||||
|
||||
def blocking_site_ids
|
||||
@blocking_site_ids ||= blockings_dataset.select(:site_id).all.collect {|s| s.site_id}
|
||||
end
|
||||
|
||||
def block!(site)
|
||||
block = blockings_dataset.filter(site_id: site.id).first
|
||||
DB.transaction do
|
||||
add_blocking site: site
|
||||
end
|
||||
end
|
||||
|
||||
def is_blocking?(site)
|
||||
@blockings ||= blockings
|
||||
!@blockings.select {|b| b.site_id == site.id}.empty?
|
||||
end
|
||||
|
||||
def self.valid_filename?(filename)
|
||||
return false if sanitize_filename(filename) != filename
|
||||
true
|
||||
|
@ -370,12 +402,17 @@ class Site < Sequel::Model
|
|||
break
|
||||
end
|
||||
|
||||
if tag.length > Tag::NAME_LENGTH_MAX
|
||||
errors.add :tags, "Tag \"#{tag}\" cannot be longer than #{Tag::NAME_LENGTH_MAX} characters."
|
||||
break
|
||||
end
|
||||
|
||||
if tag.match(/ /)
|
||||
errors.add :tags, "Tag \"#{tag}\" cannot have more than one space between words."
|
||||
break
|
||||
end
|
||||
|
||||
if tag.split(' ').length > 2
|
||||
if tag.split(' ').length > Tag::NAME_WORDS_MAX
|
||||
errors.add :tags, "Tag \"#{tag}\" cannot be more than two words."
|
||||
break
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class Tag < Sequel::Model
|
||||
NAME_LENGTH_MAX = 25
|
||||
NAME_WORDS_MAX = 2
|
||||
many_to_many :sites
|
||||
|
||||
def before_create
|
||||
|
|
|
@ -113,6 +113,13 @@ describe 'signup' do
|
|||
page.must_have_content /Tag.+cannot be more than two words/
|
||||
end
|
||||
|
||||
it "fails for tag longer than #{Tag::NAME_LENGTH_MAX} characters" do
|
||||
fill_in_valid
|
||||
fill_in 'tags', with: 'helloiamareallylongtagfornoreason lolthisisridiculous'
|
||||
click_button 'Create Home Page'
|
||||
page.must_have_content /cannot be longer than #{Tag::NAME_LENGTH_MAX}/
|
||||
end
|
||||
|
||||
it 'fails for too many tags' do
|
||||
fill_in_valid
|
||||
fill_in 'tags', with: 'one, two, three, four, five, six'
|
||||
|
|
|
@ -104,7 +104,12 @@
|
|||
|
||||
<% if site != current_site %>
|
||||
<div class="report">
|
||||
<a href="#report" data-toggle="modal">Report</a> | <a href="">Block</a>
|
||||
<a href="#report" data-toggle="modal">Report</a> |
|
||||
<% if current_site.is_blocking?(site) %>
|
||||
<a href="#">Unblock</a>
|
||||
<% else %>
|
||||
<a href="#block" data-toggle="modal">Block</a>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
@ -116,7 +121,7 @@
|
|||
<input type="hidden" value="<%= csrf_token %>" name="csrf_token">
|
||||
<div class="modal-header">
|
||||
<button class="close" type="button" data-dismiss="modal" aria-hidden="true">x</button>
|
||||
<h3 id="removeTagLabel">Report Site</h3>
|
||||
<h3 id="reportLabel">Report Site</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>
|
||||
|
@ -139,3 +144,29 @@
|
|||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="modal hide fade" id="block" tabindex="-1" role="dialog" aria-labelledby="blockLabel" aria-hidden="true">
|
||||
<form method="POST" action="/site/<%= site.username %>/block">
|
||||
<input type="hidden" value="<%= csrf_token %>" name="csrf_token">
|
||||
<div class="modal-header">
|
||||
<button class="close" type="button" data-dismiss="modal" aria-hidden="true">x</button>
|
||||
<h3 id="blockLabel">Block Site</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>You are going to block this site. This will do the following:</p>
|
||||
|
||||
<ul>
|
||||
<li>You will no longer see this site in searches.</li>
|
||||
<li>Site will no longer see your site in searches.</li>
|
||||
<li>Site will not be able to comment on your site profile.</li>
|
||||
<li>Any comments this site has posted to your profile will not be displayed.</li>
|
||||
</ul>
|
||||
|
||||
<p>Are you sure you want to do this?</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
|
||||
<button type="submit" class="btn btn-Action">Block Site</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
Loading…
Add table
Reference in a new issue