Skip to content

Commit

Permalink
Add project approval requests
Browse files Browse the repository at this point in the history
- Add Projects context module
- Add tracking for created, requested approval, approved
- Add boolean on model for indicating if a project has requested approval
- Add project approval request email
- Add project approved email
- Clarify the template config vars
  • Loading branch information
joshsmith committed Dec 1, 2017
1 parent 21e9f53 commit 5da352a
Show file tree
Hide file tree
Showing 27 changed files with 659 additions and 38 deletions.
6 changes: 4 additions & 2 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ config :code_corps, CodeCorps.Mailer, adapter: Bamboo.LocalAdapter
config :code_corps,
postmark_forgot_password_template: "123",
postmark_organization_invite_email_template: "123",
postmark_project_acceptance_template: "123",
postmark_project_request_template: "123",
postmark_project_approval_request_template: "123",
postmark_project_approved_template: "123",
postmark_project_user_acceptance_template: "123",
postmark_project_user_request_template: "123",
postmark_receipt_template: "123"

# If the dev environment has no CLOUDEX_API_KEY set, we want the app
Expand Down
6 changes: 4 additions & 2 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ config :code_corps, CodeCorps.Mailer,
config :code_corps,
postmark_forgot_password_template: "1989483",
postmark_organization_invite_email_template: "3441863",
postmark_project_acceptance_template: "1447041",
postmark_project_request_template: "4017262",
postmark_project_approval_request_template: "4105824",
postmark_project_approved_template: "4105822",
postmark_project_user_acceptance_template: "1447041",
postmark_project_user_request_template: "4017262",
postmark_receipt_template: "1255222"

# ## SSL Support
Expand Down
6 changes: 4 additions & 2 deletions config/remote-development.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ config :code_corps, CodeCorps.Mailer,
config :code_corps,
postmark_forgot_password_template: "123",
postmark_organization_invite_email_template: "123",
postmark_project_acceptance_template: "123",
postmark_project_request_template: "123",
postmark_project_approval_request_template: "123",
postmark_project_approved_template: "123",
postmark_project_user_acceptance_template: "123",
postmark_project_user_request_template: "123",
postmark_receipt_template: "123"

# ## SSL Support
Expand Down
6 changes: 4 additions & 2 deletions config/staging.exs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ config :code_corps, CodeCorps.Mailer,
config :code_corps,
postmark_forgot_password_template: "1989481",
postmark_organization_invite_email_template: "3442401",
postmark_project_acceptance_template: "1447022",
postmark_project_request_template: "4017261",
postmark_project_approval_request_template: "4105823",
postmark_project_approved_template: "4105744",
postmark_project_user_acceptance_template: "1447022",
postmark_project_user_request_template: "4017261",
postmark_receipt_template: "1252361"

# ## SSL Support
Expand Down
6 changes: 4 additions & 2 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ config :code_corps, CodeCorps.Mailer,
config :code_corps,
postmark_forgot_password_template: "123",
postmark_organization_invite_email_template: "123",
postmark_project_acceptance_template: "123",
postmark_project_request_template: "123",
postmark_project_approval_request_template: "123",
postmark_project_approved_template: "123",
postmark_project_user_acceptance_template: "123",
postmark_project_user_request_template: "123",
postmark_receipt_template: "123"

