diff --git a/.github/workflows/test_and_deploy.yml b/.github/workflows/test_and_deploy.yml index c4176979e..f9c576122 100644 --- a/.github/workflows/test_and_deploy.yml +++ b/.github/workflows/test_and_deploy.yml @@ -30,8 +30,18 @@ jobs: run: bundle install - name: Load schema run: bundle exec rake db:schema:load + - name: Setup hosts + run: | + echo ' + + 127.0.0.1 test.localmumuki.io + ' | sudo tee -a /etc/hosts + - name: Setup Xvfb + run: Xvfb :99 & - name: Run tests run: bundle exec rake + env: + DISPLAY: :99 test-firefox: env: diff --git a/Gemfile b/Gemfile index 7e379383c..f2cfb1878 100644 --- a/Gemfile +++ b/Gemfile @@ -8,6 +8,7 @@ gem 'puma' gem 'execjs' gem 'therubyracer', platforms: :ruby gem 'uglifier', '~> 2.7' +gem 'mumuki-domain', github: 'mumuki/mumuki-domain', branch: 'feature-delete-user-account' group :test do gem 'rspec-rails', '~> 3.6' diff --git a/README.md b/README.md index d46d198ae..d4a921c17 100644 --- a/README.md +++ b/README.md @@ -205,6 +205,17 @@ o.reindex_usages! Now you will be able to visit that guide at `http://localhost:3000/central/guides/#{slug}` +## Debugging email sender + +The development environment is configured to "send" emails via `mailcatcher`, a mock server, if it is available. Run these commands to install and run it - and do it _before_ the emails are sent, so it can actually _catch_ them: + +```bash +gem install mailcatcher +mailcatcher +``` + +Once up and running, go to http://localhost:1080/ to see which emails have been sent. Unfortunately, the developers recommend not to install it via Bundler, so it has to be done this way. :woman_shrugging: + ## JavaScript API Docs In order to be customized by runners, Laboratory exposes the following selectors and methods diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 56998ab41..f14b53cc0 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -41,6 +41,27 @@ def unsubscribe redirect_to root_path, notice: t(:unsubscribed_successfully) end + def delete_request + end + + def send_delete_confirmation_email + current_user.generate_delete_account_token! + UserMailer.delete_account(current_user).deliver_now + redirect_to delete_request_user_path + end + + def delete_confirmation + redirect_to delete_confirmation_invalid_user_path unless @user.delete_account_token_matches? params[:token] + end + + def delete_confirmation_invalid + end + + def disable + current_user.disable! + redirect_to root_path + end + def permissible_params super << [:avatar_id, :avatar_type] end diff --git a/app/helpers/mailer_helper.rb b/app/helpers/mailer_helper.rb new file mode 100644 index 000000000..1267efd51 --- /dev/null +++ b/app/helpers/mailer_helper.rb @@ -0,0 +1,11 @@ +module MailerHelper + def delete_account_url_for(user) + delete_confirmation_user_url host: organic_domain_for(user), token: user.delete_account_token + end + + private + + def organic_domain_for(user) + Mumukit::Platform.laboratory.organic_domain(user.last_organization) + end +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 8900a21ac..8cdc76634 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,5 +1,6 @@ class ApplicationMailer < ActionMailer::Base default from: Rails.configuration.reminder_sender_email + add_template_helper MailerHelper layout 'mailer' def self.mailer_environment_variables diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index d69b21136..040c42559 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -20,6 +20,12 @@ def no_submissions_reminder(user) end end + def delete_account(user) + with_locale(user) do + build_email t(:delete_account_mumuki), 'delete_account' + end + end + def certificate(certificate) with_locale certificate.user, certificate.organization do attachments[certificate.filename] = pdf_for(certificate) diff --git a/app/views/layouts/_organization_chooser.html.erb b/app/views/layouts/_organization_chooser.html.erb index 203372050..4119f3bff 100644 --- a/app/views/layouts/_organization_chooser.html.erb +++ b/app/views/layouts/_organization_chooser.html.erb @@ -1,4 +1,4 @@ -