diff --git a/app.rb b/app.rb index e4d95256..bd290661 100644 --- a/app.rb +++ b/app.rb @@ -122,9 +122,12 @@ post '/site/:username/comment' do |username| require_login site = Site[username: username] - redirect request.referrer if site.profile_comments_enabled == false - if params[:message].empty? || (site.is_blocking?(current_site) || current_site.is_blocking?(site)) + if(site.profile_comments_enabled == false || + params[:message].empty? || + site.is_blocking?(current_site) || + current_site.is_blocking?(site) || + current_site.commenting_allowed? == false) redirect "/site/#{username}" end @@ -1191,8 +1194,11 @@ post '/event/:event_id/comment' do |event_id| site = event.site - return {result: 'error'}.to_json if site.is_blocking?(current_site) - return {result: 'error'}.to_json if site.profile_comments_enabled == false + if site.is_blocking?(current_site) || + site.profile_comments_enabled == false || + current_site.commenting_allowed? == false + return {result: 'error'}.to_json + end event.add_site_comment current_site, params[:message] {result: 'success'}.to_json diff --git a/migrations/043_add_commenting_allowed_flag.rb b/migrations/043_add_commenting_allowed_flag.rb new file mode 100644 index 00000000..88d0738e --- /dev/null +++ b/migrations/043_add_commenting_allowed_flag.rb @@ -0,0 +1,9 @@ +Sequel.migration do + up { + DB.add_column :sites, :commenting_allowed, :boolean, default: false + } + + down { + DB.drop_column :sites, :commenting_allowed + } +end \ No newline at end of file diff --git a/models/site.rb b/models/site.rb index cb66080f..cfe2799f 100644 --- a/models/site.rb +++ b/models/site.rb @@ -71,15 +71,13 @@ class Site < Sequel::Model ] SPAM_MATCH_REGEX = ENV['RACK_ENV'] == 'test' ? /pillz/ : /#{$config['spam_smart_filter'].join('|')}/i - EMAIL_SANITY_REGEX = /.+@.+\..+/i - EDITABLE_FILE_EXT = /html|htm|txt|js|css|md/i - BANNED_TIME = 2592000 # 30 days in seconds - TITLE_MAX = 100 + COMMENTING_ALLOWED_UPDATED_COUNT = 2 + many_to_one :server many_to_many :tags @@ -280,6 +278,19 @@ class Site < Sequel::Model end =end + def commenting_allowed? + return true if commenting_allowed + + if events_dataset.exclude(site_change_id: nil).count >= COMMENTING_ALLOWED_UPDATED_COUNT && + created_at < Time.now - 604800 + set commenting_allowed: true + save_changes validate: false + return true + end + + false + end + def blocking_site_ids @blocking_site_ids ||= blockings_dataset.select(:site_id).all.collect {|s| s.site_id} end diff --git a/views/_news.erb b/views/_news.erb index a9de6811..bbc7ea64 100644 --- a/views/_news.erb +++ b/views/_news.erb @@ -22,7 +22,7 @@ <% event_site = event.site_dataset.select(:id, :username, :title, :domain).first %> <%= actioning_site.title.shorten(40) %> is following - <% if event_site.id == current_site.id %> + <% if current_site && event_site.id == current_site.id %> your site! <% else %> <%= event_site.title.shorten(40) %> @@ -36,7 +36,7 @@
+
+ Note: To prevent spam, you cannot comment until you have updated your site <%= Site::COMMENTING_ALLOWED_UPDATED_COUNT %> times (on <%= Site::COMMENTING_ALLOWED_UPDATED_COUNT %> separate days),
and your account is one week old. While waiting, now is a great time to start building your awesome site!
+
+