fixed pool deletion logic
This commit is contained in:
@@ -49,10 +49,19 @@ class PoolsController < ApplicationController
|
|||||||
if !@pool.deletable_by?(CurrentUser.user)
|
if !@pool.deletable_by?(CurrentUser.user)
|
||||||
raise User::PrivilegeError
|
raise User::PrivilegeError
|
||||||
end
|
end
|
||||||
@pool.destroy
|
@pool.update_attribute(:is_deleted, true)
|
||||||
respond_with(@pool, :notice => "Pool deleted")
|
respond_with(@pool, :notice => "Pool deleted")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def undelete
|
||||||
|
@pool = Pool.find(params[:id])
|
||||||
|
if !@pool.deletable_by?(CurrentUser.user)
|
||||||
|
raise User::PrivilegeError
|
||||||
|
end
|
||||||
|
@pool.update_attribute(:is_deleted, false)
|
||||||
|
respond_with(@pool, :notice => "Pool undeleted")
|
||||||
|
end
|
||||||
|
|
||||||
def revert
|
def revert
|
||||||
@pool = Pool.find(params[:id])
|
@pool = Pool.find(params[:id])
|
||||||
@version = PoolVersion.find(params[:version_id])
|
@version = PoolVersion.find(params[:version_id])
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ class Pool < ActiveRecord::Base
|
|||||||
before_validation :initialize_creator, :on => :create
|
before_validation :initialize_creator, :on => :create
|
||||||
after_save :create_version
|
after_save :create_version
|
||||||
before_destroy :create_mod_action_for_destroy
|
before_destroy :create_mod_action_for_destroy
|
||||||
attr_accessible :name, :description, :post_ids, :post_id_array, :post_count, :as => [:member, :privileged, :contributor, :janitor, :moderator, :admin, :default]
|
attr_accessible :name, :description, :post_ids, :post_id_array, :post_count, :is_active, :as => [:member, :privileged, :contributor, :janitor, :moderator, :admin, :default]
|
||||||
attr_accessible :is_active, :as => [:janitor, :moderator, :admin]
|
attr_accessible :is_deleted, :as => [:janitor, :moderator, :admin]
|
||||||
scope :active, where("is_active = true")
|
scope :active, where("is_active = true and is_deleted = false")
|
||||||
|
|
||||||
def self.name_to_id(name)
|
def self.name_to_id(name)
|
||||||
if name =~ /^\d+$/
|
if name =~ /^\d+$/
|
||||||
@@ -56,6 +56,7 @@ class Pool < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def initialize_is_active
|
def initialize_is_active
|
||||||
|
self.is_deleted = false if is_deleted.nil?
|
||||||
self.is_active = true if is_active.nil?
|
self.is_active = true if is_active.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,11 @@
|
|||||||
<li><%= link_to "Posts", posts_path(:tags => "pool:#{@pool.id}") %></li>
|
<li><%= link_to "Posts", posts_path(:tags => "pool:#{@pool.id}") %></li>
|
||||||
<li><%= link_to "Edit", edit_pool_path(@pool) %></li>
|
<li><%= link_to "Edit", edit_pool_path(@pool) %></li>
|
||||||
<% if @pool.deletable_by?(CurrentUser.user) %>
|
<% if @pool.deletable_by?(CurrentUser.user) %>
|
||||||
<li><%= link_to "Delete", pool_path(@pool), :method => :delete, :confirm => "Are you sure you want to delete this pool?", :remote => true %></li>
|
<% if @pool.is_deleted? %>
|
||||||
|
<li><%= link_to "Undelete", undelete_pool_path(@pool), :method => :post, :remote => true %></li>
|
||||||
|
<% else %>
|
||||||
|
<li><%= link_to "Delete", pool_path(@pool), :method => :delete, :confirm => "Are you sure you want to delete this pool?", :remote => true %></li>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<li><%= link_to "Order", edit_pool_order_path(@pool) %></li>
|
<li><%= link_to "Order", edit_pool_order_path(@pool) %></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -46,6 +46,8 @@
|
|||||||
<menu id="post-sections">
|
<menu id="post-sections">
|
||||||
<li><a href="#comments">Comments</a></li>
|
<li><a href="#comments">Comments</a></li>
|
||||||
<li><a href="#edit" id="post-edit-link">Edit</a></li>
|
<li><a href="#edit" id="post-edit-link">Edit</a></li>
|
||||||
|
<li><a href="#favorite-tab">Favorite</a></li>
|
||||||
|
<li><a href="#share">Share</a></li>
|
||||||
</menu>
|
</menu>
|
||||||
|
|
||||||
<section id="comments">
|
<section id="comments">
|
||||||
@@ -59,6 +61,14 @@
|
|||||||
<section id="edit" style="display: none;">
|
<section id="edit" style="display: none;">
|
||||||
<%= render "posts/partials/show/edit", :post => @post %>
|
<%= render "posts/partials/show/edit", :post => @post %>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section id="favorite-tab" style="display: none;">
|
||||||
|
<p>Favoriting...</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="share-tab" style="display: none;">
|
||||||
|
<h1>Share</h1>
|
||||||
|
</section>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ Danbooru::Application.routes.draw do
|
|||||||
end
|
end
|
||||||
member do
|
member do
|
||||||
put :revert
|
put :revert
|
||||||
|
post :undelete
|
||||||
end
|
end
|
||||||
resource :order, :only => [:edit, :update], :controller => "PoolOrders"
|
resource :order, :only => [:edit, :update], :controller => "PoolOrders"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ class CreatePools < ActiveRecord::Migration
|
|||||||
t.column :is_active, :boolean, :null => false, :default => true
|
t.column :is_active, :boolean, :null => false, :default => true
|
||||||
t.column :post_ids, :text, :null => false, :default => ""
|
t.column :post_ids, :text, :null => false, :default => ""
|
||||||
t.column :post_count, :integer, :null => false, :default => 0
|
t.column :post_count, :integer, :null => false, :default => 0
|
||||||
|
t.column :is_deleted, :boolean, :null => false, :default => false
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -67,9 +67,23 @@ class PoolsControllerTest < ActionController::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "destroy a pool" do
|
should "destroy a pool" do
|
||||||
assert_difference("Pool.count", -1) do
|
post :destroy, {:id => @pool.id}, {:user_id => @mod.id}
|
||||||
post :destroy, {:id => @pool.id}, {:user_id => @mod.id}
|
@pool.reload
|
||||||
end
|
assert_equal(true, @pool.is_deleted?)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "undelete action" do
|
||||||
|
setup do
|
||||||
|
@pool = Factory.create(:pool)
|
||||||
|
@pool.is_deleted = true
|
||||||
|
@pool.save
|
||||||
|
end
|
||||||
|
|
||||||
|
should "restore a pool" do
|
||||||
|
post :undelete, {:id => @pool.id}, {:user_id => @mod.id}
|
||||||
|
@pool.reload
|
||||||
|
assert_equal(false, @pool.is_deleted?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user