From b892d4006f3c8ba89a29d9d62f105e2dda7c17a7 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sat, 30 Nov 2024 19:09:04 +0100 Subject: [PATCH 1/3] Configure letter opener to read emails via web UI --- Gemfile | 1 + Gemfile.lock | 13 +++++++++++++ app/controllers/application_controller.rb | 2 +- app/controllers/users/confirmations_controller.rb | 5 ++++- config/environments/development.rb | 6 +++--- config/routes.rb | 3 +++ nginx.conf | 5 +++++ 7 files changed, 30 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 24f8631..cc2ec6e 100644 --- a/Gemfile +++ b/Gemfile @@ -35,6 +35,7 @@ end group :development do gem 'rubocop' gem 'web-console' + gem 'letter_opener_web' end gem 'chroma' diff --git a/Gemfile.lock b/Gemfile.lock index 339a1c5..d4af6c3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -88,6 +88,8 @@ GEM bootsnap (1.18.4) msgpack (~> 1.2) builder (3.3.0) + childprocess (5.1.0) + logger (~> 1.5) chroma (0.2.0) coderay (1.1.3) concurrent-ruby (1.3.4) @@ -150,6 +152,16 @@ GEM jsonapi-serializable (0.3.1) jsonapi-renderer (~> 0.2.0) language_server-protocol (3.17.0.3) + launchy (3.0.1) + addressable (~> 2.8) + childprocess (~> 5.0) + letter_opener (1.10.0) + launchy (>= 2.2, < 4) + letter_opener_web (3.0.0) + actionmailer (>= 6.1) + letter_opener (~> 1.9) + railties (>= 6.1) + rexml license_finder (7.2.1) bundler csv (~> 3.2) @@ -386,6 +398,7 @@ DEPENDENCIES importmap-rails jbuilder jsonapi-rails + letter_opener_web license_finder money pg (~> 1.1) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ef8cf29..0d2a0c7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -31,7 +31,7 @@ class ApplicationController < ActionController::Base def development_swagger? Rails.env.test? || - Rails.env.development? && request.headers['referer'].include?('/api-docs/index.html') + Rails.env.development? && request.headers['referer']&.include?('/api-docs/index.html') end def set_csrf_cookie diff --git a/app/controllers/users/confirmations_controller.rb b/app/controllers/users/confirmations_controller.rb index 5708a64..a6e3280 100644 --- a/app/controllers/users/confirmations_controller.rb +++ b/app/controllers/users/confirmations_controller.rb @@ -5,7 +5,10 @@ class Users::ConfirmationsController < Devise::ConfirmationsController def show super do |resource| if resource.errors.empty? - render json: resource, status: :ok + respond_to do |format| + format.json { render json: resource, status: :ok } + format.any { redirect_to root_path } + end else render json: { message: 'Record invalid', diff --git a/config/environments/development.rb b/config/environments/development.rb index 501a213..b3b6593 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -40,10 +40,10 @@ Rails.application.configure do # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false - config.action_mailer.perform_caching = false - - config.action_mailer.default_url_options = { host: 'libre-wedding-planner.app.localhost' } + config.action_mailer.default_url_options = { host: 'libre-wedding-planner.app.localhost/api' } + config.action_mailer.delivery_method = :letter_opener_web + config.action_mailer.perform_deliveries = true # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log diff --git a/config/routes.rb b/config/routes.rb index 4599490..35fd068 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,7 @@ # Copyright (C) 2024 Manuel Bustillo Rails.application.routes.draw do + mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development? devise_for :users, skip: [:registration, :session, :confirmation] devise_scope :user do post 'users', to: 'users/registrations#create' @@ -23,4 +24,6 @@ Rails.application.routes.draw do resources :tables_arrangements, only: %i[index show] get 'up' => 'rails/health#show', as: :rails_health_check + + root to: redirect('/dashboard') end diff --git a/nginx.conf b/nginx.conf index 995c062..06d059b 100644 --- a/nginx.conf +++ b/nginx.conf @@ -7,6 +7,11 @@ server { proxy_set_header Host $http_host; } + location /letter_opener/ { + proxy_pass http://backend:3000/letter_opener/; + proxy_set_header Host $http_host; + } + location / { proxy_pass http://frontend:3000; proxy_set_header Host $http_host; From 2889dc5c98104b67eed41831a7fff995d4595833 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sat, 30 Nov 2024 19:12:13 +0100 Subject: [PATCH 2/3] Update README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 93a449f..8e8d48e 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,10 @@ The backend, frontend and workers have hot-reloading enabled, so changes made to Once all containers have started, visit http://libre-wedding-planner.app.localhost/dashboard to load the application. +## Email delivery + +In the development environment, real emails will not be sent. You can visit http://libre-wedding-planner.app.localhost/letter_opener/ to get a list of emails generated by the application. + ## Testing Unit tests can be executed with From 7803df74940d26295efe71ec0a9427815ecc1b7f Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sat, 30 Nov 2024 18:14:58 +0000 Subject: [PATCH 3/3] Add copyright notice --- app/controllers/users/confirmations_controller.rb | 2 ++ spec/requests/users/confirmations_spec.rb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/controllers/users/confirmations_controller.rb b/app/controllers/users/confirmations_controller.rb index a6e3280..660d263 100644 --- a/app/controllers/users/confirmations_controller.rb +++ b/app/controllers/users/confirmations_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2024 Manuel Bustillo + class Users::ConfirmationsController < Devise::ConfirmationsController clear_respond_to respond_to :json diff --git a/spec/requests/users/confirmations_spec.rb b/spec/requests/users/confirmations_spec.rb index 77355ca..e99794e 100644 --- a/spec/requests/users/confirmations_spec.rb +++ b/spec/requests/users/confirmations_spec.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2024 Manuel Bustillo + require 'swagger_helper' RSpec.describe 'users/confirmations', type: :request do