prevent users with much negative karma from submitting new stories
This commit is contained in:
parent
ac3347b9cc
commit
d8c7f98cfd
|
@ -3,6 +3,7 @@ class StoriesController < ApplicationController
|
|||
:only => [ :upvote, :downvote, :unvote, :hide, :unhide, :preview ]
|
||||
before_filter :require_logged_in_user, :only => [ :destroy, :create, :edit,
|
||||
:fetch_url_attributes, :new, :suggest ]
|
||||
before_filter :verify_user_can_submit_stories, :only => [ :new, :create ]
|
||||
before_filter :find_user_story, :only => [ :destroy, :edit, :undelete,
|
||||
:update ]
|
||||
before_filter :find_story!, :only => [ :suggest, :submit_suggestions ]
|
||||
|
@ -378,4 +379,11 @@ private
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def verify_user_can_submit_stories
|
||||
if !@user.can_submit_stories?
|
||||
flash[:error] = "You are not allowed to submit new stories."
|
||||
return redirect_to "/"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -64,6 +64,9 @@ class User < ActiveRecord::Base
|
|||
# minimum karma required to be able to offer title/tag suggestions
|
||||
MIN_KARMA_TO_SUGGEST = 10
|
||||
|
||||
# minimum karma required to be able to submit new stories
|
||||
MIN_KARMA_TO_SUBMIT_STORIES = -4
|
||||
|
||||
def self.recalculate_all_karmas!
|
||||
User.all.each do |u|
|
||||
u.karma = u.stories.map(&:score).sum + u.comments.map(&:score).sum
|
||||
|
@ -178,10 +181,18 @@ class User < ActiveRecord::Base
|
|||
false
|
||||
end
|
||||
|
||||
def can_invite?
|
||||
!disabled_invite_at? && self.can_submit_stories?
|
||||
end
|
||||
|
||||
def can_offer_suggestions?
|
||||
!self.is_new? && (self.karma >= MIN_KARMA_TO_SUGGEST)
|
||||
end
|
||||
|
||||
def can_submit_stories?
|
||||
self.karma >= MIN_KARMA_TO_SUBMIT_STORIES
|
||||
end
|
||||
|
||||
def check_session_token
|
||||
if self.session_token.blank?
|
||||
self.session_token = Utils.random_str(60)
|
||||
|
@ -281,10 +292,6 @@ class User < ActiveRecord::Base
|
|||
banned_at?
|
||||
end
|
||||
|
||||
def can_invite?
|
||||
!disabled_invite_at?
|
||||
end
|
||||
|
||||
def is_new?
|
||||
Time.now - self.created_at <= NEW_USER_DAYS.days
|
||||
end
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
"/comments" => t('.commentslink')
|
||||
} %>
|
||||
|
||||
<% if @user %>
|
||||
<% if @user && @user.can_submit_stories? %>
|
||||
<% links.merge!({ "/threads" => t('.yourthreadslink'),
|
||||
"/stories/new" => t('.submitstorylink') }) %>
|
||||
<% end %>
|
||||
|
|
Loading…
Reference in a new issue