Skip to content
This repository has been archived by the owner on Aug 3, 2022. It is now read-only.

Commit

Permalink
Merge branch 'beta3'
Browse files Browse the repository at this point in the history
  • Loading branch information
tylersamples committed Jan 2, 2019
2 parents 2d3224f + 6489346 commit d8c12f2
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 54 deletions.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
erlang 21.1
elixir 1.7.4-otp-21
nodejs 10.11.0
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM elixir:1.7.3
FROM elixir:1.7.4 as build

ARG MIX_ENV=prod
ENV MIX_ENV ${MIX_ENV}
Expand All @@ -24,7 +24,7 @@ RUN mix compile
RUN mix release --env=${MIX_ENV} --verbose \
&& mv _build/${MIX_ENV}/rel/courtbot /opt/release

FROM debian:stretch
FROM debian:stretch as runtime

ENV LANG en_US.UTF-8
ENV LC_CTYPE en_US.UTF-8
Expand All @@ -37,5 +37,5 @@ RUN locale-gen en_US.UTF-8
RUN localedef -i en_US -f UTF-8 en_US.UTF-8

WORKDIR /opt/app
COPY --from=0 /opt/release .
COPY --from=build /opt/release .
CMD trap 'exit' INT; /opt/app/bin/courtbot foreground
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Courtbot
[![Build Status](https://travis-ci.org/boisebrigade/courtbot.svg?branch=development)](https://travis-ci.org/boisebrigade/Courtbot)
[![Build Status](https://travis-ci.org/boisebrigade/courtbot.svg?branch=development)](https://travis-ci.org/boisebrigade/courtbot)

Courtbot is a simple web service for subscribing to case hearing details via SMS.

Expand Down
4 changes: 0 additions & 4 deletions docker-deploy.sh

This file was deleted.

74 changes: 71 additions & 3 deletions lib/courtbot/release.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ defmodule Courtbot.ReleaseTasks do
:crypto,
:ssl,
:postgrex,
:ecto,
:ecto_sql,
:timex
]

@repos Application.get_env(:courtbot, :ecto_repos, [])
@repo Courtbot.Repo

def migrate() do
start_services()
Expand All @@ -17,6 +18,24 @@ defmodule Courtbot.ReleaseTasks do
stop_services()
end

def seeders() do
start_services()

run_seeds()

stop_services()
end

defp run_seeds() do
# Run the seed script if it exists
seed_script = priv_path_for(@repo, "seeds.exs")

if File.exists?(seed_script) do
IO.puts("Running seed script..")
Code.eval_file(seed_script)
end
end

def import() do
start_services()

Expand All @@ -33,14 +52,63 @@ defmodule Courtbot.ReleaseTasks do
stop_services()
end

def reset() do
drop_database()
create_database()

start_services()

create_migrations_table()
run_migrations()

stop_services()
end

defp create_migrations_table() do
Ecto.Migration.SchemaMigration.ensure_schema_migrations_table!(@repo, nil)
end

defp drop_database() do
case @repo.__adapter__.storage_down(@repo.config) do
:ok ->
IO.puts("Database has been dropped")

{:error, :already_down} ->
IO.puts("Dtabase has already been dropped")

{:error, term} when is_binary(term) ->
raise "Database couldn't be dropped: #{term}"

{:error, term} ->
raise "Database couldn't be dropped: #{inspect(term)}"
end
end

defp create_database() do
case @repo.__adapter__.storage_up(@repo.config) do
:ok ->
IO.puts("Database has been created")

{:error, :already_up} ->
IO.puts("Database has already been created")

{:error, term} when is_binary(term) ->
raise "Database couldn't be created: #{term}"

{:error, term} ->
raise "Database couldn't be created: #{inspect(term)}"
end
end

defp start_services do
IO.puts("Starting dependencies..")
# Start apps necessary for executing migrations
Enum.each(@start_apps, &Application.ensure_all_started/1)

# Start the Repo(s) for app
IO.puts("Starting repos..")
Enum.each(@repos, & &1.start_link(pool_size: 2))

@repo.start_link(pool_size: 2)
end

defp stop_services do
Expand All @@ -49,7 +117,7 @@ defmodule Courtbot.ReleaseTasks do
end

defp run_migrations do
Enum.each(@repos, &run_migrations_for/1)
run_migrations_for(Courtbot.Repo)
end

defp run_migrations_for(repo) do
Expand Down
11 changes: 9 additions & 2 deletions lib/courtbot_web/controllers/twiliocontroller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ defmodule CourtbotWeb.TwilioController do
gettext("unsubscribe")
]

@county gettext("county")

@request_defaults %{"locale" => "en"}

def sms(conn, _ = %{"From" => phone_number, "Body" => @debug_phase}) do
Expand Down Expand Up @@ -148,6 +150,11 @@ defmodule CourtbotWeb.TwilioController do
"requires_county" => case_number
}
) do
message =
message
|> String.replace(@county, "")
|> String.trim()

if Enum.member?(Case.all_counties(), message) do
{_, params} =
params
Expand Down Expand Up @@ -251,7 +258,7 @@ defmodule CourtbotWeb.TwilioController do

defp respond(conn, params, [case = %Case{hearings: _}]), do: prompt_remind(conn, params, case)
defp respond(conn, params, [_ | _]), do: prompt_county(conn, params)
defp respond(conn, params, _), do: prompt_unfound(conn, params)
defp respond(conn, params, _), do: prompt_not_found(conn, params)

defp prompt_no_hearings(conn, params = %{"From" => phone_number}, case) do
Logger.info(
Expand All @@ -266,7 +273,7 @@ defmodule CourtbotWeb.TwilioController do
|> encode(response)
end

defp prompt_unfound(conn, params = %{"From" => phone_number, "message" => message}) do
defp prompt_not_found(conn, params = %{"From" => phone_number, "message" => message}) do
Logger.info(log_safe_phone_number(phone_number) <> ": No case found for input: #{message}")

response = Response.message(:not_found, params)
Expand Down
20 changes: 11 additions & 9 deletions lib/courtbot_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ defmodule CourtbotWeb.Endpoint do
"""
def init(_key, config) do
if config[:load_from_system_env] do
port = String.to_integer(System.get_env("PORT")) || 4000
host = System.get_env("HOST") || "localhost"
port = String.to_integer(System.get_env("PORT") || "4000")

secret_key_base =
if config[:secret_key_base] do
Expand All @@ -53,16 +52,19 @@ defmodule CourtbotWeb.Endpoint do

config =
config
|> Keyword.put(:http, port: port)
|> Keyword.put(:url, port: port, host: host)
|> Keyword.put(:secret_key_base, secret_key_base)

# If we are trying to mount to 443 then set HTTPS specific settings
config =
if port === 443 do
config
|> Keyword.put(:url, scheme: "https")
|> Keyword.put(:force_ssl, rewrite_on: [:x_forwarded_proto])
if config[:server] do
# If we are trying to mount to 443 then set HTTPS specific settings
if port === 443 do
config
|> Keyword.put(:https, port: port, host: {0, 0, 0, 0})
|> Keyword.put(:force_ssl, rewrite_on: [:x_forwarded_proto])
else
config
|> Keyword.put(:http, port: port, host: {0, 0, 0, 0})
end
else
config
end
Expand Down
6 changes: 4 additions & 2 deletions lib/courtbot_web/response.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ defmodule CourtbotWeb.Response do

defp response(:prompt_reminder, %{"locale" => locale}) do
Gettext.with_locale(locale, fn ->
gettext("Would you like a reminder 24hr before the hearing date?")
gettext("Would you like a reminder a day before the next hearing date?")
end)
end

Expand All @@ -88,7 +88,9 @@ defmodule CourtbotWeb.Response do

defp response(:reject_reminder, %{"locale" => locale}) do
Gettext.with_locale(locale, fn ->
gettext("You said “No” so we won’t text you a reminder.")
gettext(
"Ok. We won't send you a reminder for this case. Text the case again in the future and you can subscribe."
)
end)
end

Expand Down
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ defmodule Courtbot.Mixfile do
{:cloak, "~> 0.7.0"},
{:gettext, "~> 0.11"},
{:csv, "~> 2.0.0"},
{:jason, "~> 1.1"},
{:aes256, "~> 0.5.0"},
{:sched_ex, "~> 1.0"},
{:tesla, "~> 1.0.0"},
{:timex, "~> 3.1"},
{:plug_cowboy, "~> 2.0"},
{:ex_twilio, "~> 0.6.0", runtime: false},
{:ex_twilio, "~> 0.6.0"},
{:ex_twiml, "~> 2.1.3"},
{:rollbax, ">= 0.0.0"},
{:ex_doc, "~> 0.18.0", only: :dev, runtime: false},
Expand Down
Loading

0 comments on commit d8c12f2

Please sign in to comment.