Story: do automatic user suggestion promotion for story titles too
It's much less likely that users will all agree on an exact title name, but try it anyway.
This commit is contained in:
parent
800aea1ca9
commit
a4e3f04d2d
|
@ -188,6 +188,7 @@ class StoriesController < ApplicationController
|
|||
if @story.tags_a.sort != params[:story][:tags_a].sort
|
||||
@story.save_suggested_tags_a_for_user!(params[:story][:tags_a], @user)
|
||||
end
|
||||
ostory.reload
|
||||
flash[:success] = "Your suggested changes have been noted."
|
||||
redirect_to ostory.comments_path
|
||||
else
|
||||
|
|
|
@ -592,6 +592,30 @@ class Story < ActiveRecord::Base
|
|||
end
|
||||
st.title = title
|
||||
st.save!
|
||||
|
||||
# if enough users voted on the same exact title, save it
|
||||
title_votes = {}
|
||||
self.suggested_titles.each do |st|
|
||||
title_votes[st.title] ||= 0
|
||||
title_votes[st.title] += 1
|
||||
end
|
||||
|
||||
title_votes.sort_by{|k,v| v }.reverse.each do |kv|
|
||||
if kv[1] >= SUGGESTION_QUORUM
|
||||
Rails.logger.info "[s#{self.id}] promoting suggested title " <<
|
||||
"#{kv[0].inspect} instead of #{self.title.inspect}"
|
||||
self.editor = nil
|
||||
self.editing_from_suggestions = true
|
||||
self.moderation_reason = "Automatically changed from user suggestions"
|
||||
self.title = kv[0]
|
||||
if !self.save
|
||||
Rails.logger.error "[s#{self.id}] failed auto promoting: " <<
|
||||
self.errors.inspect
|
||||
end
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def title=(t)
|
||||
|
|
Loading…
Reference in a new issue