Skip to content

Commit

Permalink
moving to mailtrap from sendgrid
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasConnolly committed Aug 6, 2023
1 parent 7038acc commit c80218f
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ yarn-debug.log*
!/app/assets/builds/.keep

/config/credentials/development.key
401ErrorHandle.rb
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ gem 'jbuilder'
gem 'jsbundling-rails'
gem 'loofah'
# gem 'madmin'
gem 'mail'
gem 'mailtrap'
gem 'matrix'
gem 'mini_magick'
gem 'nested_scaffold'
Expand Down
5 changes: 3 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ GEM
rake (>= 10.4, < 14.0)
ast (2.4.2)
aws-eventstream (1.2.0)
aws-partitions (1.797.0)
aws-partitions (1.798.0)
aws-sdk-core (3.121.5)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.520.1)
Expand Down Expand Up @@ -268,6 +268,7 @@ GEM
net-imap
net-pop
net-smtp
mailtrap (1.2.1)
marcel (1.0.2)
matrix (0.4.2)
method_source (1.0.0)
Expand Down Expand Up @@ -585,7 +586,7 @@ DEPENDENCIES
letter_opener_web
listen
loofah
mail
mailtrap
matrix
mini_magick
nested_scaffold
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/vnotes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def vnote_params

def vestry_only
unless current_user.roles.include?("vestry")
redirect_to(root_path, alert: "You must be a member of the St. Paul
redirect_to(root_path, alert: "You must be a member of St. Paul's
Vestry to use this function.")
end
end
Expand Down
3 changes: 2 additions & 1 deletion app/mailers/vnote_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# frozen_string_literal: true

class VnoteMailer < ApplicationMailer
default to: proc { User.where(" 'vestry' = ANY (roles)").pluck(:email) }


def vnote_created(vnote)
@vnote = vnote
@url = vnote_url(@vnote)
mail(
to: User.vestry.pluck(:email),
subject: "There's a new topic on the vestry forum.",
)
end
Expand Down
19 changes: 11 additions & 8 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class User < ApplicationRecord
validates :email, presence: true, uniqueness: { case_sensitive: false }
after_save :add_profile
after_create :set_default_role, if: :new_record?
# after_save :maybe_add_stripe_id
after_save :maybe_add_stripe_id
after_destroy :cancel_stripe_customer
has_many :posts, dependent: :destroy
has_many :comments, dependent: :destroy
Expand All @@ -58,7 +58,7 @@ class User < ApplicationRecord
# honey used to prevent bots-filled forms from being saved to db
validates :honey, absence: true


scope :vestry, -> { where(" 'vestry' = ANY (roles)") }

# Include default devise modules
# Others available are:
Expand All @@ -70,17 +70,20 @@ class User < ApplicationRecord
:confirmable,
:trackable

# def maybe_add_stripe_id
# return unless stripe_id.blank?

# customer = Stripe::Customer.create(email:)
# update(stripe_id: customer.id)
# end
def maybe_add_stripe_id
return unless stripe_id.blank?
customer = Stripe::Customer.create(email:)
update(stripe_id: customer.id)
end

def cancel_stripe_customer
Stripe::Customer.delete(self.stripe_id) if self.stripe_id
end

def vestry?
roles.include?('vestry')
end

def add_profile
create_profile if profile.nil?
end
Expand Down
11 changes: 11 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@

config.action_mailer.perform_caching = false

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:user_name => ENV['MAILTRAP_USERNAME'],
:password => ENV['MAILTRAP_PASSWORD'],
:address => 'smtp.mailtrap.io',
:domain => 'smtp.mailtrap.io',
:port => '2525',
:authentication => :cram_md5
}


# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
Expand Down
99 changes: 99 additions & 0 deletions log/development.log
Original file line number Diff line number Diff line change
Expand Up @@ -4062,3 +4062,102 @@ Processing by VnotesController#show as HTML
Completed 200 OK in 28ms (Views: 23.6ms | ActiveRecord: 1.2ms | Allocations: 12066)


Started DELETE "/vnotes/10" for 127.0.0.1 at 2023-08-03 13:54:32 -0400
Processing by VnotesController#destroy as TURBO_STREAM
Parameters: {"id"=>"10"}
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 798], ["LIMIT", 1]]
Vnote Load (0.2ms) SELECT "vnotes".* FROM "vnotes" WHERE "vnotes"."id" = $1 ORDER BY created_at DESC LIMIT $2 [["id", 10], ["LIMIT", 1]]
↳ app/controllers/vnotes_controller.rb:55:in `set_vnote'
TRANSACTION (0.1ms) BEGIN
↳ app/controllers/vnotes_controller.rb:48:in `destroy'
Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."commentable_id" = $1 AND "comments"."commentable_type" = $2 [["commentable_id", 10], ["commentable_type", "Vnote"]]
↳ app/controllers/vnotes_controller.rb:48:in `destroy'
ActionText::RichText Load (0.1ms) SELECT "action_text_rich_texts".* FROM "action_text_rich_texts" WHERE "action_text_rich_texts"."record_id" = $1 AND "action_text_rich_texts"."record_type" = $2 AND "action_text_rich_texts"."name" = $3 LIMIT $4 [["record_id", 10], ["record_type", "Vnote"], ["name", "content"], ["LIMIT", 1]]
↳ app/controllers/vnotes_controller.rb:48:in `destroy'
ActiveStorage::Attachment Load (0.1ms) SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = $1 AND "active_storage_attachments"."record_type" = $2 AND "active_storage_attachments"."name" = $3 [["record_id", 237], ["record_type", "ActionText::RichText"], ["name", "embeds"]]
↳ app/controllers/vnotes_controller.rb:48:in `destroy'
ActionText::RichText Destroy (0.2ms) DELETE FROM "action_text_rich_texts" WHERE "action_text_rich_texts"."id" = $1 [["id", 237]]
↳ app/controllers/vnotes_controller.rb:48:in `destroy'
Vnote Destroy (0.1ms) DELETE FROM "vnotes" WHERE "vnotes"."id" = $1 [["id", 10]]
↳ app/controllers/vnotes_controller.rb:48:in `destroy'
TRANSACTION (3.5ms) COMMIT
↳ app/controllers/vnotes_controller.rb:48:in `destroy'
Redirected to http://localhost:5000/vnotes
Completed 303 See Other in 13ms (ActiveRecord: 4.6ms | Allocations: 7959)


