From d77bd87acb748283a78f2258bff3723d55b791fb Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Mon, 29 Jan 2024 01:13:41 +0200 Subject: [PATCH] add account removal button --- app/controllers/accounts_controller.rb | 12 ++++++++++++ app/views/accounts/show.html.erb | 6 ++++++ config/routes.rb | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 15bdcacf..38cf5477 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -37,6 +37,18 @@ class AccountsController < ApplicationController render :show, status: :unprocessable_entity end + def destroy + authorize!(:manage, current_account) + + true_user.update!(locked_at: Time.current) + + render turbo_stream: turbo_stream.replace( + :account_delete_button, + html: helpers.tag.p('Your account removal request will be processed within 2 weeks. ' \ + 'Please contact us if you want to keep your account.') + ) + end + private def load_account diff --git a/app/views/accounts/show.html.erb b/app/views/accounts/show.html.erb index 06c86853..5d3916a9 100644 --- a/app/views/accounts/show.html.erb +++ b/app/views/accounts/show.html.erb @@ -65,6 +65,12 @@ <% end %> <% end %> + <% if can?(:manage, current_account) && Docuseal.multitenant? && true_user == current_user %> +
+

Danger Zone

+ <%= button_to button_title(title: 'Delete my account'), settings_account_path, class: 'btn btn-outline btn-error block', data: { turbo_confirm: 'Schedule account for deletion?' }, method: :delete, id: :account_delete_button %> +
+ <% end %>
diff --git a/config/routes.rb b/config/routes.rb index 3d26f247..118335df 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -116,7 +116,7 @@ Rails.application.routes.draw do resource :personalization, only: %i[show create], controller: 'personalization_settings' resources :api, only: %i[index create], controller: 'api_settings' resource :webhooks, only: %i[show create update], controller: 'webhook_settings' - resource :account, only: %i[show update] + resource :account, only: %i[show update destroy] resources :profile, only: %i[index] do collection do patch :update_contact