diff --git a/.env.example b/.env.example index 1322ce5354..2c113aa380 100644 --- a/.env.example +++ b/.env.example @@ -5,6 +5,7 @@ APP_BASE_URL="" DATABASE_URL="postgres://root:password@localhost/miru_web?encoding=utf8&pool=5&timeout=5000" # Mailer Configuration +EMAIL_DELIVERY_METHOD='letter_opener' MAILER_SENDER="info@miru.saeloun.com" # SendGrid Email Configuration diff --git a/Gemfile b/Gemfile index a186b2cd49..da86a17783 100644 --- a/Gemfile +++ b/Gemfile @@ -69,6 +69,9 @@ gem "sass-rails" gem "dotenv-rails" gem "foreman" +# Letter opener can be configured to avoid sending sending actual emails whenever required. +gem "letter_opener_web" + group :development, :test do # See https://edgeguides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem gem "debug", ">= 1.0.0", platforms: %i[mri mingw x64_mingw] diff --git a/Gemfile.lock b/Gemfile.lock index 7e626023b9..f46af53e6f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -133,6 +133,11 @@ GEM addressable (~> 2.7) letter_opener (1.7.0) launchy (~> 2.2) + letter_opener_web (2.0.0) + actionmailer (>= 5.2) + letter_opener (~> 1.7) + railties (>= 5.2) + rexml loofah (2.13.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -149,6 +154,8 @@ GEM nokogiri (1.12.5) mini_portile2 (~> 2.6.1) racc (~> 1.4) + nokogiri (1.12.5-x86_64-linux) + racc (~> 1.4) orm_adapter (0.5.0) parallel (1.21.0) parser (3.0.3.2) @@ -319,6 +326,7 @@ DEPENDENCIES foreman jbuilder (~> 2.11) letter_opener + letter_opener_web pg puma (~> 5.0) rack-mini-profiler (>= 2.3.3) diff --git a/README.md b/README.md index 30a0e2565f..4a3802e292 100644 --- a/README.md +++ b/README.md @@ -6,35 +6,64 @@ Saeloun timetracking application. ### Installation -* Step 1: Clone repo to local +- Step 1: Clone repo to local + ``` git clone https://github.com/saeloun/miru-web.git ``` -* Step 2: Install ruby 3.0.3 + +- Step 2: Install ruby 3.0.3 + ``` rvm install $(cat .ruby-version) ``` -* Step 3: Install Node 16.4.2 + +- Step 3: Install Node 16.4.2 + ``` nvm install $(cat .nvmrc) ``` -* Step 4: Install Postgres + +- Step 4: Install Postgres + ``` brew install postgresql ``` -* Step 5: Install gem + +- Step 5: Install gem + ``` bundle install ``` -* Step 6: Install node packages + +- Step 6: Install node packages + ``` yarn install ``` -* Step 7: Setup ENV's + +- Step 7: Setup ENV's + ``` cp .env.example .env ``` -* Step 8: Running app in local + +- Step 8: Running app in local + ``` foreman start -f Procfile.dev ``` + +### To receive the emails in non-production apps. + +Go to `/sent_emails` for accessing the emails. + +## Testing in Review apps + +### User Test credentials + +| Role | Email | Password | +| -------- | ------------------- | -------- | +| Owner | vipul@example.com | password | +| Admin | supriya@example.com | password | +| Employee | akhil@example.com | password | diff --git a/app.json b/app.json index a6c41cceed..83ab30f419 100644 --- a/app.json +++ b/app.json @@ -6,6 +6,20 @@ "plan": "heroku-postgresql:hobby-dev" } ], + "env": { + "MAILER_SENDER": { + "description": "The email address to use as the sender", + "value": "miru-review@saeloun.com" + }, + "EMAIL_DELIVERY_METHOD": { + "description": "The email delivery method to use", + "value": "letter_opener_web" + }, + "JWT_SECRET_KEY": { + "description": "The secret key for the JWT", + "value": "fc68556be046e0972ccd4608d10aa36f01adf7fd9eeae05c792308f973be79c055f0a72f8b76cd5aa0740622d263a93c2b3f6e51ad2873afda81e6a0724884c2" + } + }, "buildpacks": [ { "url": "heroku/nodejs" diff --git a/config/application.rb b/config/application.rb index a72fb94fc8..86c55276ae 100644 --- a/config/application.rb +++ b/config/application.rb @@ -26,5 +26,9 @@ class Application < Rails::Application end config.react.server_renderer_extensions = ["jsx", "js", "tsx", "ts"] + + if email_delivery_method = ENV["EMAIL_DELIVERY_METHOD"] + config.action_mailer.delivery_method = email_delivery_method.to_sym + end end end diff --git a/config/environments/production.rb b/config/environments/production.rb index bbdb0f5065..152eaa6bda 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -122,7 +122,7 @@ # config.active_record.shard_resolver = ->(request) { Tenant.find_by!(host: request.host).shard } # Action Mailer Configuration - host = ENV.fetch("APP_BASE_URL", "localhost") + host = ENV.fetch("APP_BASE_URL", "#{ENV["HEROKU_APP_NAME"] + ".herokuapp.com"}") config.action_mailer.default_url_options = { host: host } config.action_mailer.asset_host = host end diff --git a/config/routes.rb b/config/routes.rb index 6d8f9cc3f3..da33e2e18c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,4 +7,9 @@ root to: "application#redirect_path" resources :dashboard, only: [:index] resources :time_trackings, only: [:index], path: "time-tracking" + + # For opening the email in the web browser in non production environments + if ENV["EMAIL_DELIVERY_METHOD"] == "letter_opener_web" + mount LetterOpenerWeb::Engine, at: "/sent_emails" + end end diff --git a/db/seeds.rb b/db/seeds.rb index 0664d1be66..12c1677c1d 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). # @@ -6,3 +7,12 @@ # # movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }]) # Character.create(name: "Luke", movie: movies.first) + +# Create Owner user +User.create(first_name: "Vipul", last_name: "A M", email: "vipul@example.com", password: "password", password_confirmation: "password", role: "owner", confirmed_at: DateTime.now) + +# Create Admin user +User.create(first_name: "Supriya", last_name: "Agarwal", email: "supriya@example.com", password: "password", password_confirmation: "password", role: "admin", confirmed_at: DateTime.now) + +# Create Employee User +User.create(first_name: "Akhil", last_name: "G Krishnan", email: "akhil@example.com", password: "password", password_confirmation: "password", role: "employee", confirmed_at: DateTime.now)