Skip to content

Commit

Permalink
Merge branch 'main' into add-personal-email
Browse files Browse the repository at this point in the history
* main:
  Bump ansi-regex from 4.1.0 to 4.1.1
  Bump semver from 5.7.1 to 5.7.2
  Run db:migrate
  Use email variables from method in teacher model
  Show the current values avaiable in email templates
  Filter commas from teacher names when sending emails.
  • Loading branch information
cycomachead committed Sep 26, 2023
2 parents d19f25a + 02c2fa9 commit 20d43f7
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 37 deletions.
15 changes: 4 additions & 11 deletions app/mailers/teacher_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,13 @@ def form_submission(teacher)

private
def liquid_assigns
{
teacher_first_name: @teacher.first_name,
teacher_last_name: @teacher.last_name,
teacher_email: @teacher.email,
teacher_more_info: @teacher.more_info,
teacher_school_name: @teacher.school.name,
teacher_school_city: @teacher.school.city,
teacher_school_state: @teacher.school.state,
teacher_snap: @teacher.snap,
teacher_school_website: @teacher.school.website,
base_rules = {
bjc_password: Rails.application.secrets[:bjc_password],
piazza_password: Rails.application.secrets[:piazza_password],
reason: @reason
}.with_indifferent_access
}
base_rules.merge!(@teacher.email_attributes)
base_rules.with_indifferent_access
end

def email_template
Expand Down
30 changes: 28 additions & 2 deletions app/models/teacher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ def full_name
end

def email_name
"#{full_name} <#{email}>"
# We need to normalize names for emails.
"#{full_name} <#{email}>".delete(",")
end

def snap_username
# TODO: use this method until we rename the column.
self.snap
end

def status=(value)
Expand Down Expand Up @@ -186,7 +192,27 @@ def try_append_ip(ip)
save
end


def email_attributes
# Used when passing data to liquid templates
{
teacher_first_name: self.first_name,
teacher_last_name: self.last_name,
teacher_full_name: self.full_name,
teacher_email: self.email,
teacher_personal_email: self.personal_email,
teacher_more_info: self.more_info,
teacher_snap: self.snap_username,
teacher_snap_username: self.snap_username,
teacher_education_level: self.education_level,
teacher_personal_website: self.personal_website,
teacher_teaching_status: self.text_status,
teacher_signed_up_at: self.created_at,
teacher_school_name: self.school.name,
teacher_school_city: self.school.city,
teacher_school_state: self.school.state,
teacher_school_website: self.school.website,
}
end
# TODO: Figure out how this should be used. store and check `uid` field
# def self.validate_access_token(omniauth)
# Teacher.find_by('LOWER(email) = ?', omniauth.email.downcase).present?
Expand Down
2 changes: 2 additions & 0 deletions app/views/email_templates/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
</div>
<% end %>

<%= render 'liquid_fields' %>

<script type="text/javascript">
tinyMCE.init({
selector: 'textarea.tinymce',
Expand Down
31 changes: 31 additions & 0 deletions app/views/email_templates/_liquid_fields.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<hr>
<h3>Allowed Tags</h3>
<p>Use the following tags in the email body. The example shows your current values.</p>
<table class="table table-striped">
<thead>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<%- current_user.email_attributes.each do |key, value| %>
<tr>
<td><code><%= "{{#{key}}}" %></code></td>
<td><%= value %></td>
</tr>
<%- end %>
<tr>
<td><code>{{bjc_password}}</code></td>
<td>(Should no longer be relevant)</td>
</tr>
<tr>
<td><code>{{piazza_password}}</code></td>
<td>(The current piazza sign up password)</td>
</tr>
<tr>
<td><code>{{reason}}</code></td>
<td>(Only on denial emails.)</td>
</tr>
</tbody>
</table>
7 changes: 6 additions & 1 deletion spec/models/teacher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,15 @@

let(:teacher) { teachers(:bob) }

it "shows email names correct" do
it "formats a proper email name" do
expect(teacher.email_name).to eq "Bob Johnson <[email protected]>"
end

it "formats a proper email name filtering commas" do
teacher.update(last_name: "Johnson, III")
expect(teacher.email_name).to eq "Bob Johnson III <[email protected]>"
end

it "should be valid" do
expect(teacher.valid?).to be true
end
Expand Down
29 changes: 6 additions & 23 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1531,9 +1531,9 @@ ansi-html-community@^0.0.8:
integrity sha512-1APHAyr3+PCamwNw3bXCPp4HFLONZt/yIH0sZp0/469KWNTEy+qN5jQ3GVX6DMZ1UXAi34yVwtTeaG/HpBuuzw==

ansi-regex@^4.1.0:
version "4.1.0"
resolved "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz"
integrity sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==
version "4.1.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.1.tgz#164daac87ab2d6f6db3a29875e2d1766582dabed"
integrity sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==

ansi-styles@^3.2.0, ansi-styles@^3.2.1:
version "3.2.1"
Expand Down Expand Up @@ -6275,40 +6275,23 @@ selfsigned@^2.1.1:
dependencies:
node-forge "^1"

semver@^5.5.0:
version "5.7.1"
resolved "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz"
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==

semver@^5.6.0:
semver@^5.5.0, semver@^5.6.0:
version "5.7.2"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.2.tgz#48d55db737c3287cd4835e17fa13feace1c41ef8"
integrity sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==

semver@^6.0.0, semver@^6.3.0:
version "6.3.0"
resolved "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==

semver@^6.3.1:
semver@^6.0.0, semver@^6.3.0, semver@^6.3.1:
version "6.3.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4"
integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==

semver@^7.3.2:
semver@^7.3.2, semver@^7.3.5:
version "7.5.4"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e"
integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==
dependencies:
lru-cache "^6.0.0"

semver@^7.3.5:
version "7.3.5"
resolved "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz"
integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==
dependencies:
lru-cache "^6.0.0"

[email protected]:
version "0.18.0"
resolved "https://registry.yarnpkg.com/send/-/send-0.18.0.tgz#670167cc654b05f5aa4a767f9113bb371bc706be"
Expand Down

0 comments on commit 20d43f7

Please sign in to comment.