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
|
end
|
||||||
|
|
||||||
def suggest
|
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?
|
if (st = @story.suggested_taggings.where(:user_id => @user.id)).any?
|
||||||
@story.tags_a = st.map{|st| st.tag.tag }
|
@story.tags_a = st.map{|st| st.tag.tag }
|
||||||
end
|
end
|
||||||
|
@ -180,6 +185,11 @@ class StoriesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def submit_suggestions
|
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
|
ostory = @story.dup
|
||||||
|
|
||||||
@story.title = params[:story][:title]
|
@story.title = params[:story][:title]
|
||||||
|
|
|
@ -219,11 +219,7 @@ class Story < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_have_suggestions_from_user?(user)
|
def can_have_suggestions_from_user?(user)
|
||||||
if !user
|
if !user || (user.id == self.user_id) || !user.can_offer_suggestions?
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
if user.id == self.user_id
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,9 @@ class User < ActiveRecord::Base
|
||||||
# days old accounts are considered new for
|
# days old accounts are considered new for
|
||||||
NEW_USER_DAYS = 7
|
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!
|
def self.recalculate_all_karmas!
|
||||||
User.all.each do |u|
|
User.all.each do |u|
|
||||||
u.karma = u.stories.map(&:score).sum + u.comments.map(&:score).sum
|
u.karma = u.stories.map(&:score).sum + u.comments.map(&:score).sum
|
||||||
|
@ -146,6 +149,10 @@ class User < ActiveRecord::Base
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def can_offer_suggestions?
|
||||||
|
!self.is_new? && (self.karma >= MIN_KARMA_TO_SUGGEST)
|
||||||
|
end
|
||||||
|
|
||||||
def check_session_token
|
def check_session_token
|
||||||
if self.session_token.blank?
|
if self.session_token.blank?
|
||||||
self.session_token = Utils.random_str(60)
|
self.session_token = Utils.random_str(60)
|
||||||
|
|
Loading…
Reference in a new issue