alert the user when submitting a long-ago-submitted story
show the user a link to the previous story and let them know they can submit it again if they want to (just by submitting the form again)
This commit is contained in:
parent
22b77573a5
commit
f1f6b3c7e0
|
@ -1034,6 +1034,9 @@ div.flash-notice {
|
||||||
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
|
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.flash-error h2,
|
||||||
|
div.flash-notice h2,
|
||||||
|
div.flash-success h2,
|
||||||
div.errorExplanation h2 {
|
div.errorExplanation h2 {
|
||||||
font-size: 1.25em;
|
font-size: 1.25em;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|
|
@ -16,28 +16,19 @@ class StoriesController < ApplicationController
|
||||||
@story.url = params[:story][:url]
|
@story.url = params[:story][:url]
|
||||||
@story.user_id = @user.id
|
@story.user_id = @user.id
|
||||||
|
|
||||||
if @story.save
|
if @story.valid? && !(@story.already_posted_story && !@story.seen_previous)
|
||||||
Vote.vote_thusly_on_story_or_comment_for_user_because(1, @story.id,
|
if @story.save
|
||||||
nil, @user.id, nil)
|
Vote.vote_thusly_on_story_or_comment_for_user_because(1, @story.id,
|
||||||
|
nil, @user.id, nil)
|
||||||
|
|
||||||
Countinual.count!("#{Rails.application.shortname}.stories.submitted",
|
Countinual.count!("#{Rails.application.shortname}.stories.submitted",
|
||||||
"+1")
|
"+1")
|
||||||
|
|
||||||
return redirect_to @story.comments_url
|
return redirect_to @story.comments_url
|
||||||
|
|
||||||
else
|
|
||||||
if @story.already_posted_story
|
|
||||||
# consider it an upvote
|
|
||||||
Vote.vote_thusly_on_story_or_comment_for_user_because(1,
|
|
||||||
@story.already_posted_story.id, nil, @user.id, nil)
|
|
||||||
|
|
||||||
flash[:success] = "This URL has already been submitted recently."
|
|
||||||
|
|
||||||
return redirect_to @story.already_posted_story.comments_url
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return render :action => "new"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return render :action => "new"
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
@ -87,11 +78,16 @@ class StoriesController < ApplicationController
|
||||||
if params[:url].present?
|
if params[:url].present?
|
||||||
@story.url = params[:url]
|
@story.url = params[:url]
|
||||||
|
|
||||||
# if this story was already submitted, don't bother the user filling out
|
if s = Story.find_similar_by_url(@story.url)
|
||||||
# tags and stuff, just redirect them right away
|
if s.is_recent?
|
||||||
if s = Story.find_recent_similar_by_url(@story.url)
|
# user won't be able to submit this story as new, so just redirect
|
||||||
flash[:success] = "This URL has already been submitted recently."
|
# them to the previous story
|
||||||
return redirect_to s.comments_url
|
flash[:success] = "This URL has already been submitted recently."
|
||||||
|
return redirect_to s.comments_url
|
||||||
|
else
|
||||||
|
# user will see a warning like with preview screen
|
||||||
|
@story.already_posted_story = s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:title].present?
|
if params[:title].present?
|
||||||
|
@ -112,6 +108,8 @@ class StoriesController < ApplicationController
|
||||||
|
|
||||||
@story.valid?
|
@story.valid?
|
||||||
|
|
||||||
|
@story.seen_previous = true
|
||||||
|
|
||||||
return render :action => "new", :layout => false
|
return render :action => "new", :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,15 @@ class Story < ActiveRecord::Base
|
||||||
# after this many minutes old, a story cannot be edited
|
# after this many minutes old, a story cannot be edited
|
||||||
MAX_EDIT_MINS = 30
|
MAX_EDIT_MINS = 30
|
||||||
|
|
||||||
attr_accessor :vote, :already_posted_story, :fetched_content, :previewing
|
# days a story is considered recent
|
||||||
|
RECENT_DAYS = 30
|
||||||
|
|
||||||
|
attr_accessor :vote, :already_posted_story, :fetched_content, :previewing,
|
||||||
|
:seen_previous
|
||||||
attr_accessor :editor_user_id, :moderation_reason
|
attr_accessor :editor_user_id, :moderation_reason
|
||||||
|
|
||||||
attr_accessible :title, :description, :tags_a, :moderation_reason
|
attr_accessible :title, :description, :tags_a, :moderation_reason,
|
||||||
|
:seen_previous
|
||||||
|
|
||||||
before_validation :assign_short_id,
|
before_validation :assign_short_id,
|
||||||
:on => :create
|
:on => :create
|
||||||
|
@ -27,9 +32,12 @@ class Story < ActiveRecord::Base
|
||||||
# URI.parse is not very lenient, so we can't use it
|
# URI.parse is not very lenient, so we can't use it
|
||||||
|
|
||||||
if self.url.match(/\Ahttps?:\/\/([^\.]+\.)+[a-z]+(\/|\z)/)
|
if self.url.match(/\Ahttps?:\/\/([^\.]+\.)+[a-z]+(\/|\z)/)
|
||||||
if self.new_record? && (s = Story.find_recent_similar_by_url(self.url))
|
if self.new_record? && (s = Story.find_similar_by_url(self.url))
|
||||||
errors.add(:url, "has already been submitted recently")
|
|
||||||
self.already_posted_story = s
|
self.already_posted_story = s
|
||||||
|
if s.is_recent?
|
||||||
|
errors.add(:url, "has already been submitted within the past " <<
|
||||||
|
"#{RECENT_DAYS} days")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
errors.add(:url, "is not valid")
|
errors.add(:url, "is not valid")
|
||||||
|
@ -41,7 +49,7 @@ class Story < ActiveRecord::Base
|
||||||
check_tags
|
check_tags
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_recent_similar_by_url(url)
|
def self.find_similar_by_url(url)
|
||||||
urls = [ url.to_s ]
|
urls = [ url.to_s ]
|
||||||
urls2 = [ url.to_s ]
|
urls2 = [ url.to_s ]
|
||||||
|
|
||||||
|
@ -66,14 +74,13 @@ class Story < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
urls = urls2.clone
|
urls = urls2.clone
|
||||||
|
|
||||||
conds = [ "created_at >= ? AND (", (Time.now - 30.days) ]
|
conds = [ "" ]
|
||||||
urls.uniq.each_with_index do |u,x|
|
urls.uniq.each_with_index do |u,x|
|
||||||
conds[0] << (x == 0 ? "" : " OR ") << "url = ?"
|
conds[0] << (x == 0 ? "" : " OR ") << "url = ?"
|
||||||
conds.push u
|
conds.push u
|
||||||
end
|
end
|
||||||
conds[0] << ")"
|
|
||||||
|
|
||||||
if s = Story.where(*conds).first
|
if s = Story.where(*conds).order("id DESC").first
|
||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -376,6 +383,10 @@ class Story < ActiveRecord::Base
|
||||||
is_expired?
|
is_expired?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_recent?
|
||||||
|
self.created_at >= RECENT_DAYS.days.ago
|
||||||
|
end
|
||||||
|
|
||||||
def recalculate_hotness!
|
def recalculate_hotness!
|
||||||
update_column :hotness, calculated_hotness
|
update_column :hotness, calculated_hotness
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,20 @@
|
||||||
<%= error_messages_for f.object %>
|
<%= error_messages_for f.object %>
|
||||||
|
|
||||||
|
<% if !f.object.errors.any? && f.object.already_posted_story %>
|
||||||
|
<div class="flash-notice">
|
||||||
|
<h2>Note: This story was already submitted <%=
|
||||||
|
time_ago_in_words(f.object.already_posted_story.created_at) %> ago, but may
|
||||||
|
be submitted again.</h2>
|
||||||
|
<p>
|
||||||
|
Please view the <a href="<%= f.object.already_posted_story.comments_url %>"
|
||||||
|
target="_blank">previous discussion</a> for this story first. If the content
|
||||||
|
has changed or warrants new discussion, you may submit it again.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= f.hidden_field :seen_previous %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="boxline">
|
<div class="boxline">
|
||||||
<% if f.object.url_is_editable_by_user?(@user) %>
|
<% if f.object.url_is_editable_by_user?(@user) %>
|
||||||
|
|
Loading…
Reference in a new issue