From ce477273da280fc78426d2e3e582c483f988412f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 8 Apr 2016 11:03:30 +0200 Subject: [PATCH] adds managers option to delete a level 2 account --- .../management/users_controller.rb | 6 +++++ .../document_verifications/new.html.erb | 11 ++++++++ config/locales/management.en.yml | 6 +++++ config/locales/management.es.yml | 6 +++++ config/routes.rb | 5 +++- spec/features/management/users_spec.rb | 27 ++++++++++++++++++- 6 files changed, 59 insertions(+), 2 deletions(-) diff --git a/app/controllers/management/users_controller.rb b/app/controllers/management/users_controller.rb index 53c432fd1..8ee04cfdf 100644 --- a/app/controllers/management/users_controller.rb +++ b/app/controllers/management/users_controller.rb @@ -18,6 +18,12 @@ class Management::UsersController < Management::BaseController end end + def erase + managed_user.erase(t("management.users.erased_by_manager", manager: current_manager['login'])) if current_manager.present? + destroy_session + redirect_to management_document_verifications_path, notice: t("management.users.erased_notice") + end + def logout destroy_session redirect_to management_root_url, notice: t("management.sessions.signed_out_managed_user") diff --git a/app/views/management/document_verifications/new.html.erb b/app/views/management/document_verifications/new.html.erb index 068d84f41..100c2592e 100644 --- a/app/views/management/document_verifications/new.html.erb +++ b/app/views/management/document_verifications/new.html.erb @@ -13,3 +13,14 @@ <%= f.hidden_field :document_number %> <%= f.submit t("management.document_verifications.verify"), class: "button success" %> <% end %> + + +<%= link_to t("management.document_verifications.erase_account_link"), "#", class: "delete js-toggle-link", data: { "toggle-selector" => "#erase-account-form" } %> + + diff --git a/config/locales/management.en.yml b/config/locales/management.en.yml index 3f9a447b0..fb9929924 100644 --- a/config/locales/management.en.yml +++ b/config/locales/management.en.yml @@ -24,6 +24,10 @@ en: title: User management under_age: You must be over 16 to verify your account. verify: Verify + erase_account_link: Delete user + erase_account_confirm: Are you sure you want to erase the account? This action can not be undone + erase_warning: This action can not be undone. Please make sure you want to erase this account. + erase_submit: Delete account email_label: Email email_verifications: already_verified: This user account is already verified. @@ -84,3 +88,5 @@ en: create_user_info: 'We will create an account with the following data:' create_user_submit: Create user create_user_success_html: We have sent an email to the email address %{email} in order to verify that it belongs to this user. It contains a link they have to click. Then they will have to set their access password before being able to log in to the website + erased_notice: User account deleted. + erased_by_manager: "Deleted by manager: %{manager}" diff --git a/config/locales/management.es.yml b/config/locales/management.es.yml index 540bad027..262108652 100644 --- a/config/locales/management.es.yml +++ b/config/locales/management.es.yml @@ -24,6 +24,10 @@ es: title: Gestión de usuarios under_age: Debes ser mayor de 16 años para verificar tu cuenta. verify: Verificar usuario + erase_account_link: Borrar cuenta + erase_account_confirm: ¿Seguro que quieres borrar a este usuario? Esta acción no se puede deshacer + erase_warning: Esta acción no se puede deshacer. Por favor asegurese de que quiere eliminar esta cuenta. + erase_submit: Borrar cuenta email_label: Email email_verifications: already_verified: Esta cuenta de usuario ya está verificada. @@ -84,3 +88,5 @@ es: create_user_info: 'Procedemos a crear un usuario con la siguiente información:' create_user_submit: Crear usuario create_user_success_html: Hemos enviado un correo electrónico a %{email} para verificar que es suya. El correo enviado contiene un link que el usuario deberá pulsar. Entonces podrá seleccionar una clave de acceso, y entrar en la web de participación. + erased_notice: Cuenta de usuario borrada. + erased_by_manager: "Borrada por el manager: %{manager}" diff --git a/config/routes.rb b/config/routes.rb index 92bdf8601..b38823a65 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -214,7 +214,10 @@ Rails.application.routes.draw do resources :email_verifications, only: [:new, :create] resources :users, only: [:new, :create] do - delete :logout, on: :collection + collection do + delete :logout + delete :erase + end end get 'sign_in', to: 'sessions#create' diff --git a/spec/features/management/users_spec.rb b/spec/features/management/users_spec.rb index 31e4bbeeb..83ac9248a 100644 --- a/spec/features/management/users_spec.rb +++ b/spec/features/management/users_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' feature 'users' do - scenario 'Creating a level 3 user from scratch' do + scenario 'Create a level 3 user from scratch' do login_as_manager @@ -42,4 +42,29 @@ feature 'users' do expect(page).to have_content "Your account has been confirmed." end + scenario 'Delete a level 2 user account from document verification page', :js do + level_2_user = create(:user, :level_two, document_number: 13579) + login_as_manager + + visit management_document_verifications_path + fill_in 'document_verification_document_number', with: '13579' + click_button 'Check' + + expect(page).to_not have_content "This user account is already verified." + expect(page).to have_content "This user can participate in the website with the following permissions" + + click_link "Delete user" + click_link "Delete account" + + expect(page).to have_content "User account deleted." + + expect(level_2_user.reload.erase_reason).to eq "Deleted by manager: JJB042" + + visit management_document_verifications_path + fill_in 'document_verification_document_number', with: '13579' + click_button 'Check' + + expect(page).to have_content "no user account associated to it" + end + end \ No newline at end of file