Redirect to home if remove yourself from the collection

This commit is contained in:
Jorge Manrubia
2025-09-17 18:21:50 +02:00
parent 515fb72d54
commit a680235773
2 changed files with 17 additions and 2 deletions
+5 -2
View File
@@ -20,8 +20,11 @@ class CollectionsController < ApplicationController
def update
@collection.update! collection_params
@collection.accesses.revise granted: grantees, revoked: revokees if grantees_changed?
redirect_to edit_collection_path(@collection), notice: "Saved"
if @collection.accessible_to?(Current.user)
redirect_to edit_collection_path(@collection), notice: "Saved"
else
redirect_to root_path, notice: "Saved (you were removed from the collection)"
end
end
def destroy
@@ -45,6 +45,18 @@ class CollectionsControllerTest < ActionDispatch::IntegrationTest
assert_not collections(:writebook).all_access?
end
test "update redirects to root when user removes themselves from collection" do
collection = collections(:writebook)
patch collection_path(collection), params: {
collection: { name: "Updated name", all_access: false },
user_ids: users(:david, :jz).pluck(:id)
}
assert_redirected_to root_path
assert_not collection.reload.users.include?(users(:kevin))
end
test "update collection with granular permissions, submitting no user ids" do
assert_not collections(:private).all_access?