Skip to content

Commit ece57e9

Browse files
authored
Merge pull request #1274 from code-corps/add-project-approval-requests
Add project approval requests
2 parents 21e9f53 + 5da352a commit ece57e9

27 files changed

+659
-38
lines changed

config/dev.exs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ config :code_corps, CodeCorps.Mailer, adapter: Bamboo.LocalAdapter
6161
config :code_corps,
6262
postmark_forgot_password_template: "123",
6363
postmark_organization_invite_email_template: "123",
64-
postmark_project_acceptance_template: "123",
65-
postmark_project_request_template: "123",
64+
postmark_project_approval_request_template: "123",
65+
postmark_project_approved_template: "123",
66+
postmark_project_user_acceptance_template: "123",
67+
postmark_project_user_request_template: "123",
6668
postmark_receipt_template: "123"
6769

6870
# If the dev environment has no CLOUDEX_API_KEY set, we want the app

config/prod.exs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ config :code_corps, CodeCorps.Mailer,
6262
config :code_corps,
6363
postmark_forgot_password_template: "1989483",
6464
postmark_organization_invite_email_template: "3441863",
65-
postmark_project_acceptance_template: "1447041",
66-
postmark_project_request_template: "4017262",
65+
postmark_project_approval_request_template: "4105824",
66+
postmark_project_approved_template: "4105822",
67+
postmark_project_user_acceptance_template: "1447041",
68+
postmark_project_user_request_template: "4017262",
6769
postmark_receipt_template: "1255222"
6870

6971
# ## SSL Support

config/remote-development.exs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ config :code_corps, CodeCorps.Mailer,
4545
config :code_corps,
4646
postmark_forgot_password_template: "123",
4747
postmark_organization_invite_email_template: "123",
48-
postmark_project_acceptance_template: "123",
49-
postmark_project_request_template: "123",
48+
postmark_project_approval_request_template: "123",
49+
postmark_project_approved_template: "123",
50+
postmark_project_user_acceptance_template: "123",
51+
postmark_project_user_request_template: "123",
5052
postmark_receipt_template: "123"
5153

5254
# ## SSL Support

config/staging.exs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ config :code_corps, CodeCorps.Mailer,
6161
config :code_corps,
6262
postmark_forgot_password_template: "1989481",
6363
postmark_organization_invite_email_template: "3442401",
64-
postmark_project_acceptance_template: "1447022",
65-
postmark_project_request_template: "4017261",
64+
postmark_project_approval_request_template: "4105823",
65+
postmark_project_approved_template: "4105744",
66+
postmark_project_user_acceptance_template: "1447022",
67+
postmark_project_user_request_template: "4017261",
6668
postmark_receipt_template: "1252361"
6769

6870
# ## SSL Support

config/test.exs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ config :code_corps, CodeCorps.Mailer,
6767
config :code_corps,
6868
postmark_forgot_password_template: "123",
6969
postmark_organization_invite_email_template: "123",
70-
postmark_project_acceptance_template: "123",
71-
postmark_project_request_template: "123",
70+
postmark_project_approval_request_template: "123",
71+
postmark_project_approved_template: "123",
72+
postmark_project_user_acceptance_template: "123",
73+
postmark_project_user_request_template: "123",
7274
postmark_receipt_template: "123"
7375

