fixes #1289
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
class ForumTopicsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
before_filter :member_only, :except => [:index, :show]
|
||||
before_filter :janitor_only, :only => [:new_merge, :create_merge]
|
||||
before_filter :normalize_search, :only => :index
|
||||
|
||||
def new
|
||||
@@ -68,6 +69,17 @@ class ForumTopicsController < ApplicationController
|
||||
redirect_to forum_topics_path, :notice => "All topics marked as read"
|
||||
end
|
||||
|
||||
def new_merge
|
||||
@forum_topic = ForumTopic.find(params[:id])
|
||||
end
|
||||
|
||||
def create_merge
|
||||
@forum_topic = ForumTopic.find(params[:id])
|
||||
@merged_topic = ForumTopic.find(params[:merged_id])
|
||||
@forum_topic.merge(@merged_topic)
|
||||
redirect_to forum_topic_path(@forum_topic)
|
||||
end
|
||||
|
||||
private
|
||||
def normalize_search
|
||||
if params[:title_matches]
|
||||
|
||||
@@ -130,4 +130,9 @@ class ForumTopic < ActiveRecord::Base
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def merge(topic)
|
||||
ForumPost.update_all({:topic_id => id}, :id => topic.posts.map(&:id))
|
||||
update_attribute(:is_deleted, true)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
<% else %>
|
||||
<li><%= link_to "Sticky", forum_topic_path(@forum_topic, :forum_topic => {:is_sticky => true}), :method => :put, :confirm => "Are you sure you want to sticky this forum topic?" %></li>
|
||||
<% end %>
|
||||
<li><%= link_to "Merge", new_merge_forum_topic_path(@forum_topic) %></li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
23
app/views/forum_topics/new_merge.html.erb
Normal file
23
app/views/forum_topics/new_merge.html.erb
Normal file
@@ -0,0 +1,23 @@
|
||||
<div id="c-forum-topics">
|
||||
<div id="a-merge">
|
||||
<h1>Merge Forum Topic</h1>
|
||||
|
||||
<p>Merge <strong><%= @forum_topic.title %></strong> into:</p>
|
||||
|
||||
<%= form_tag(create_merge_forum_topic_path(@forum_topic)) do %>
|
||||
<div>
|
||||
<label>
|
||||
Forum Topic ID:
|
||||
<%= text_field_tag :merged_id %>
|
||||
</label>
|
||||
</div>
|
||||
<%= submit_tag "Merge" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "secondary_links" %>
|
||||
|
||||
<% content_for(:page_title) do %>
|
||||
Merge Forum Topic - <%= Danbooru.config.app_name %>
|
||||
<% end %>
|
||||
@@ -113,6 +113,8 @@ Danbooru::Application.routes.draw do
|
||||
resources :forum_topics do
|
||||
member do
|
||||
post :undelete
|
||||
get :new_merge
|
||||
post :create_merge
|
||||
end
|
||||
collection do
|
||||
post :mark_all_as_read
|
||||
|
||||
@@ -14,6 +14,19 @@ class ForumTopicTest < ActiveSupport::TestCase
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "#merge" do
|
||||
setup do
|
||||
@topic2 = FactoryGirl.create(:forum_topic, :title => "yyy")
|
||||
FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => "xxx")
|
||||
FactoryGirl.create(:forum_post, :topic_id => @topic2.id, :body => "xxx")
|
||||
end
|
||||
|
||||
should "merge all the posts in one topic into the other" do
|
||||
@topic.merge(@topic2)
|
||||
assert_equal(2, @topic.posts.count)
|
||||
end
|
||||
end
|
||||
|
||||
context "#read_by?" do
|
||||
context "for a topic that was never read by the user" do
|
||||
should "return false" do
|
||||
|
||||
Reference in New Issue
Block a user