Fix #4982: Add route to remove a post from a favorite group
This commit is contained in:
@@ -59,4 +59,12 @@ class FavoriteGroupsController < ApplicationController
|
||||
|
||||
respond_with(@favorite_group)
|
||||
end
|
||||
|
||||
def remove_post
|
||||
@favorite_group = authorize FavoriteGroup.find(params[:id])
|
||||
@post = Post.find(params[:post_id])
|
||||
@favorite_group.remove(@post)
|
||||
|
||||
respond_with(@favorite_group)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,6 +17,10 @@ class FavoriteGroupPolicy < ApplicationPolicy
|
||||
update?
|
||||
end
|
||||
|
||||
def remove_post?
|
||||
update?
|
||||
end
|
||||
|
||||
def can_enable_privacy?
|
||||
record.creator.is_gold?
|
||||
end
|
||||
|
||||
7
app/views/favorite_groups/remove_post.js.erb
Normal file
7
app/views/favorite_groups/remove_post.js.erb
Normal file
@@ -0,0 +1,7 @@
|
||||
<% if @favorite_group.errors.any? %>
|
||||
Danbooru.notice("<%= j @favorite_group.errors.full_messages.join("; ") %>");
|
||||
<% else %>
|
||||
Danbooru.notice("Removed post from favorite group <%= j @favorite_group.pretty_name %>");
|
||||
<% end %>
|
||||
|
||||
$("#add-to-favgroup-dialog").dialog("close");
|
||||
@@ -125,6 +125,7 @@ Rails.application.routes.draw do
|
||||
resources :favorite_groups do
|
||||
member do
|
||||
put :add_post
|
||||
put :remove_post
|
||||
end
|
||||
resource :order, :only => [:edit], :controller => "favorite_group_orders"
|
||||
end
|
||||
|
||||
@@ -116,6 +116,7 @@ class FavoriteGroupsControllerTest < ActionDispatch::IntegrationTest
|
||||
should "render" do
|
||||
@post = create(:post)
|
||||
put_auth add_post_favorite_group_path(@favgroup), @user, params: {post_id: @post.id, format: "js"}
|
||||
|
||||
assert_response :success
|
||||
assert_equal([@post.id], @favgroup.reload.post_ids)
|
||||
end
|
||||
@@ -123,7 +124,33 @@ class FavoriteGroupsControllerTest < ActionDispatch::IntegrationTest
|
||||
should "not add posts to favgroups belonging to other users" do
|
||||
@post = create(:post)
|
||||
put_auth add_post_favorite_group_path(@favgroup), create(:user), params: {post_id: @post.id, format: "js"}
|
||||
|
||||
assert_response 403
|
||||
assert_equal([], @favgroup.reload.post_ids)
|
||||
end
|
||||
end
|
||||
|
||||
context "remove_post action" do
|
||||
should "render" do
|
||||
@post = create(:post)
|
||||
@favgroup.add(@post)
|
||||
assert_equal([@post.id], @favgroup.reload.post_ids)
|
||||
|
||||
put_auth remove_post_favorite_group_path(@favgroup), @user, params: { post_id: @post.id, format: "js" }
|
||||
|
||||
assert_response :success
|
||||
assert_equal([], @favgroup.reload.post_ids)
|
||||
end
|
||||
|
||||
should "not remove posts from favgroups belonging to other users" do
|
||||
@post = create(:post)
|
||||
@favgroup.add(@post)
|
||||
assert_equal([@post.id], @favgroup.reload.post_ids)
|
||||
|
||||
put_auth remove_post_favorite_group_path(@favgroup), create(:user), params: { post_id: @post.id, format: "js" }
|
||||
|
||||
assert_response 403
|
||||
assert_equal([@post.id], @favgroup.reload.post_ids)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user