7476
config :code_corps, :cloudex, CloudexTest
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml">
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
5+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6+
<title>{{project_title}} is asking to be approved</title>
7+
<!--
8+
Make sure you copy the styles from styles.css into the email template in Postmark before saving there.
9+
10+
<style type="text/css" rel="stylesheet" media="all">
11+
</style>
12+
-->
13+
<link rel="stylesheet" type="text/css" href="styles.css" media="screen" />
14+
</head>
15+
<body>
16+
<span class="preheader">Head over to the app to process their request.</span>
17+
<table class="email-wrapper" width="100%" cellpadding="0" cellspacing="0">
18+
<tr>
19+
<td align="center">
20+
<table class="email-content" width="100%" cellpadding="0" cellspacing="0">
21+
<tr>
22+
<td class="email-masthead" width="100%" cellpadding="0" cellspacing="0">
23+
<table class="email-masthead_inner" align="center" width="570" cellpadding="0" cellspacing="0">
24+
<tr>
25+
<td>
26+
<a href="https://www.codecorps.org">
27+
<img src="https://d3pgew4wbk2vb1.cloudfront.net/emails/images/logo-small@2x.png" class="email-masthead_logo" />
28+
</a>
29+
</td>
30+
</tr>
31+
</table>
32+
</td>
33+
</tr>
34+
<!-- Email Body -->
35+
<tr>
36+
<td class="email-body" width="100%" cellpadding="0" cellspacing="0">
37+
<table class="email-body_inner" align="center" width="570" cellpadding="0" cellspacing="0">
38+
<!-- Body content -->
39+
<tr>
40+
<td class="content-cell">
41+
<table class="donation" width="100%" cellpadding="0" cellspacing="0">
42+
<tr>
43+
<td>
44+
<p>
45+
Hi Code Corps team,
46+
</p>
47+
<p>
48+
<strong>{{project_title}}</strong> is asking to have their project approved.
49+
</p>
50+
</td>
51+
</tr>
52+
</table>
53+
<table class="donation" width="100%" cellpadding="0" cellspacing="0">
54+
<tr>
55+
<td>
56+
<tr>
57+
<td>
58+
<p>
59+
<p class="center">
60+
<img src="{{project_logo_url}}" width="70" height="70" />
61+
</p>
62+
<p class="center">
63+
<strong>{{project_title}}</strong>
64+
</p>
65+
</p>
66+
<p class="center">
67+
{{project_description}}
68+
</p>
69+
<td>
70+
</tr>
71+
</tr>
72+
</td>
73+
</table>
74+
<table class="donation" width="100%" cellpadding="0" cellspacing="0">
75+
<tr>
76+
<td>
77+
<p>
78+
You can head over to <a href="{{admin_project_show_url}}">the admin page for the project</a> to process their request.
79+
</p>
80+
<p>
81+
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.
82+
</p>
83+
</td>
84+
</tr>
85+
</table>
86+
<table class="body-signature">
87+
<tr>
88+
<td>
89+
<p>
90+
Cheers,
91+
<br><strong>🤖 The Code Corps Robots</strong>
92+
</p>
93+
</td>
94+
</tr>
95+
</table>
96+
</td>
97+
</tr>
98+
</table>
99+
</td>
100+
</tr>
101+
<tr>
102+
<td>
103+
<table class="email-footer" align="center" width="570" cellpadding="0" cellspacing="0">
104+
<tr>
105+
<td class="content-cell" align="center">
106+
<p class="sub align-center">
107+
Code Corps PBC
108+
<br>4166 Wilson Ave #1
109+
<br>San Diego, CA 92104
110+
</p>
111+
</td>
112+
</tr>
113+
</table>
114+
</td>
115+
</tr>
116+
</table>
117+
</td>
118+
</tr>
119+
</table>
120+
</body>
121+
</html>

emails/project_approved.html

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml">
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
5+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6+
<title>{{project_title}} is approved!</title>
7+
<!--
8+
Make sure you copy the styles from styles.css into the email template in Postmark before saving there.
9+
10+
<style type="text/css" rel="stylesheet" media="all">
11+
</style>
12+
-->
13+
<link rel="stylesheet" type="text/css" href="styles.css" media="screen" />
14+
</head>
15+
<body>
16+
<span class="preheader">Head over to the app to get started.</span>
17+
<table class="email-wrapper" width="100%" cellpadding="0" cellspacing="0">
18+
<tr>
19+
<td align="center">
20+
<table class="email-content" width="100%" cellpadding="0" cellspacing="0">
21+
<tr>
22+
<td class="email-masthead" width="100%" cellpadding="0" cellspacing="0">
23+
<table class="email-masthead_inner" align="center" width="570" cellpadding="0" cellspacing="0">
24+
<tr>
25+
<td>
26+
<a href="https://www.codecorps.org">
27+
<img src="https://d3pgew4wbk2vb1.cloudfront.net/emails/images/logo-small@2x.png" class="email-masthead_logo" />
28+
</a>
29+
</td>
30+
</tr>
31+
</table>
32+
</td>
33+
</tr>
34+
<!-- Email Body -->
35+
<tr>
36+
<td class="email-body" width="100%" cellpadding="0" cellspacing="0">
37+
<table class="email-body_inner" align="center" width="570" cellpadding="0" cellspacing="0">
38+
<!-- Body content -->
39+
<tr>
40+
<td class="content-cell">
41+
<table width="100%" cellpadding="0" cellspacing="0">
42+
<tr>
43+
<td>
44+
<p class="center">
45+
<img src="https://d3pgew4wbk2vb1.cloudfront.net/emails/images/party@2x.png" width="100" height="100" />
46+
</p>
47+
<p>
48+
Hi {{project_title}} team,
49+
</p>
50+
<p>
51+
Congratulations, your project was just approved!
52+
</p>
53+
<p>
54+
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:
55+
</p>
56+
<p>
57+
<a href="{{project_url}}">{{project_url}}</a>
58+
</p>
59+
</td>
60+
</tr>
61+
</table>
62+
<table class="body-signature">
63+
<tr>
64+
<td>
65+
<p>
66+
Cheers,
67+
<br><strong>The Code Corps Team</strong>
68+
</p>
69+
<p class="center small">
70+
Questions? Feedback?
71+
<br>Visit our <strong><a href="https://help.codecorps.org">Help Center</a></strong> or just reply to this email.</p>
72+
</td>
73+
</tr>
74+
</table>
75+
</td>
76+
</tr>
77+
</table>
78+
</td>
79+
</tr>
80+
<tr>
81+
<td>
82+
<table class="email-footer" align="center" width="570" cellpadding="0" cellspacing="0">
83+
<tr>
84+
<td class="content-cell" align="center">
85+
<p class="sub align-center">
86+
Code Corps PBC
87+
<br>4166 Wilson Ave #1
88+
<br>San Diego, CA 92104
89+
</p>
90+
</td>
91+
</tr>
92+
</table>
93+
</td>
94+
</tr>
95+
</table>
96+
</td>
97+
</tr>
98+
</table>
99+
</body>
100+
</html>

