Disallow account deletion after confirmation
This commit is contained in:
parent
14bd660114
commit
b5f8df642a
2 changed files with 28 additions and 5 deletions
|
@ -53,12 +53,16 @@ class AccountsController < ApplicationController
|
|||
end
|
||||
|
||||
def destroy
|
||||
current_user.soft_destroy!
|
||||
if current_user.deletion_allowed?
|
||||
current_user.soft_destroy!
|
||||
|
||||
session.delete(:user)
|
||||
session_expires_automatically
|
||||
session.delete(:user)
|
||||
session_expires_automatically
|
||||
|
||||
flash[:notice] = t ".success"
|
||||
redirect_to root_path
|
||||
flash[:notice] = t ".success"
|
||||
redirect_to root_path
|
||||
else
|
||||
head :bad_request
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -152,4 +152,23 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
|
|||
# Make sure we have a button to "go public"
|
||||
assert_select "form.button_to[action='/user/go_public']", true
|
||||
end
|
||||
|
||||
def test_destroy_allowed
|
||||
user = create(:user)
|
||||
session_for(user)
|
||||
|
||||
delete account_path
|
||||
assert_response :redirect
|
||||
end
|
||||
|
||||
def test_destroy_not_allowed
|
||||
with_user_account_deletion_delay(24) do
|
||||
user = create(:user)
|
||||
create(:changeset, :user => user, :created_at => Time.now.utc)
|
||||
session_for(user)
|
||||
|
||||
delete account_path
|
||||
assert_response :bad_request
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue