Skip to content

Commit a98e520

Browse files
committed
Change OrganizationInvite title to organization_name
1 parent f1fdef9 commit a98e520

14 files changed

Lines changed: 79 additions & 62 deletions

config/dev.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ config :code_corps, CodeCorps.Mailer,
6161

6262
config :code_corps,
6363
postmark_forgot_password_template: "123",
64+
postmark_organization_invite_email_template: "123",
6465
postmark_project_acceptance_template: "123",
65-
postmark_receipt_template: "123",
66-
postmark_organization_invite_email_template: "123"
66+
postmark_receipt_template: "123"
6767

6868
# If the dev environment has no CLOUDEX_API_KEY set, we want the app
6969
# to still run, with cloudex in test API mode

config/prod.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ config :code_corps, CodeCorps.Mailer,
6262

6363
config :code_corps,
6464
postmark_forgot_password_template: "1989483",
65+
postmark_organization_invite_email_template: "3441863",
6566
postmark_project_acceptance_template: "1447041",
66-
postmark_receipt_template: "1255222",
67-
postmark_organization_invite_email_template: "3441863"
67+
postmark_receipt_template: "1255222"
6868

6969
# ## SSL Support
7070
#

config/staging.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ config :code_corps, CodeCorps.Mailer,
6060

6161
config :code_corps,
6262
postmark_forgot_password_template: "1989481",
63+
postmark_organization_invite_email_template: "3442401",
6364
postmark_project_acceptance_template: "1447022",
64-
postmark_receipt_template: "1252361",
65-
postmark_organization_invite_email_template: "3442401"
65+
postmark_receipt_template: "1252361"
6666

6767
# ## SSL Support
6868
#

emails/organization_invite.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@
4141
<table width="100%" cellpadding="0" cellspacing="0">
4242
<tr>
4343
<td>
44-
<p>Hi {{title}},</p>
44+
<p>Hi {{organization_name}},</p>
4545
<p>You've just been invited to add your first project on Code Corps.</p>
46-
<p>To create your project, please <a href="{{url}}">click here</a> or paste this link into your browser:</p>
47-
<p><a href="{{url}}">{{url}}</a></p>
46+
<p>To create your project, please <a href="{{invite_url}}">click here</a> or paste this link into your browser:</p>
47+
<p><a href="{{invite_url}}">{{invite_url}}</a></p>
4848
<p>If you have any issues, don't hesitate to <a href="https://help.codecorps.org">contact us</a>.</p>
4949
</td>
5050
</tr>
Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
defmodule CodeCorps.Emails.OrganizationInviteEmail do
22
import Bamboo.Email
33
import Bamboo.PostmarkHelper
4-
5-
alias CodeCorps.{OrganizationInvite}
6-
alias CodeCorps.Emails.BaseEmail
7-
8-
def create(%OrganizationInvite{} = organization_invite) do
4+
5+
alias CodeCorps.{Emails.BaseEmail, OrganizationInvite}
6+
7+
def create(%OrganizationInvite{} = invite) do
98
BaseEmail.create
10-
|> to(organization_invite.email)
11-
|> template(template_id(), build_model(organization_invite))
9+
|> to(invite.email)
10+
|> template(template_id(), build_model(invite))
1211
end
13-
14-
defp build_model(%OrganizationInvite{} = organization_invite) do
12+
13+
defp build_model(%OrganizationInvite{} = invite) do
1514
%{
16-
title: organization_invite.title,
17-
url: url(organization_invite.title, organization_invite.code),
15+
organization_name: invite.organization_name,
16+
invite_url: invite_url(invite.code, invite.organization_name),
1817
subject: "Create your first project on Code Corps"
1918
}
2019
end
21-
22-
defp url(title, code) do
20+
21+
defp invite_url(code, organization_name) do
2322
Application.get_env(:code_corps, :site_url)
24-
|> URI.merge("/invites/organization" <> "?" <> set_params(code, title))
23+
|> URI.merge("/invites/organization" <> "?" <> set_params(code, organization_name))
2524
|> URI.to_string
2625
end
2726

28-
defp set_params(code, title) do
29-
%{code: code, organization_title: title }
27+
defp set_params(code, organization_name) do
28+
%{code: code, organization_name: organization_name }
3029
|> URI.encode_query
3130
end
32-
31+
3332
defp template_id, do: Application.get_env(:code_corps, :organization_invite_email_template)
34-
end
33+
end

lib/code_corps/model/organization_invite.ex

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ defmodule CodeCorps.OrganizationInvite do
88
schema "organization_invites" do
99
field :code, :string
1010
field :email, :string
11-
field :title, :string
1211
field :fulfilled, :boolean, default: false
12+
field :organization_name, :string
1313