emails/styles.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ td {
5858

5959
.email-masthead_inner {
6060
padding: 10px 0;
61+
text-align: center;
6162
}
6263

6364
.email-masthead_logo {

lib/code_corps/analytics/segment_traits_builder.ex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ defmodule CodeCorps.Analytics.SegmentTraitsBuilder do
5555
project_id: record.project_id
5656
}
5757
end
58+
defp traits(%CodeCorps.Project{} = record) do
59+
record = record |> Repo.preload([:organization])
60+
%{
61+
id: record.id,
62+
approval_requested: record.approval_requested,
63+
approved: record.approved,
64+
description: record.description,
65+
slug: record.slug,
66+
title: record.title,
67+
total_monthly_donated: record.total_monthly_donated,
68+
website: record.website
69+
}
70+
end
5871
defp traits(%CodeCorps.ProjectSkill{} = record) do
5972
record = record |> Repo.preload([:project, :skill])
6073
%{
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
defmodule CodeCorps.Emails.ProjectApprovalRequestEmail do
2+
import Bamboo.Email, only: [to: 2]
3+
import Bamboo.PostmarkHelper
4+
import Ecto.Query, only: [where: 3]
5+
6+
alias CodeCorps.{Project, Repo, User, WebClient}
7+
alias CodeCorps.Emails.BaseEmail
8+
alias CodeCorps.Presenters.ImagePresenter
9+
10+
@spec create(Project.t) :: Bamboo.Email.t
11+
def create(%Project{} = project) do
12+
BaseEmail.create
13+
|> to(get_site_admins_emails())
14+
|> template(template_id(), build_model(project))
15+
end
16+
17+
@spec build_model(Project.t) :: map
18+
defp build_model(%Project{} = project) do
19+
%{
20+
admin_project_show_url: project |> admin_url(),
21+
project_description: project.description,
22+
project_logo_url: ImagePresenter.large(project),
23+
project_title: project.title,
24+
project_url: project |> preload() |> project_url(),
25+
subject: "#{project.title} is asking to be approved"
26+
}
27+
end
28+
29+
@spec preload(Project.t) :: Project.t
30+
defp preload(%Project{} = project), do: project |> Repo.preload(:organization)
31+
32+
@spec admin_url(Project.t) :: String.t
33+
defp admin_url(project) do
34+
WebClient.url()
35+
|> URI.merge("/admin/projects/" <> Integer.to_string(project.id))
36+
|> URI.to_string()
37+
end
38+
39+
@spec project_url(Project.t) :: String.t
40+
defp project_url(project) do
41+
WebClient.url()
42+
|> URI.merge(project.organization.slug <> "/" <> project.slug)
43+
|> URI.to_string()
44+
end
45+
46+
@spec template_id :: String.t
47+
defp template_id, do: Application.get_env(:code_corps, :postmark_project_approval_request_template)
48+
49+
@spec get_site_admins_emails() :: list(String.t)
50+
defp get_site_admins_emails() do
51+
get_site_admins() |> Enum.map(&extract_email/1)
52+
end
53+
54+
@spec extract_email(User.t) :: String.t
55+
defp extract_email(%User{email: email}), do: email
56+
57+
@spec get_site_admins() :: list(User.t)
58+
defp get_site_admins() do
59+
User
60+
|> where([object], object.admin == true)
61+
|> Repo.all()
62+
end
63+
end

0 commit comments

Comments
 (0)