config :code_corps, :cloudex, CloudexTest
Expand Down
121 changes: 121 additions & 0 deletions emails/project_approval_request.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>{{project_title}} is asking to be approved</title>
<!--
Make sure you copy the styles from styles.css into the email template in Postmark before saving there.
<style type="text/css" rel="stylesheet" media="all">
</style>
-->
<link rel="stylesheet" type="text/css" href="styles.css" media="screen" />
</head>
<body>
<span class="preheader">Head over to the app to process their request.</span>
<table class="email-wrapper" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<table class="email-content" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td class="email-masthead" width="100%" cellpadding="0" cellspacing="0">
<table class="email-masthead_inner" align="center" width="570" cellpadding="0" cellspacing="0">
<tr>
<td>
<a href="https://www.codecorps.org">
<img src="https://d3pgew4wbk2vb1.cloudfront.net/emails/images/logo-small@2x.png" class="email-masthead_logo" />
</a>
</td>
</tr>
</table>
</td>
</tr>
<!-- Email Body -->
<tr>
<td class="email-body" width="100%" cellpadding="0" cellspacing="0">
<table class="email-body_inner" align="center" width="570" cellpadding="0" cellspacing="0">
<!-- Body content -->
<tr>
<td class="content-cell">
<table class="donation" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>
<p>
Hi Code Corps team,
</p>
<p>
<strong>{{project_title}}</strong> is asking to have their project approved.
</p>
</td>
</tr>
</table>
<table class="donation" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>
<tr>
<td>
<p>
<p class="center">
<img src="{{project_logo_url}}" width="70" height="70" />
</p>
<p class="center">
<strong>{{project_title}}</strong>
</p>
</p>
<p class="center">
{{project_description}}
</p>
<td>
</tr>
</tr>
</td>
</table>
<table class="donation" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>
<p>
You can head over to <a href="{{admin_project_show_url}}">the admin page for the project</a> to process their request.
</p>
<p>
You can also take a look at <a href="{{project_url}}">their project on Code Corps</a> to see it how users will see it.
</p>
</td>
</tr>
</table>
<table class="body-signature">
<tr>
<td>
<p>
Cheers,
<br><strong>🤖 The Code Corps Robots</strong>
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table class="email-footer" align="center" width="570" cellpadding="0" cellspacing="0">
<tr>
<td class="content-cell" align="center">
<p class="sub align-center">
Code Corps PBC
<br>4166 Wilson Ave #1
<br>San Diego, CA 92104
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
100 changes: 100 additions & 0 deletions emails/project_approved.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>{{project_title}} is approved!</title>
<!--
Make sure you copy the styles from styles.css into the email template in Postmark before saving there.
<style type="text/css" rel="stylesheet" media="all">
</style>
-->
<link rel="stylesheet" type="text/css" href="styles.css" media="screen" />
</head>
<body>
<span class="preheader">Head over to the app to get started.</span>
<table class="email-wrapper" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<table class="email-content" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td class="email-masthead" width="100%" cellpadding="0" cellspacing="0">
<table class="email-masthead_inner" align="center" width="570" cellpadding="0" cellspacing="0">
<tr>
<td>
<a href="https://www.codecorps.org">
<img src="https://d3pgew4wbk2vb1.cloudfront.net/emails/images/logo-small@2x.png" class="email-masthead_logo" />
</a>
</td>
</tr>
</table>
</td>
</tr>
<!-- Email Body -->
<tr>
<td class="email-body" width="100%" cellpadding="0" cellspacing="0">
<table class="email-body_inner" align="center" width="570" cellpadding="0" cellspacing="0">
<!-- Body content -->
<tr>
<td class="content-cell">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>
<p class="center">
<img src="https://d3pgew4wbk2vb1.cloudfront.net/emails/images/party@2x.png" width="100" height="100" />
</p>
<p>
Hi {{project_title}} team,
</p>
<p>
Congratulations, your project was just approved!
</p>
<p>
You can head over to <a href="{{project_url}}">your project</a> now to see it live and are free to share your project link:
</p>
<p>
<a href="{{project_url}}">{{project_url}}</a>
</p>
</td>
</tr>
</table>
<table class="body-signature">
<tr>
<td>
<p>
Cheers,
<br><strong>The Code Corps Team</strong>
</p>
<p class="center small">
Questions? Feedback?
<br>Visit our <strong><a href="https://help.codecorps.org">Help Center</a></strong> or just reply to this email.</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table class="email-footer" align="center" width="570" cellpadding="0" cellspacing="0">
<tr>
<td class="content-cell" align="center">
<p class="sub align-center">
Code Corps PBC
<br>4166 Wilson Ave #1
<br>San Diego, CA 92104
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
1 change: 1 addition & 0 deletions emails/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ td {

.email-masthead_inner {
padding: 10px 0;
text-align: center;
}

.email-masthead_logo {
Expand Down
13 changes: 13 additions & 0 deletions lib/code_corps/analytics/segment_traits_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ defmodule CodeCorps.Analytics.SegmentTraitsBuilder do
project_id: record.project_id
}
end
defp traits(%CodeCorps.Project{} = record) do
record = record |> Repo.preload([:organization])
%{
id: record.id,
approval_requested: record.approval_requested,
approved: record.approved,
description: record.description,
slug: record.slug,
title: record.title,
total_monthly_donated: record.total_monthly_donated,
website: record.website
}
end
defp traits(%CodeCorps.ProjectSkill{} = record) do
record = record |> Repo.preload([:project, :skill])
%{
Expand Down
63 changes: 63 additions & 0 deletions lib/code_corps/emails/project_approval_request_email.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
defmodule CodeCorps.Emails.ProjectApprovalRequestEmail do
import Bamboo.Email, only: [to: 2]
import Bamboo.PostmarkHelper
import Ecto.Query, only: [where: 3]

alias CodeCorps.{Project, Repo, User, WebClient}
alias CodeCorps.Emails.BaseEmail
alias CodeCorps.Presenters.ImagePresenter

@spec create(Project.t) :: Bamboo.Email.t
def create(%Project{} = project) do
BaseEmail.create
|> to(get_site_admins_emails())
|> template(template_id(), build_model(project))
end

@spec build_model(Project.t) :: map
defp build_model(%Project{} = project) do
%{
admin_project_show_url: project |> admin_url(),
project_description: project.description,
project_logo_url: ImagePresenter.large(project),
project_title: project.title,
project_url: project |> preload() |> project_url(),
subject: "#{project.title} is asking to be approved"
}
end

@spec preload(Project.t) :: Project.t
defp preload(%Project{} = project), do: project |> Repo.preload(:organization)

@spec admin_url(Project.t) :: String.t
defp admin_url(project) do
WebClient.url()
|> URI.merge("/admin/projects/" <> Integer.to_string(project.id))
|> URI.to_string()
end

@spec project_url(Project.t) :: String.t
defp project_url(project) do
WebClient.url()
|> URI.merge(project.organization.slug <> "/" <> project.slug)
|> URI.to_string()
end

@spec template_id :: String.t
defp template_id, do: Application.get_env(:code_corps, :postmark_project_approval_request_template)

@spec get_site_admins_emails() :: list(String.t)
defp get_site_admins_emails() do
get_site_admins() |> Enum.map(&extract_email/1)
end

@spec extract_email(User.t) :: String.t
defp extract_email(%User{email: email}), do: email

@spec get_site_admins() :: list(User.t)
defp get_site_admins() do
User
|> where([object], object.admin == true)
|> Repo.all()
end
end

0 comments on commit 5da352a

Please sign in to comment.