restrict comments for new users that haven't updated their site

This commit is contained in:
Kyle Drake 2014-09-05 22:23:23 -07:00
parent 305bb71aa3
commit 96e277c331
6 changed files with 63 additions and 18 deletions

View file

@ -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