Redirect to home if remove yourself from the collection
This commit is contained in:
@@ -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?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user