From e554666fc599d207fc03291c48873beff01bd949 Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Sun, 27 Nov 2016 19:19:28 -0600 Subject: [PATCH] better tos issue reporting, and a threshold for being considered abusive in comments --- .gitignore | 1 + app/event.rb | 5 +++-- app/site.rb | 5 +++-- models/site.rb | 10 ++++++++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 6a1cc1be..3a14f421 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ files/disposable_email_blacklist.conf files/letsencrypt.key files/tor.txt .bundle +ext/black_box.rb diff --git a/app/event.rb b/app/event.rb index 3247c9e6..ef8c1090 100644 --- a/app/event.rb +++ b/app/event.rb @@ -13,9 +13,10 @@ post '/event/:event_id/comment' do |event_id| site = event.site - if site.is_blocking?(current_site) || + if(site.is_blocking?(current_site) || site.profile_comments_enabled == false || - current_site.commenting_allowed? == false + current_site.commenting_allowed? == false || + (current_site.is_a_jerk? && event.site_id != current_site.id && !site.is_following?(current_site))) return {result: 'error'}.to_json end diff --git a/app/site.rb b/app/site.rb index 91f88ec7..c3f378f1 100644 --- a/app/site.rb +++ b/app/site.rb @@ -129,11 +129,12 @@ post '/site/:username/comment' do |username| site = Site[username: username] - if(site.profile_comments_enabled == false || + if site.profile_comments_enabled == false || params[:message].empty? || site.is_blocking?(current_site) || current_site.is_blocking?(site) || - current_site.commenting_allowed? == false) + current_site.commenting_allowed? == false || + (current_site.is_a_jerk? && site.id != current_site.id && !site.is_following?(current_site)) redirect request.referrer end diff --git a/models/site.rb b/models/site.rb index 810de209..9e94262f 100644 --- a/models/site.rb +++ b/models/site.rb @@ -124,6 +124,8 @@ class Site < Sequel::Model EMAIL_VALIDATION_CUTOFF_DATE = Time.parse('May 16, 2016') DISPOSABLE_EMAIL_BLACKLIST_PATH = File.join(DIR_ROOT, 'files', 'disposable_email_blacklist.conf') + BLOCK_JERK_THRESHOLD = 3 + def self.newsletter_sites Site.select(:email). exclude(email: 'nil').exclude(is_banned: true). @@ -522,6 +524,10 @@ class Site < Sequel::Model false end + def is_a_jerk? + blocks_dataset.count >= BLOCK_JERK_THRESHOLD + end + def blocking_site_ids @blocking_site_ids ||= blockings_dataset.select(:site_id).all.collect {|s| s.site_id} end @@ -1468,8 +1474,8 @@ class Site < Sequel::Model return false end - if pathname.extname.match HTML_REGEX - # SPAM and phishing checking code goes here + if pathname.extname.match(HTML_REGEX) && defined?(BlackBox) + BlackBox.tos_violation_check self, uploaded end relative_path_dir = Pathname(relative_path).dirname