mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
limit on comments per day to prevent spam
This commit is contained in:
parent
92abcd6a49
commit
d220d73b0c
2 changed files with 17 additions and 1 deletions
|
@ -164,6 +164,8 @@ class Site < Sequel::Model
|
||||||
|
|
||||||
MAXIMUM_EMAIL_CONFIRMATIONS = 20
|
MAXIMUM_EMAIL_CONFIRMATIONS = 20
|
||||||
|
|
||||||
|
MAX_COMMENTS_PER_DAY = 10
|
||||||
|
|
||||||
many_to_many :tags
|
many_to_many :tags
|
||||||
|
|
||||||
one_to_many :profile_comments
|
one_to_many :profile_comments
|
||||||
|
@ -503,6 +505,8 @@ class Site < Sequel::Model
|
||||||
set commenting_allowed: true
|
set commenting_allowed: true
|
||||||
save_changes validate: false
|
save_changes validate: false
|
||||||
return true
|
return true
|
||||||
|
else
|
||||||
|
return false if owner.commenting_too_much?
|
||||||
end
|
end
|
||||||
|
|
||||||
if (account_sites_events_dataset.exclude(site_change_id: nil).count >= COMMENTING_ALLOWED_UPDATED_COUNT || (created_at < Date.new(2014, 12, 25).to_time && changed_count >= COMMENTING_ALLOWED_UPDATED_COUNT )) &&
|
if (account_sites_events_dataset.exclude(site_change_id: nil).count >= COMMENTING_ALLOWED_UPDATED_COUNT || (created_at < Date.new(2014, 12, 25).to_time && changed_count >= COMMENTING_ALLOWED_UPDATED_COUNT )) &&
|
||||||
|
@ -515,6 +519,14 @@ class Site < Sequel::Model
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def commenting_too_much?
|
||||||
|
recent_comments = Comment.where(actioning_site_id: owner.id).where{created_at > 24.hours.ago}.count
|
||||||
|
recent_profile_comments = owner.profile_commentings_dataset.where{created_at > 24.hours.ago}.count
|
||||||
|
|
||||||
|
return true if (recent_comments + recent_profile_comments) > MAX_COMMENTS_PER_DAY
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
def blocking_site_ids
|
def blocking_site_ids
|
||||||
@blocking_site_ids ||= blockings_dataset.select(:site_id).all.collect {|s| s.site_id}
|
@blocking_site_ids ||= blockings_dataset.select(:site_id).all.collect {|s| s.site_id}
|
||||||
end
|
end
|
||||||
|
|
|
@ -83,7 +83,11 @@
|
||||||
|
|
||||||
<% unless current_site.commenting_allowed? %>
|
<% unless current_site.commenting_allowed? %>
|
||||||
<p class="comment-policy">
|
<p class="comment-policy">
|
||||||
|
<% if current_site.commenting_too_much? %>
|
||||||
|
To prevent spam, we have a <%= Site::MAX_COMMENTS_PER_DAY %> comment per day limit. Please try commenting again tomorrow!
|
||||||
|
<% else %>
|
||||||
To prevent spam, you cannot comment until you have updated your site <strong><%= Site::COMMENTING_ALLOWED_UPDATED_COUNT %> times</strong> (on <%= Site::COMMENTING_ALLOWED_UPDATED_COUNT %> separate days), and your account is one week old. While waiting, now is a great time to <a href="/dashboard">start building your awesome site!</a>
|
To prevent spam, you cannot comment until you have updated your site <strong><%= Site::COMMENTING_ALLOWED_UPDATED_COUNT %> times</strong> (on <%= Site::COMMENTING_ALLOWED_UPDATED_COUNT %> separate days), and your account is one week old. While waiting, now is a great time to <a href="/dashboard">start building your awesome site!</a>
|
||||||
|
<% end %>
|
||||||
</p>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue