Skip to content

Commit

Permalink
Move :cf_utils to main :cf lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree committed Nov 5, 2018
1 parent 04fcadb commit d8d1fb2
Show file tree
Hide file tree
Showing 48 changed files with 177 additions and 206 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
script:
- set -e
- # ---- Build ----
- docker build --build-arg APP=cf -t ${CF_API_REST_IMAGE} .
- docker build --build-arg APP=cf_rest_api -t ${CF_API_REST_IMAGE} .
- docker build --build-arg APP=cf_graphql -t ${CF_API_GRAPHQL_IMAGE} .
- docker build --build-arg APP=cf_atom_feed -t ${CF_API_ATOM_FEED} .
- docker build --build-arg APP=cf_opengraph -t ${CF_API_OPENGRAPH_IMAGE} .
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ COPY apps/cf_atom_feed/mix.exs ./apps/cf_atom_feed/
COPY apps/cf_graphql/mix.exs ./apps/cf_graphql/
COPY apps/cf_jobs/mix.exs ./apps/cf_jobs/
COPY apps/cf_opengraph/mix.exs ./apps/cf_opengraph/
COPY apps/cf_utils/mix.exs ./apps/cf_utils/
COPY apps/cf_rest_api/mix.exs ./apps/cf_rest_api/
COPY apps/db/mix.exs ./apps/db/
RUN HEX_HTTP_CONCURRENCY=4 HEX_HTTP_TIMEOUT=180 mix deps.get

Expand Down
16 changes: 16 additions & 0 deletions apps/cf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# [CaptainFact App] CF

This is CaptainFact main library. It holds most helpers and functions used to
manipulate data from DB.

## Secrets

Following secrets must be configured in production:

- frontend_url
- youtube_api_key
- facebook_app_id
- facebook_app_secret
- secret_key_base
- mailgun_domain
- mailgun_api_key
2 changes: 1 addition & 1 deletion apps/cf/config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dev_secret = "8C6FsJwjV11d+1WPUIbkEH6gB/VavJrcXWoPLujgpclfxjkLkoNFSjVU9XfeNm6s"

# General config
config :cf,
frontend_url: "http://localhost:3333",
frontend_url: "http://localhost:3333/",
oauth: [
facebook: [
client_id: "506726596325615",
Expand Down
2 changes: 1 addition & 1 deletion apps/cf/config/test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use Mix.Config

# General config
config :cf, frontend_url: "https://TEST_FRONTEND"
config :cf, frontend_url: "https://TEST_FRONTEND/"

# Don't fetch user picture on test environment
config :cf, fetch_default_user_picture: false
Expand Down
2 changes: 1 addition & 1 deletion apps/cf/lib/cf_mailer/templates/invitation.en.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Your invitation to try CaptainFact is ready !<br>
<br><br>
<% end %>
Please follow this link to create your account:
<a href="<%= frontend_url() %>/signup?invitation_token=<%= @invitation_token %>">
<a href="<%= invitation_url(@invitation_token) %>">
Create account
</a>
<br>
2 changes: 1 addition & 1 deletion apps/cf/lib/cf_mailer/templates/invitation.en.text.eex
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Your invitation to try CaptainFact is ready !
<% end %>

Please follow this link to create your account:
<%= frontend_url() %>/signup?invitation_token=<%= @invitation_token %>
<%= invitation_url(@invitation_token) %>
2 changes: 1 addition & 1 deletion apps/cf/lib/cf_mailer/templates/invitation.fr.html.eex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Votre invitation pour rejoindre CaptainFact est prête !<br>
<br>
Pour créer un compte dès maintenant, utilisez votre lien d'invitation unique :
<a href="<%= frontend_url() %>/signup?invitation_token=<%= @invitation_token %>">
<a href="<%= invitation_url(@invitation_token) %>">
Je m'inscris
</a>
<br>
Expand Down
2 changes: 1 addition & 1 deletion apps/cf/lib/cf_mailer/templates/invitation.fr.text.eex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Votre invitation pour rejoindre CaptainFact est prête !

Pour créer un compte dès maintenant, utilisez votre lien d'invitation unique :
<%= frontend_url() %>/signup?invitation_token=<%= @invitation_token %>
<%= invitation_url(@invitation_token) %>

A très vite !
2 changes: 1 addition & 1 deletion apps/cf/lib/cf_mailer/templates/newsletter.en.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<br><br>

<a href="<%= frontend_url() %>/newsletter/unsubscribe/<%= @user.newsletter_subscription_token %>"
<a href="<%= unsubscribe_newsletter_url(@user.newsletter_subscription_token) %>"
style="font-size: 15px;text-align: center;font-family: Ubuntu, Lato, Tahoma, sans-serif;background: aliceblue;padding: 1em;display: block;">
Unsubscribe from this newsletter
</a>
2 changes: 1 addition & 1 deletion apps/cf/lib/cf_mailer/templates/newsletter.en.text.eex
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

--------------------------------------------------------------------------------

Unsubscribe from this newsletter: <%= frontend_url() %>/newsletter/unsubscribe/<%= @user.newsletter_subscription_token %>
Unsubscribe from this newsletter: <%= unsubscribe_newsletter_url(@user.newsletter_subscription_token) %>
2 changes: 1 addition & 1 deletion apps/cf/lib/cf_mailer/templates/newsletter.fr.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<br><br>

<a href="<%= frontend_url() %>/newsletter/unsubscribe/<%= @user.newsletter_subscription_token %>"
<a href="<%= unsubscribe_newsletter_url(@user.newsletter_subscription_token) %>"
style="font-size: 15px;text-align: center;font-family: Ubuntu, Lato, Tahoma, sans-serif;background: aliceblue;padding: 1em;display: block;">
Se désinscrire de cette newsletter
</a>
2 changes: 1 addition & 1 deletion apps/cf/lib/cf_mailer/templates/newsletter.fr.text.eex
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

--------------------------------------------------------------------------------

Se désinscrire de cette newsletter: <%= frontend_url() %>/newsletter/unsubscribe/<%= @user.newsletter_subscription_token %>
Se désinscrire de cette newsletter: <%= unsubscribe_newsletter_url(@user.newsletter_subscription_token) %>
2 changes: 1 addition & 1 deletion apps/cf/lib/cf_mailer/templates/reset_password.en.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ You recently asked to reset your password on CF.

You can do so by following this link:

<a href="<%= frontend_url() %>/reset_password/confirm/<%= @reset_password_token %>">
<a href="<%= reset_password_url(@reset_password_token) %>">
Reset password
</a>

Expand Down
2 changes: 1 addition & 1 deletion apps/cf/lib/cf_mailer/templates/reset_password.en.text.eex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
You recently asked to reset your password on CF.

You can do so by following this link:
<%= frontend_url() %>/reset_password/confirm/<%= @reset_password_token %>
<%= reset_password_url(@reset_password_token) %>

Please ignore this email if the request is not comming from you.

Expand Down
2 changes: 1 addition & 1 deletion apps/cf/lib/cf_mailer/templates/reset_password.fr.html.eex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Vous avez demandé la réinitialisation de votre mot de passe sur CF.
Vous pouvez procéder au changement de mot de passe en suivant ce lien :

<a href="<%= frontend_url() %>/reset_password/confirm/<%= @reset_password_token %>">
<a href="<%= reset_password_url(@reset_password_token) %>">
Changer mon mot de passe
</a>

Expand Down
2 changes: 1 addition & 1 deletion apps/cf/lib/cf_mailer/templates/reset_password.fr.text.eex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Vous avez demandé la réinitialisation de votre mot de passe sur CF.

Vous pouvez procéder au changement de mot de passe en suivant ce lien :
<%= frontend_url() %>/reset_password/confirm/<%= @reset_password_token %>
<%= reset_password_url(@reset_password_token) %>

Merci d'ignorer cet email si la requête ne vient pas de vous.

Expand Down
4 changes: 2 additions & 2 deletions apps/cf/lib/cf_mailer/templates/welcome.en.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ Welcome to CaptainFact.io!<br>
<br>
To confirm your email and gain a bonus of
+<%= @confirm_email_reputation %> reputation, click on the following link:
<a href="<%= frontend_url() %>/confirm_email/<%= @user.email_confirmation_token %>">
<a href="<%= confirm_email_url(@user.email_confirmation_token) %>">
Confirm my email
</a>
<br><br>
You can learn more about how the system works by
checking <a href="<%= frontend_url() %>/help">the help pages</a>.
checking <a href="<%= help_url() %>">the help pages</a>.
<br><br>
Feel free to contact us
at <a href="mailto:[email protected]">[email protected]</a>.<br>
Expand Down
4 changes: 2 additions & 2 deletions apps/cf/lib/cf_mailer/templates/welcome.en.text.eex
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Welcome to CaptainFact.io!
To confirm your email and gain a bonus of
+<%= @confirm_email_reputation %> reputation, click on the following link:

<%= frontend_url() %>/confirm_email/<%= @user.email_confirmation_token %>
<%= confirm_email_url(@user.email_confirmation_token) %>

You can learn more about how the system works and the whys of CaptainFact by
checking the help pages at <%= frontend_url() %>/help
checking the help pages at <%= help_url() %>

Feel free to contact us at [email protected]

Expand Down
4 changes: 2 additions & 2 deletions apps/cf/lib/cf_mailer/templates/welcome.fr.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ Bienvenue sur CaptainFact !<br>
<br>
Pour confirmer votre adresse email et obtenir un bonus de
+<%= @confirm_email_reputation %> de réputation, cliquez sur le lien suivant :
<a href="<%= frontend_url() %>/confirm_email/<%= @user.email_confirmation_token %>">
<a href="<%= confirm_email_url(@user.email_confirmation_token) %>">
Confirmer mon adresse email
</a>
<br><br>
Vous pouvez en apprendre plus sur le fonctionnement du système en
allant voir les <a href="<%= frontend_url() %>/help">pages d'aide</a>.
allant voir les <a href="<%= help_url() %>">pages d'aide</a>.
<br><br>
Vous pouvez également nous contacter
sur <a href="mailto:[email protected]">[email protected]</a>.<br>
Expand Down
6 changes: 3 additions & 3 deletions apps/cf/lib/cf_mailer/templates/welcome.fr.text.eex
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Bienvenue sur CaptainFact !
Pour confirmer votre adresse email et obtenir un bonus de
+<%= @confirm_email_reputation %> de réputation, cliquez sur le lien suivant :

<%= frontend_url() %>/confirm_email/<%= @user.email_confirmation_token %>
<%= confirm_email_url(@user.email_confirmation_token) %>

Vous pouvez en apprendre plus sur le fonctionnement du système en
allant voir les pages d'aide : <%= frontend_url() %>/help
allant voir les pages d'aide : <%= help_url() %>

Vous pouvez également nous contacter [email protected]

Bon fact-checking !
Bon fact-checking !
5 changes: 1 addition & 4 deletions apps/cf/lib/cf_mailer/view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ defmodule CF.Mailer.View do
use Phoenix.HTML

import CF.Gettext

def frontend_url do
Application.fetch_env!(:cf, :frontend_url)
end
import CF.Utils.FrontendRouter

def user_appelation(user) do
DB.Schema.User.user_appelation(user)
Expand Down
79 changes: 79 additions & 0 deletions apps/cf/lib/utils/frontend_router.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
defmodule CF.Utils.FrontendRouter do
@moduledoc """
Generate routes matching Frontend URL.
"""

alias DB.Schema.User
alias DB.Schema.Speaker
alias DB.Schema.Comment

@doc """
Base frontend URL
"""
def base_url, do: Application.get_env(:cf, :frontend_url)

@doc """
Build an url for given path
"""
def url(path \\ "")
def url("/" <> path), do: base_url() <> path
def url(path), do: base_url() <> path

@doc """
User's profile page URL
"""
def user_url(%User{username: username}), do: url("u/#{username}")

@doc """
Video URL
"""
def video_url(video_hash_id), do: url("videos/#{video_hash_id}")

@doc """
Comment's URL
"""
def statement_url(video_hash_id, statement_id),
do: video_url(video_hash_id) <> "?statement=#{statement_id}"

@doc """
Comment's URL
"""
def comment_url(video_hash_id, %Comment{statement: statement}),
do: statement_url(video_hash_id, statement.id)

@doc """
Speaker URL
"""
def speaker_url(%Speaker{slug: slug, id: id}),
do: url("s/#{slug || id}")

@doc """
URL to unsubscribe from newsletter
"""
def unsubscribe_newsletter_url(newsletter_subscription_token),
do: url("newsletter/unsubscribe/#{newsletter_subscription_token}")

@doc """
URL to confirm email
"""
def confirm_email_url(email_confirmation_token),
do: url("confirm_email/#{email_confirmation_token}")

@doc """
URL to reset user password
"""
def reset_password_url(reset_password_token),
do: url("reset_password/confirm/#{reset_password_token}")

@doc """
URL to help pages
"""
def help_url(),
do: url("help")

@doc """
Invitation URL
"""
def invitation_url(token),
do: url("signup?invitation_token=#{token}")
end
File renamed without changes.
1 change: 0 additions & 1 deletion apps/cf/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ defmodule CF.Mixfile do

# ---- Internal ----
{:db, in_umbrella: true},
{:cf_utils, in_umbrella: true},

# Dev only
{:exsync, "~> 0.2", only: :dev},
Expand Down
2 changes: 1 addition & 1 deletion apps/cf/test/cf/videos/videos_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ defmodule CF.VideosTest do

describe "Fetch captions" do
test "fetch captions" do
video = DB.Factory.insert(:video, provider: "__TEST__")
video = DB.Factory.insert(:video, provider: "__TEST__", language: "en")
{:ok, captions} = Videos.download_captions(video)

assert captions.content == "__TEST-CONTENT__"
Expand Down
Loading

0 comments on commit d8d1fb2

Please sign in to comment.