require a minimum karma to suggest story title/tag suggestions
This commit is contained in:
parent
21a5152acf
commit
4c5cf4a542
|
@ -171,6 +171,11 @@ class StoriesController < ApplicationController
|
|||
end
|
||||
|
||||
def suggest
|
||||
if !@story.can_have_suggestions_from_user?(@user)
|
||||
flash[:error] = "You are not allowed to offer suggestions on that story."
|
||||
return redirect_to @story.comments_path
|
||||
end
|
||||
|
||||
if (st = @story.suggested_taggings.where(:user_id => @user.id)).any?
|
||||
@story.tags_a = st.map{|st| st.tag.tag }
|
||||
end
|
||||
|
@ -180,6 +185,11 @@ class StoriesController < ApplicationController
|
|||
end
|
||||
|
||||
def submit_suggestions
|
||||
if !@story.can_have_suggestions_from_user?(@user)
|
||||
flash[:error] = "You are not allowed to offer suggestions on that story."
|
||||
return redirect_to @story.comments_path
|
||||
end
|
||||
|
||||
ostory = @story.dup
|
||||
|
||||
@story.title = params[:story][:title]
|
||||
|
|
|
@ -219,11 +219,7 @@ class Story < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def can_have_suggestions_from_user?(user)
|
||||
if !user
|
||||
return false
|
||||
end
|
||||
|
||||
if user.id == self.user_id
|
||||
if !user || (user.id == self.user_id) || !user.can_offer_suggestions?
|
||||
return false
|
||||
end
|
||||
|
||||
|
|
|
@ -59,6 +59,9 @@ class User < ActiveRecord::Base
|
|||
# days old accounts are considered new for
|
||||
NEW_USER_DAYS = 7
|
||||
|
||||
# minimum karma required to be able to offer title/tag suggestions
|
||||
MIN_KARMA_TO_SUGGEST = 10
|
||||
|
||||
def self.recalculate_all_karmas!
|
||||
User.all.each do |u|
|
||||
u.karma = u.stories.map(&:score).sum + u.comments.map(&:score).sum
|
||||
|
@ -146,6 +149,10 @@ class User < ActiveRecord::Base
|
|||
false
|
||||
end
|
||||
|
||||
def can_offer_suggestions?
|
||||
!self.is_new? && (self.karma >= MIN_KARMA_TO_SUGGEST)
|
||||
end
|
||||
|
||||
def check_session_token
|
||||
if self.session_token.blank?
|
||||
self.session_token = Utils.random_str(60)
|
||||
|
|
Loading…
Reference in a new issue