Started GET "/vnotes" for 127.0.0.1 at 2023-08-03 13:54:32 -0400
Processing by VnotesController#index as TURBO_STREAM
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 798], ["LIMIT", 1]]
Rendering layout layouts/application.html.erb
Rendering vnotes/index.html.erb within layouts/application
Vnote Load (0.2ms) SELECT "vnotes".* FROM "vnotes" ORDER BY created_at DESC
↳ app/views/vnotes/index.html.erb:15
Comment Load (0.2ms) SELECT "comments".* FROM "comments" WHERE "comments"."commentable_type" = $1 AND "comments"."commentable_id" IN ($2, $3, $4, $5, $6, $7, $8, $9, $10) [["commentable_type", "Vnote"], ["commentable_id", 9], ["commentable_id", 8], ["commentable_id", 7], ["commentable_id", 6], ["commentable_id", 5], ["commentable_id", 4], ["commentable_id", 3], ["commentable_id", 2], ["commentable_id", 1]]
↳ app/views/vnotes/index.html.erb:15
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 16], ["LIMIT", 1]]
↳ app/views/vnotes/index.html.erb:18
CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 16], ["LIMIT", 1]]
↳ app/views/vnotes/index.html.erb:18
CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 16], ["LIMIT", 1]]
↳ app/views/vnotes/index.html.erb:18
CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 16], ["LIMIT", 1]]
↳ app/views/vnotes/index.html.erb:18
CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 16], ["LIMIT", 1]]
↳ app/views/vnotes/index.html.erb:18
CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 16], ["LIMIT", 1]]
↳ app/views/vnotes/index.html.erb:18
CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 16], ["LIMIT", 1]]
↳ app/views/vnotes/index.html.erb:18
CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 16], ["LIMIT", 1]]
↳ app/views/vnotes/index.html.erb:18
CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 16], ["LIMIT", 1]]
↳ app/views/vnotes/index.html.erb:18
Rendered vnotes/index.html.erb within layouts/application (Duration: 10.3ms | Allocations: 9167)
Rendered layouts/_header.html.erb (Duration: 1.3ms | Allocations: 1044)
Profile Load (0.2ms) SELECT "profiles".* FROM "profiles" WHERE "profiles"."user_id" = $1 LIMIT $2 [["user_id", 798], ["LIMIT", 1]]
↳ app/views/layouts/_navbar.html.erb:8
Rendered layouts/_navbar.html.erb (Duration: 1.8ms | Allocations: 1855)
Rendered layouts/_footer.html.erb (Duration: 0.1ms | Allocations: 78)
Rendered layout layouts/application.html.erb (Duration: 14.3ms | Allocations: 12713)
Completed 200 OK in 17ms (Views: 13.8ms | ActiveRecord: 0.9ms | Allocations: 14522)


