summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/users_controller.rb6
-rw-r--r--app/helpers/users_helper.rb8
-rw-r--r--app/views/users/_destroy_account.html.haml15
-rw-r--r--config/locales/en/users.en.yml1
-rw-r--r--test/integration/browser/account_livecycle_test.rb20
5 files changed, 38 insertions, 12 deletions
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 0a0f551..da82d1c 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -44,7 +44,7 @@ class UsersController < ApplicationController
end
def destroy
- @user.account.destroy
+ @user.account.destroy(release_handles)
flash[:notice] = I18n.t(:account_destroyed)
# admins can destroy other users
if @user != current_user
@@ -65,4 +65,8 @@ class UsersController < ApplicationController
params.require(:user).permit(:password, :password_confirmation)
end
end
+
+ def release_handles
+ ! params[:block_username]
+ end
end
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index 1b2dc5d..985f750 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -11,4 +11,12 @@ module UsersHelper
end
end
+
+ def destroy_account_text
+ if @user == current_user
+ t(:destroy_my_account)
+ else
+ t(:admin_destroy_account, :username => @user.login)
+ end
+ end
end
diff --git a/app/views/users/_destroy_account.html.haml b/app/views/users/_destroy_account.html.haml
index a2c4ddd..66a7dc2 100644
--- a/app/views/users/_destroy_account.html.haml
+++ b/app/views/users/_destroy_account.html.haml
@@ -3,14 +3,15 @@
-#
%legend
- - if @user == current_user
- = t(:destroy_my_account)
- - else
- = t(:admin_destroy_account, :username => @user.login)
+ = destroy_account_text
%p= t(:destroy_account_info)
-= destroy_btn user_path(@user), :type => "danger" do
- %i.icon-remove.icon-white
- = t(:destroy_my_account)
+= form_tag user_path(@user), method: :delete do
+ .checkbox
+ = label_tag do
+ = check_box_tag 'block_username', 1, true
+ = t(:keep_username_blocked)
+ = submit_tag destroy_account_text, class: "btn btn-danger"
+
- if @user != current_user and @user.enabled?
%legend
= t(:deactivate_account, :username => @user.login)
diff --git a/config/locales/en/users.en.yml b/config/locales/en/users.en.yml
index b9f1724..d3dab30 100644
--- a/config/locales/en/users.en.yml
+++ b/config/locales/en/users.en.yml
@@ -19,6 +19,7 @@ en:
destroy_my_account: "Destroy my account"
destroy_account_info: "This will permanently destroy your account and all the data associated with it. Proceed with caution!"
admin_destroy_account: "Destroy the account %{username}"
+ keep_username_blocked: "Keep the username blocked from reuse for a while"
account_destroyed: "The account has been destroyed successfully."
set_email_address: "Set email address"
forward_email: "Forward Email"
diff --git a/test/integration/browser/account_livecycle_test.rb b/test/integration/browser/account_livecycle_test.rb
index 835dfdc..3d23363 100644
--- a/test/integration/browser/account_livecycle_test.rb
+++ b/test/integration/browser/account_livecycle_test.rb
@@ -8,7 +8,7 @@ class AccountLivecycleTest < BrowserIntegrationTest
test "signup successfully when invited" do
username, password = submit_signup
- assert page.has_content?("Welcome #{username}")
+ assert_successful_login username
click_on 'Log Out'
assert page.has_content?("Log In")
assert_equal '/', current_path
@@ -28,14 +28,14 @@ class AccountLivecycleTest < BrowserIntegrationTest
fill_in 'Password confirmation', with: password
click_on 'Sign Up'
- assert page.has_content?("Welcome #{username}")
+ assert_successful_login username
end
end
test "signup with username ending in dot json" do
username = Faker::Internet.user_name + '.json'
submit_signup username
- assert page.has_content?("Welcome #{username}")
+ assert_successful_login username
end
test "signup with reserved username" do
@@ -48,7 +48,7 @@ class AccountLivecycleTest < BrowserIntegrationTest
username, password = submit_signup
click_on 'Log Out'
attempt_login(username, password)
- assert page.has_content?("Welcome #{username}")
+ assert_successful_login username
within('.sidenav li.active') do
assert page.has_content?("Overview")
end
@@ -80,6 +80,15 @@ class AccountLivecycleTest < BrowserIntegrationTest
assert page.has_content?('has already been taken')
end
+ test "handle available after non blocking account destruction" do
+ username, password = submit_signup
+ click_on I18n.t('account_settings')
+ uncheck I18n.t('keep_username_blocked')
+ click_on I18n.t('destroy_my_account')
+ submit_signup(username)
+ assert_successful_login username
+ end
+
test "change pgp key" do
with_config user_actions: ['change_pgp_key'] do
pgp_key = FactoryGirl.build :pgp_key
@@ -111,4 +120,7 @@ class AccountLivecycleTest < BrowserIntegrationTest
assert page.has_no_selector? '.btn-primary.disabled'
end
+ def assert_successful_login(username)
+ assert page.has_content?("Welcome #{username}")
+ end
end