This repository has been archived by the owner on Sep 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
WIP—Email sending #15
Open
zanedb
wants to merge
10
commits into
master
Choose a base branch
from
email-sending
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c0a788f
Require signin on fields controller
zanedb e6a84a6
Move custom_auth method to application
zanedb ec0c314
Remove old
zanedb 26f91ab
Add email_config model
zanedb eec795d
Add email model
zanedb 48100c9
Run migration
zanedb c74a601
Add emails controller
zanedb 5d94b59
Add emails policy
zanedb 945d22e
Add emails routes
zanedb d41c2da
Add email views
zanedb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
class EmailsController < ApplicationController | ||
before_action :please_sign_in | ||
before_action :set_event | ||
before_action :set_email, only: %i[show] | ||
before_action :custom_authorization, only: %i[index settings configure] | ||
|
||
def index | ||
end | ||
|
||
def show | ||
authorize @email | ||
end | ||
|
||
def new | ||
@email = @event.emails.new | ||
authorize @email | ||
end | ||
|
||
def create | ||
@email = @event.emails.new(email_params) | ||
authorize @email | ||
|
||
if @email.save | ||
redirect_to event_emails_path(@event) | ||
flash[:success] = 'Email will be sent shortly.' | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def settings | ||
@email_config = @event.email_config | ||
end | ||
|
||
def configure | ||
if @event.email_config.update(email_config_params) | ||
redirect_to event_emails_path(@event) | ||
flash[:success] = 'Email sending has been configured.' | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_email | ||
@email = @event.emails.find(params[:id]) | ||
end | ||
|
||
def email_params | ||
params.require(:email).permit(:recipient, :sender_email, :subject, :body) | ||
end | ||
|
||
def email_config_params | ||
params.require(:email_config).permit(:smtp_url, :smtp_port, :authentication, :domain, :sender_email, :username, :password) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Email < ApplicationRecord | ||
belongs_to :event | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class EmailConfig < ApplicationRecord | ||
belongs_to :event | ||
|
||
def enabled? | ||
true unless [ | ||
smtp_url, smtp_port, authentication, domain, sender_email, username, password | ||
].any?(&:nil?) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class EmailPolicy < ApplicationPolicy | ||
def show? | ||
record.event.users.include?(user) || user.admin? | ||
end | ||
|
||
def new? | ||
record.event.users.include?(user) || user.admin? | ||
end | ||
|
||
def create? | ||
record.event.users.include?(user) || user.admin? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<% title "Emails on #{@event.name}" %> | ||
<div class="breadcrumbs"> | ||
<%= link_to 'Home', root_url %> › <%= link_to 'Events', events_url %> › <%= link_to @event.name, @event %> | ||
</div> | ||
|
||
<h1 class="heading"> | ||
Emails | ||
<% if @event.email_config.enabled? %> | ||
<%= link_to 'Send an email', new_event_email_path, class: 'btn bg-success' %> | ||
<%= link_to 'Edit settings', settings_event_emails_path, class: 'btn bg-info' %> | ||
<% else %> | ||
<%= link_to 'Configure email sending', settings_event_emails_path, class: 'btn bg-info' %> | ||
<% end %> | ||
</h1> | ||
|
||
<% if @event.email_config.enabled? %> | ||
a | ||
<% else %> | ||
<p class="muted no-margin">Email sending hasn’t been configured.</p> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<% title "Editing email settings on #{@event.name}" %> | ||
<div class="breadcrumbs"> | ||
<%= link_to 'Home', root_url %> › <%= link_to 'Events', events_url %> › <%= link_to @event.name, @event %> › <%= link_to 'Emails', event_emails_path(@event) %> | ||
</div> | ||
<h1>Email Configuration</h1> | ||
|
||
<%= form_with(model: @email_config, local: true, url: configure_event_emails_path) do |form| %> | ||
<% if @email_config.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@email_config.errors.count, "error") %> prohibited this event from being saved:</h2> | ||
|
||
<ul> | ||
<% @email_config.errors.full_messages.each do |message| %> | ||
<li><%= message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="field"> | ||
<%= form.label :smtp_url %> | ||
<%= form.text_field :smtp_url %> | ||
</div> | ||
|
||
<div class="field"> | ||
<%= form.label :smtp_port %> | ||
<%= form.text_field :smtp_port %> | ||
</div> | ||
|
||
<div class="field"> | ||
<%= form.label :authentication %> | ||
<%= form.text_field :authentication, placeholder: 'PLAIN' %> | ||
</div> | ||
|
||
<div class="field"> | ||
<%= form.label :smtp_url %> | ||
<%= form.text_field :smtp_url %> | ||
</div> | ||
|
||
<div class="field"> | ||
<%= form.label :domain %> | ||
<%= form.text_field :domain %> | ||
</div> | ||
|
||
<div class="field"> | ||
<%= form.label :sender_email %> | ||
<%= form.text_field :sender_email %> | ||
</div> | ||
|
||
<div class="field"> | ||
<%= form.label :username %> | ||
<%= form.text_field :username %> | ||
</div> | ||
|
||
<div class="field"> | ||
<%= form.label :password %> | ||
<%= form.password_field :password %> | ||
</div> | ||
|
||
<div class="actions"> | ||
<%= form.submit 'Configure' %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class CreateEmailConfigs < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :email_configs do |t| | ||
t.string :smtp_url | ||
t.string :smtp_port | ||
t.string :authentication | ||
t.string :domain | ||
t.string :sender_email | ||
t.string :username | ||
t.string :password | ||
t.belongs_to :event, index: true | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CreateEmails < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :emails do |t| | ||
t.string :recipient | ||
t.string :sender_email | ||
t.text :subject | ||
t.text :body | ||
t.string :read_receipt_img_url | ||
t.string :read_receipt_stats_url | ||
t.belongs_to :event, index: true | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
one: | ||
enabled: false | ||
smtp_url: MyString | ||
smtp_port: MyString | ||
authentication: MyString | ||
domain: MyString | ||
sender_email: MyString | ||
username: MyString | ||
password: MyString | ||
|
||
two: | ||
enabled: false | ||
smtp_url: MyString | ||
smtp_port: MyString | ||
authentication: MyString | ||
domain: MyString | ||
sender_email: MyString | ||
username: MyString | ||
password: MyString |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
one: | ||
recipient: MyString | ||
sender_email: MyString | ||
subject: MyText | ||
body: MyText | ||
read_receipt_img_url: MyString | ||
read_receipt_stats_url: MyString | ||
|
||
two: | ||
recipient: MyString | ||
sender_email: MyString | ||
subject: MyText | ||
body: MyText | ||
read_receipt_img_url: MyString | ||
read_receipt_stats_url: MyString |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'test_helper' | ||
|
||
class EmailConfigTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'test_helper' | ||
|
||
class EmailTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eep