Started GET "/vnotes/9" for 127.0.0.1 at 2023-08-03 13:54:41 -0400
Processing by VnotesController#show as HTML
Parameters: {"id"=>"9"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 798], ["LIMIT", 1]]
Vnote Load (0.3ms) SELECT "vnotes".* FROM "vnotes" WHERE "vnotes"."id" = $1 ORDER BY created_at DESC LIMIT $2 [["id", 9], ["LIMIT", 1]]
↳ app/controllers/vnotes_controller.rb:55:in `set_vnote'
Rendering layout layouts/application.html.erb
Rendering vnotes/show.html.erb within layouts/application
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 16], ["LIMIT", 1]]
↳ app/views/vnotes/show.html.erb:8
ActionText::RichText Load (0.2ms) SELECT "action_text_rich_texts".* FROM "action_text_rich_texts" WHERE "action_text_rich_texts"."record_id" = $1 AND "action_text_rich_texts"."record_type" = $2 AND "action_text_rich_texts"."name" = $3 LIMIT $4 [["record_id", 9], ["record_type", "Vnote"], ["name", "content"], ["LIMIT", 1]]
↳ app/views/vnotes/show.html.erb:10
Rendered /usr/share/rvm/gems/ruby-3.2.2/gems/actiontext-7.0.6/app/views/action_text/contents/_content.html.erb within layouts/action_text/contents/_content (Duration: 0.6ms | Allocations: 432)
Rendered comments/_form.html.erb (Duration: 0.6ms | Allocations: 510)
Comment Load (0.2ms) SELECT "comments".* FROM "comments" WHERE "comments"."commentable_id" = $1 AND "comments"."commentable_type" = $2 [["commentable_id", 9], ["commentable_type", "Vnote"]]
↳ app/views/comments/_comments.html.erb:3
Rendered comments/_comments.html.erb (Duration: 0.7ms | Allocations: 706)
Rendered vnotes/show.html.erb within layouts/application (Duration: 4.7ms | Allocations: 3830)
Rendered layouts/_header.html.erb (Duration: 0.7ms | Allocations: 1043)
Profile Load (0.2ms) SELECT "profiles".* FROM "profiles" WHERE "profiles"."user_id" = $1 LIMIT $2 [["user_id", 798], ["LIMIT", 1]]
↳ app/views/layouts/_navbar.html.erb:8
Rendered layouts/_navbar.html.erb (Duration: 1.6ms | Allocations: 1855)
Rendered layouts/_footer.html.erb (Duration: 0.1ms | Allocations: 78)
Rendered layout layouts/application.html.erb (Duration: 8.2ms | Allocations: 7360)
Completed 200 OK in 12ms (Views: 7.6ms | ActiveRecord: 1.3ms | Allocations: 9911)


User Pluck (1.5ms) SELECT "users"."email" FROM "users" WHERE ( 'vestry' = ANY (:roles))
User Pluck (1.2ms) SELECT "users"."email" FROM "users" WHERE ( 'vestry' = ANY (roles))
User Pluck (0.9ms) SELECT "users"."email" FROM "users" WHERE ( 'vestry' = ANY (roles))
User Load (0.3ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT $1 [["LIMIT", 1]]
TRANSACTION (0.6ms) BEGIN
User Exists? (0.9ms) SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER($1) AND "users"."id" != $2 LIMIT $3 [["email", "mldogo@me.com"], ["id", 798], ["LIMIT", 1]]
ActiveStorage::Attachment Load (0.6ms) SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = $1 AND "active_storage_attachments"."record_type" = $2 AND "active_storage_attachments"."name" = $3 LIMIT $4 [["record_id", 798], ["record_type", "User"], ["name", "avatar"], ["LIMIT", 1]]
User Update (1.0ms) UPDATE "users" SET "email" = $1, "updated_at" = $2 WHERE "users"."id" = $3 [["email", "mldogo@me.com"], ["updated_at", "2023-08-04 02:19:35.483137"], ["id", 798]]
Profile Load (0.4ms) SELECT "profiles".* FROM "profiles" WHERE "profiles"."user_id" = $1 LIMIT $2 [["user_id", 798], ["LIMIT", 1]]
TRANSACTION (3.7ms) COMMIT
User Pluck (0.9ms) SELECT "users"."email" FROM "users" WHERE ( 'vestry' = ANY (roles))

0 comments on commit c80218f

Please sign in to comment.