1414
timestamps()
1515
end
@@ -19,8 +19,8 @@ defmodule CodeCorps.OrganizationInvite do
1919
"""
2020
def changeset(struct, params \\ %{}) do
2121
struct
22-
|> cast(params, [:email, :title, :fulfilled])
23-
|> validate_required([:email, :title])
22+
|> cast(params, [:email, :organization_name, :fulfilled])
23+
|> validate_required([:email, :organization_name])
2424
|> validate_format(:email, ~r/@/)
2525
|> validate_change(:fulfilled, &check_fulfilled_changes_to_true/2)
2626
end
@@ -32,21 +32,25 @@ defmodule CodeCorps.OrganizationInvite do
3232
struct
3333
|> changeset(params)
3434
|> generate_code
35+
|> unique_constraint(:code)
3536
end
3637

3738
defp generate_code(changeset) do
3839
case changeset do
3940
%Ecto.Changeset{valid?: true} ->
40-
length = 10
41-
code = length
42-
|> :crypto.strong_rand_bytes
43-
|> Base.encode64
44-
|> binary_part(0, length)
41+
code = do_generate_code(10)
4542
put_change(changeset, :code, code)
4643
_ -> changeset
4744
end
4845
end
4946

47+
defp do_generate_code(length) do
48+
length
49+
|> :crypto.strong_rand_bytes
50+
|> Base.encode64
51+
|> binary_part(0, length)
52+
end
53+
5054
defp check_fulfilled_changes_to_true :fulfilled, fulfilled do
5155
if fulfilled == false do
5256
[fulfillled: "Fulfilled can only change from false to true"]

lib/code_corps_web/views/organization_invite_view.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ defmodule CodeCorpsWeb.OrganizationInviteView do
33
use JaSerializer.PhoenixView
44

55
attributes [
6-
:email, :title, :updated_at, :inserted_at, :fulfilled
6+
:email, :fulfilled, :inserted_at, :organization_name, :updated_at
77
]
88
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
defmodule CodeCorps.Repo.Migrations.ChangeOrganizationInviteTitleToOrganizationName do
2+
use Ecto.Migration
3+
4+
def change do
5+
rename table(:organization_invites), :title, to: :organization_name
6+
end
7+
end

priv/repo/structure.sql

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ CREATE TABLE organization_invites (
344344
id bigint NOT NULL,
345345
code character varying(255) NOT NULL,
346346
email character varying(255) NOT NULL,
347-
title character varying(255) NOT NULL,
347+
organization_name character varying(255) NOT NULL,
348348
fulfilled boolean DEFAULT false NOT NULL,
349349
inserted_at timestamp without time zone NOT NULL,
350350
updated_at timestamp without time zone NOT NULL
@@ -2570,6 +2570,13 @@ CREATE UNIQUE INDEX user_tasks_user_id_task_id_index ON user_tasks USING btree (
25702570
CREATE UNIQUE INDEX users_email_index ON users USING btree (email);
25712571

25722572

2573+
--
2574+
-- Name: users_github_id_index; Type: INDEX; Schema: public; Owner: -
2575+
--
2576+
2577+
CREATE UNIQUE INDEX users_github_id_index ON users USING btree (github_id);
2578+
2579+
25732580
--
25742581
-- Name: users_lower_username_index; Type: INDEX; Schema: public; Owner: -
25752582
--
@@ -3044,5 +3051,5 @@ ALTER TABLE ONLY user_tasks
30443051
-- PostgreSQL database dump complete
30453052
--
30463053

3047-
INSERT INTO "schema_migrations" (version) VALUES (20160723215749), (20160804000000), (20160804001111), (20160805132301), (20160805203929), (20160808143454), (20160809214736), (20160810124357), (20160815125009), (20160815143002), (20160816020347), (20160816034021), (20160817220118), (20160818000944), (20160818132546), (20160820113856), (20160820164905), (20160822002438), (20160822004056), (20160822011624), (20160822020401), (20160822044612), (20160830081224), (20160830224802), (20160911233738), (20160912002705), (20160912145957), (20160918003206), (20160928232404), (20161003185918), (20161019090945), (20161019110737), (20161020144622), (20161021131026), (20161031001615), (20161121005339), (20161121014050), (20161121043941), (20161121045709), (20161122015942), (20161123081114), (20161123150943), (20161124085742), (20161125200620), (20161126045705), (20161127054559), (20161205024856), (20161207112519), (20161209192504), (20161212005641), (20161214005935), (20161215052051), (20161216051447), (20161218005913), (20161219160401), (20161219163909), (20161220141753), (20161221085759), (20161226213600), (20161231063614), (20170102130055), (20170102181053), (20170104113708), (20170104212623), (20170104235423), (20170106013143), (20170115035159), (20170115230549), (20170121014100), (20170131234029), (20170201014901), (20170201025454), (20170201035458), (20170201183258), (20170220032224), (20170224233516), (20170226050552), (20170228085250), (20170308214128), (20170308220713), (20170308222552), (20170313130611), (20170318032449), (20170318082740), (20170324194827), (20170424215355), (20170501225441), (20170505224222), (20170526095401), (20170602000208), (20170622205732), (20170626231059), (20170628092119), (20170628213609), (20170629183404), (20170630140136), (20170706132431), (20170707213648), (20170711122252), (20170717092127), (20170725060612), (20170727052644), (20170731130121), (20170814131722), (20170913114958), (20170921014405), (20170925214512), (20170925230419), (20170926134646), (20170927100300), (20170928234412), (20171003225853);
3054+
INSERT INTO "schema_migrations" (version) VALUES (20160723215749), (20160804000000), (20160804001111), (20160805132301), (20160805203929), (20160808143454), (20160809214736), (20160810124357), (20160815125009), (20160815143002), (20160816020347), (20160816034021), (20160817220118), (20160818000944), (20160818132546), (20160820113856), (20160820164905), (20160822002438), (20160822004056), (20160822011624), (20160822020401), (20160822044612), (20160830081224), (20160830224802), (20160911233738), (20160912002705), (20160912145957), (20160918003206), (20160928232404), (20161003185918), (20161019090945), (20161019110737), (20161020144622), (20161021131026), (20161031001615), (20161121005339), (20161121014050), (20161121043941), (20161121045709), (20161122015942), (20161123081114), (20161123150943), (20161124085742), (20161125200620), (20161126045705), (20161127054559), (20161205024856), (20161207112519), (20161209192504), (20161212005641), (20161214005935), (20161215052051), (20161216051447), (20161218005913), (20161219160401), (20161219163909), (20161220141753), (20161221085759), (20161226213600), (20161231063614), (20170102130055), (20170102181053), (20170104113708), (20170104212623), (20170104235423), (20170106013143), (20170115035159), (20170115230549), (20170121014100), (20170131234029), (20170201014901), (20170201025454), (20170201035458), (20170201183258), (20170220032224), (20170224233516), (20170226050552), (20170228085250), (20170308214128), (20170308220713), (20170308222552), (20170313130611), (20170318032449), (20170318082740), (20170324194827), (20170424215355), (20170501225441), (20170505224222), (20170526095401), (20170602000208), (20170622205732), (20170626231059), (20170628092119), (20170628213609), (20170629183404), (20170630140136), (20170706132431), (20170707213648), (20170711122252), (20170717092127), (20170725060612), (20170727052644), (20170731130121), (20170814131722), (20170913114958), (20170921014405), (20170925214512), (20170925230419), (20170926134646), (20170927100300), (20170928234412), (20171003134956), (20171003225853), (20171006161407);
30483055

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
defmodule CodeCorps.Emails.OrganizationInviteEmailTest do
22
use CodeCorps.ModelCase
33
use Bamboo.Test
4-
4+
55
alias CodeCorps.Emails.OrganizationInviteEmail
6-
6+
77
test "organization email invite works" do
8-
organization_invite = insert(:organization_invite)
9-
email = OrganizationInviteEmail.create(organization_invite)
8+
invite = insert(:organization_invite)
9+
email = OrganizationInviteEmail.create(invite)
1010

1111
assert email.from == "Code Corps<team@codecorps.org>"
12-
assert email.to == organization_invite.email
13-
12+
assert email.to == invite.email
13+
1414
template_model = email.private.template_model
15-
params =
16-
%{code: organization_invite.code, organization_title: organization_invite.title}
15+
params =
16+
%{code: invite.code, organization_name: invite.organization_name}
1717
|> URI.encode_query
18+
invite_url = "#{Application.get_env(:code_corps, :site_url)}/invites/organization?#{params}"
1819

1920
assert template_model == %{
20-
title: organization_invite.title,
21-
url: "#{Application.get_env(:code_corps, :site_url)}/invites/organization?#{params}",
21+
invite_url: invite_url,
22+
organization_name: invite.organization_name,
2223
subject: "Create your first project on Code Corps"
2324
}
2425
end
2526
end
26-

0 commit comments

Comments
 (0)