From 9b4c95df8d219196f9ffca87c941183965f8e979 Mon Sep 17 00:00:00 2001 From: Matheus Buss Date: Sun, 8 May 2022 15:25:49 -0300 Subject: [PATCH 01/21] Created rich_link_controller and functionalities --- .../controllers/rich_link_controller.ex | 33 +++++++++++++++++++ lib/cambiatus_web/resolvers/accounts.ex | 18 ++++++++++ lib/cambiatus_web/resolvers/commune.ex | 18 ++++++++++ lib/cambiatus_web/resolvers/shop.ex | 18 ++++++++++ lib/cambiatus_web/router.ex | 1 + .../templates/rich_link.html.eex | 22 +++++++++++++ 6 files changed, 110 insertions(+) create mode 100644 lib/cambiatus_web/controllers/rich_link_controller.ex create mode 100644 lib/cambiatus_web/templates/rich_link.html.eex diff --git a/lib/cambiatus_web/controllers/rich_link_controller.ex b/lib/cambiatus_web/controllers/rich_link_controller.ex new file mode 100644 index 00000000..8988124d --- /dev/null +++ b/lib/cambiatus_web/controllers/rich_link_controller.ex @@ -0,0 +1,33 @@ +defmodule CambiatusWeb.RichLinkController do + use CambiatusWeb, :controller + + alias CambiatusWeb.Resolvers.{Accounts, Commune, Shop} + + @rich_link_file Path.expand("../templates/rich_link.html.eex", __DIR__) + + def rich_link(conn, params) do + data = + case Map.get(params, "page") do + ["shop"] -> + Shop.get_product_rich_link(Map.get(params, "id")) + + ["profile", user] -> + Accounts.get_user_rich_link(user) + + [] -> + Commune.get_community_rich_link(conn.host) + + _ -> + send_resp(conn, 404, "Category not found") + end + + case data do + {:ok, data} -> + response = EEx.eval_file(@rich_link_file, Enum.into(data, [])) + html(conn, response) + + {:error, reason} -> + send_resp(conn, 404, reason) + end + end +end diff --git a/lib/cambiatus_web/resolvers/accounts.ex b/lib/cambiatus_web/resolvers/accounts.ex index fa07f26e..174f9147 100755 --- a/lib/cambiatus_web/resolvers/accounts.ex +++ b/lib/cambiatus_web/resolvers/accounts.ex @@ -218,4 +218,22 @@ defmodule CambiatusWeb.Resolvers.Accounts do def get_contribution_count(%User{} = user, _, _) do Accounts.get_contribution_count(user) end + + def get_user_rich_link(account) do + case get_user(nil, %{account: account}, nil) do + {:ok, user} -> + {:ok, + %{ + name: user.name, + description: user.bio, + title: user.name, + url: user.email, + image: user.avatar, + locale: user.location + }} + + {:error, reason} -> + {:error, reason} + end + end end diff --git a/lib/cambiatus_web/resolvers/commune.ex b/lib/cambiatus_web/resolvers/commune.ex index 0e664fc8..adcc4f4b 100755 --- a/lib/cambiatus_web/resolvers/commune.ex +++ b/lib/cambiatus_web/resolvers/commune.ex @@ -144,4 +144,22 @@ defmodule CambiatusWeb.Resolvers.Commune do highlighted_news: community_id ) end + + def get_community_rich_link(community_subdomain) do + case find_community(%{}, %{subdomain: community_subdomain}, %{}) do + {:ok, community} -> + {:ok, + %{ + name: community.name, + description: community.description, + title: community.name, + url: community_subdomain, + image: community.logo, + locale: nil + }} + + {:error, reason} -> + {:error, reason} + end + end end diff --git a/lib/cambiatus_web/resolvers/shop.ex b/lib/cambiatus_web/resolvers/shop.ex index 907dd21f..624250db 100644 --- a/lib/cambiatus_web/resolvers/shop.ex +++ b/lib/cambiatus_web/resolvers/shop.ex @@ -69,4 +69,22 @@ defmodule CambiatusWeb.Resolvers.Shop do {:ok, %{status: :success, reason: message}} end end + + def get_product_rich_link(id) do + case get_product(nil, %{id: id}, nil) do + {:ok, product} -> + {:ok, + %{ + name: product.title, + description: product.description, + title: product.title, + url: nil, + image: product.image, + locale: nil + }} + + {:error, reason} -> + {:error, reason} + end + end end diff --git a/lib/cambiatus_web/router.ex b/lib/cambiatus_web/router.ex index c4bff93c..1a14b84b 100755 --- a/lib/cambiatus_web/router.ex +++ b/lib/cambiatus_web/router.ex @@ -51,6 +51,7 @@ defmodule CambiatusWeb.Router do get("/chain/info", ChainController, :info) post("/invite", InviteController, :invite) get("/manifest", ManifestController, :manifest) + get("/rich_link/*page", RichLinkController, :rich_link) post("/paypal", PaypalController, :index) end diff --git a/lib/cambiatus_web/templates/rich_link.html.eex b/lib/cambiatus_web/templates/rich_link.html.eex new file mode 100644 index 00000000..0ddf9681 --- /dev/null +++ b/lib/cambiatus_web/templates/rich_link.html.eex @@ -0,0 +1,22 @@ + + + + + + + + + + > + > + > + + > + > + > + + <%= title %> + From 75213d659db15198319278397c62f4c57880e776 Mon Sep 17 00:00:00 2001 From: Matheus da Cunha Buss Date: Tue, 10 May 2022 23:17:16 -0300 Subject: [PATCH 02/21] Updated rich_link to accept markdown. Added pandex --- .../controllers/rich_link_controller.ex | 18 ++++++++++++++++-- lib/cambiatus_web/templates/rich_link.html.eex | 8 ++++---- mix.exs | 1 + 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/cambiatus_web/controllers/rich_link_controller.ex b/lib/cambiatus_web/controllers/rich_link_controller.ex index 8988124d..03ae3a0e 100644 --- a/lib/cambiatus_web/controllers/rich_link_controller.ex +++ b/lib/cambiatus_web/controllers/rich_link_controller.ex @@ -2,6 +2,7 @@ defmodule CambiatusWeb.RichLinkController do use CambiatusWeb, :controller alias CambiatusWeb.Resolvers.{Accounts, Commune, Shop} + require Pandex @rich_link_file Path.expand("../templates/rich_link.html.eex", __DIR__) @@ -23,11 +24,24 @@ defmodule CambiatusWeb.RichLinkController do case data do {:ok, data} -> - response = EEx.eval_file(@rich_link_file, Enum.into(data, [])) - html(conn, response) + response = + data + |> Enum.map(fn {k, v} -> {k, md_to_txt(v)} end) + |> Enum.into([]) + + html(conn, EEx.eval_file(@rich_link_file, response)) {:error, reason} -> send_resp(conn, 404, reason) end end + + defp md_to_txt(markdown) do + with {:ok, string} <- Pandex.markdown_to_plain(markdown) do + String.trim(string) + else + {:error, _} -> + "" + end + end end diff --git a/lib/cambiatus_web/templates/rich_link.html.eex b/lib/cambiatus_web/templates/rich_link.html.eex index 0ddf9681..12335d9d 100644 --- a/lib/cambiatus_web/templates/rich_link.html.eex +++ b/lib/cambiatus_web/templates/rich_link.html.eex @@ -10,11 +10,11 @@ --> - > - > - > + + + - > + > > diff --git a/mix.exs b/mix.exs index 5747d0fa..6fef4601 100755 --- a/mix.exs +++ b/mix.exs @@ -49,6 +49,7 @@ defmodule Cambiatus.Mixfile do {:ex_phone_number, "~> 0.2"}, {:number, "~> 1.0"}, {:earmark, "~> 1.4"}, + {:pandex, "~> 0.2.0"}, # Email capabilities {:swoosh, "~> 1.0"}, From 18097d65453bade152cccdf9488eb98df74853b5 Mon Sep 17 00:00:00 2001 From: Matheus Buss Date: Thu, 12 May 2022 09:38:34 -0300 Subject: [PATCH 03/21] Created rich_link_controller_test. Replaced query functions --- .../controllers/rich_link_controller.ex | 77 +++++++++-- lib/cambiatus_web/resolvers/accounts.ex | 18 --- lib/cambiatus_web/resolvers/commune.ex | 18 --- lib/cambiatus_web/resolvers/shop.ex | 18 --- .../templates/rich_link.html.eex | 8 +- mix.exs | 2 +- .../controllers/rich_link_controller_test.exs | 121 ++++++++++++++++++ 7 files changed, 192 insertions(+), 70 deletions(-) create mode 100644 test/cambiatus_web/controllers/rich_link_controller_test.exs diff --git a/lib/cambiatus_web/controllers/rich_link_controller.ex b/lib/cambiatus_web/controllers/rich_link_controller.ex index 03ae3a0e..9144d774 100644 --- a/lib/cambiatus_web/controllers/rich_link_controller.ex +++ b/lib/cambiatus_web/controllers/rich_link_controller.ex @@ -2,7 +2,9 @@ defmodule CambiatusWeb.RichLinkController do use CambiatusWeb, :controller alias CambiatusWeb.Resolvers.{Accounts, Commune, Shop} - require Pandex + alias Cambiatus.Repo + require Earmark + require HtmlSanitizeEx @rich_link_file Path.expand("../templates/rich_link.html.eex", __DIR__) @@ -10,13 +12,13 @@ defmodule CambiatusWeb.RichLinkController do data = case Map.get(params, "page") do ["shop"] -> - Shop.get_product_rich_link(Map.get(params, "id")) + product_rich_link(Map.get(params, "id")) - ["profile", user] -> - Accounts.get_user_rich_link(user) + ["profile", account] -> + user_rich_link(account) [] -> - Commune.get_community_rich_link(conn.host) + community_rich_link(conn.host) _ -> send_resp(conn, 404, "Category not found") @@ -25,8 +27,7 @@ defmodule CambiatusWeb.RichLinkController do case data do {:ok, data} -> response = - data - |> Enum.map(fn {k, v} -> {k, md_to_txt(v)} end) + %{data | description: md_to_txt(data.description)} |> Enum.into([]) html(conn, EEx.eval_file(@rich_link_file, response)) @@ -36,9 +37,67 @@ defmodule CambiatusWeb.RichLinkController do end end + def product_rich_link(id) do + case Shop.get_product(nil, %{id: id}, nil) do + {:ok, product} -> + product = Repo.preload(product, :images) + [image | _] = product.images + + {:ok, + %{ + name: product.title, + description: product.description, + title: product.title, + url: nil, + image: image.uri, + locale: nil + }} + + {:error, reason} -> + {:error, reason} + end + end + + def user_rich_link(account) do + case Accounts.get_user(nil, %{account: account}, nil) do + {:ok, user} -> + {:ok, + %{ + name: user.name, + description: user.bio, + title: user.name, + url: user.email, + image: user.avatar, + locale: user.location + }} + + {:error, reason} -> + {:error, reason} + end + end + + def community_rich_link(community_subdomain) do + case Commune.find_community(%{}, %{subdomain: community_subdomain}, %{}) do + {:ok, community} -> + {:ok, + %{ + name: community.name, + description: community.description, + title: community.name, + url: community_subdomain, + image: community.logo, + locale: nil + }} + + {:error, reason} -> + {:error, reason} + end + end + defp md_to_txt(markdown) do - with {:ok, string} <- Pandex.markdown_to_plain(markdown) do - String.trim(string) + with {:ok, string, _} <- Earmark.as_html(markdown) do + HtmlSanitizeEx.strip_tags(string) + |> String.trim() else {:error, _} -> "" diff --git a/lib/cambiatus_web/resolvers/accounts.ex b/lib/cambiatus_web/resolvers/accounts.ex index 174f9147..fa07f26e 100755 --- a/lib/cambiatus_web/resolvers/accounts.ex +++ b/lib/cambiatus_web/resolvers/accounts.ex @@ -218,22 +218,4 @@ defmodule CambiatusWeb.Resolvers.Accounts do def get_contribution_count(%User{} = user, _, _) do Accounts.get_contribution_count(user) end - - def get_user_rich_link(account) do - case get_user(nil, %{account: account}, nil) do - {:ok, user} -> - {:ok, - %{ - name: user.name, - description: user.bio, - title: user.name, - url: user.email, - image: user.avatar, - locale: user.location - }} - - {:error, reason} -> - {:error, reason} - end - end end diff --git a/lib/cambiatus_web/resolvers/commune.ex b/lib/cambiatus_web/resolvers/commune.ex index adcc4f4b..0e664fc8 100755 --- a/lib/cambiatus_web/resolvers/commune.ex +++ b/lib/cambiatus_web/resolvers/commune.ex @@ -144,22 +144,4 @@ defmodule CambiatusWeb.Resolvers.Commune do highlighted_news: community_id ) end - - def get_community_rich_link(community_subdomain) do - case find_community(%{}, %{subdomain: community_subdomain}, %{}) do - {:ok, community} -> - {:ok, - %{ - name: community.name, - description: community.description, - title: community.name, - url: community_subdomain, - image: community.logo, - locale: nil - }} - - {:error, reason} -> - {:error, reason} - end - end end diff --git a/lib/cambiatus_web/resolvers/shop.ex b/lib/cambiatus_web/resolvers/shop.ex index 624250db..907dd21f 100644 --- a/lib/cambiatus_web/resolvers/shop.ex +++ b/lib/cambiatus_web/resolvers/shop.ex @@ -69,22 +69,4 @@ defmodule CambiatusWeb.Resolvers.Shop do {:ok, %{status: :success, reason: message}} end end - - def get_product_rich_link(id) do - case get_product(nil, %{id: id}, nil) do - {:ok, product} -> - {:ok, - %{ - name: product.title, - description: product.description, - title: product.title, - url: nil, - image: product.image, - locale: nil - }} - - {:error, reason} -> - {:error, reason} - end - end end diff --git a/lib/cambiatus_web/templates/rich_link.html.eex b/lib/cambiatus_web/templates/rich_link.html.eex index 12335d9d..d9252bbf 100644 --- a/lib/cambiatus_web/templates/rich_link.html.eex +++ b/lib/cambiatus_web/templates/rich_link.html.eex @@ -4,10 +4,6 @@ - @@ -15,8 +11,8 @@ - > - > + + <%= title %> diff --git a/mix.exs b/mix.exs index 6fef4601..5a3e9326 100755 --- a/mix.exs +++ b/mix.exs @@ -49,7 +49,7 @@ defmodule Cambiatus.Mixfile do {:ex_phone_number, "~> 0.2"}, {:number, "~> 1.0"}, {:earmark, "~> 1.4"}, - {:pandex, "~> 0.2.0"}, + {:html_sanitize_ex, "~> 1.4"}, # Email capabilities {:swoosh, "~> 1.0"}, diff --git a/test/cambiatus_web/controllers/rich_link_controller_test.exs b/test/cambiatus_web/controllers/rich_link_controller_test.exs new file mode 100644 index 00000000..1a4811c5 --- /dev/null +++ b/test/cambiatus_web/controllers/rich_link_controller_test.exs @@ -0,0 +1,121 @@ +defmodule CambiatusWeb.RichLinkControllerTest do + use Cambiatus.DataCase + use CambiatusWeb.ConnCase + + alias Cambiatus.Repo + + @rich_link_file Path.expand("../../../lib/cambiatus_web/templates/rich_link.html.eex", __DIR__) + + setup %{conn: conn} do + {:ok, conn: put_req_header(conn, "accept", "application/json")} + end + + describe "RichLink" do + test "generate rich link for community", + %{conn: conn} do + # Get community for DataCase.valid_community_and_user, + # pattern match community for name and subdomain, + # insert subdomain name into conn + community = + insert(:community) + |> Repo.preload(:subdomain) + + data = %{ + name: community.name, + description: community.description, + title: community.name, + url: community.subdomain.name, + image: community.logo, + locale: nil + } + + expected_response = + %{data | description: md_to_txt(data.description)} + |> Enum.into([]) + + conn = + %{conn | host: community.subdomain.name} + |> get("/api/rich_link") + + response = html_response(conn, 200) + + # Check http code 200 and if the community name served is the same generated + assert conn.status == 200 + assert EEx.eval_file(@rich_link_file, expected_response) == response + end + + test "generate rich link for user", + %{conn: conn} do + # Get community for DataCase.valid_community_and_user, + # pattern match community for name and subdomain, + # insert subdomain name into conn + # community = Repo.preload(community, :subdomain) + + user = insert(:user) + + data = %{ + name: user.name, + description: user.bio, + title: user.name, + url: user.email, + image: user.avatar, + locale: user.location + } + + expected_response = + %{data | description: md_to_txt(data.description)} + |> Enum.into([]) + + conn = get(conn, "/api/rich_link/profile/#{user.account}") + + response = html_response(conn, 200) + + # Check http code 200 and if the community name served is the same generated + assert conn.status == 200 + assert EEx.eval_file(@rich_link_file, expected_response) == response + end + + test "generate rich link for product", + %{conn: conn} do + # Get community for DataCase.valid_community_and_user, + # pattern match community for name and subdomain, + # insert subdomain name into conn + product = + insert(:product) + |> Repo.preload(:images) + + [image | _] = product.images + + data = %{ + name: product.title, + description: product.description, + title: product.title, + url: nil, + image: image.uri, + locale: nil + } + + expected_response = + %{data | description: md_to_txt(data.description)} + |> Enum.into([]) + + conn = get(conn, "/api/rich_link/shop?id=#{product.id}") + + response = html_response(conn, 200) + + # Check http code 200 and if the community name served is the same generated + assert conn.status == 200 + assert EEx.eval_file(@rich_link_file, expected_response) == response + end + end + + defp md_to_txt(markdown) do + with {:ok, string, _} <- Earmark.as_html(markdown) do + HtmlSanitizeEx.strip_tags(string) + |> String.trim() + else + {:error, _} -> + "" + end + end +end From c8cf9a602a6562f6ce92807ea0f7dbab1e94a389 Mon Sep 17 00:00:00 2001 From: Matheus Buss Date: Fri, 13 May 2022 10:57:06 -0300 Subject: [PATCH 04/21] Using Elixir's views. Updated tests --- .../controllers/rich_link_controller.ex | 21 +++--- .../templates/layout/app.html.eex | 1 + .../templates/rich_link.html.eex | 18 ----- .../templates/rich_link/rich_link.html.eex | 18 +++++ lib/cambiatus_web/views/rich_link_view.ex | 3 + .../controllers/rich_link_controller_test.exs | 66 ++++++++----------- 6 files changed, 58 insertions(+), 69 deletions(-) create mode 100644 lib/cambiatus_web/templates/layout/app.html.eex delete mode 100644 lib/cambiatus_web/templates/rich_link.html.eex create mode 100644 lib/cambiatus_web/templates/rich_link/rich_link.html.eex create mode 100644 lib/cambiatus_web/views/rich_link_view.ex diff --git a/lib/cambiatus_web/controllers/rich_link_controller.ex b/lib/cambiatus_web/controllers/rich_link_controller.ex index 9144d774..19fb08a8 100644 --- a/lib/cambiatus_web/controllers/rich_link_controller.ex +++ b/lib/cambiatus_web/controllers/rich_link_controller.ex @@ -1,18 +1,21 @@ defmodule CambiatusWeb.RichLinkController do use CambiatusWeb, :controller + @moduledoc """ + Get data and render html to be used for rich links (also known as Open Graphs). + These rich links show additional information about the website when shared on social media and must be compliant with the [Open Grap Protocol](https://ogp.me/) + """ + alias CambiatusWeb.Resolvers.{Accounts, Commune, Shop} alias Cambiatus.Repo require Earmark require HtmlSanitizeEx - @rich_link_file Path.expand("../templates/rich_link.html.eex", __DIR__) - def rich_link(conn, params) do data = case Map.get(params, "page") do - ["shop"] -> - product_rich_link(Map.get(params, "id")) + ["shop", id] -> + product_rich_link(id) ["profile", account] -> user_rich_link(account) @@ -26,11 +29,8 @@ defmodule CambiatusWeb.RichLinkController do case data do {:ok, data} -> - response = - %{data | description: md_to_txt(data.description)} - |> Enum.into([]) - - html(conn, EEx.eval_file(@rich_link_file, response)) + data = %{data | description: md_to_txt(data.description)} + render(conn, "rich_link.html", %{data: data}) {:error, reason} -> send_resp(conn, 404, reason) @@ -45,7 +45,6 @@ defmodule CambiatusWeb.RichLinkController do {:ok, %{ - name: product.title, description: product.description, title: product.title, url: nil, @@ -63,7 +62,6 @@ defmodule CambiatusWeb.RichLinkController do {:ok, user} -> {:ok, %{ - name: user.name, description: user.bio, title: user.name, url: user.email, @@ -81,7 +79,6 @@ defmodule CambiatusWeb.RichLinkController do {:ok, community} -> {:ok, %{ - name: community.name, description: community.description, title: community.name, url: community_subdomain, diff --git a/lib/cambiatus_web/templates/layout/app.html.eex b/lib/cambiatus_web/templates/layout/app.html.eex new file mode 100644 index 00000000..05433985 --- /dev/null +++ b/lib/cambiatus_web/templates/layout/app.html.eex @@ -0,0 +1 @@ +<%= @inner_content %> diff --git a/lib/cambiatus_web/templates/rich_link.html.eex b/lib/cambiatus_web/templates/rich_link.html.eex deleted file mode 100644 index d9252bbf..00000000 --- a/lib/cambiatus_web/templates/rich_link.html.eex +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - <%= title %> - diff --git a/lib/cambiatus_web/templates/rich_link/rich_link.html.eex b/lib/cambiatus_web/templates/rich_link/rich_link.html.eex new file mode 100644 index 00000000..33c23ca3 --- /dev/null +++ b/lib/cambiatus_web/templates/rich_link/rich_link.html.eex @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + "<%= @data.title %>" + diff --git a/lib/cambiatus_web/views/rich_link_view.ex b/lib/cambiatus_web/views/rich_link_view.ex new file mode 100644 index 00000000..3f542fd7 --- /dev/null +++ b/lib/cambiatus_web/views/rich_link_view.ex @@ -0,0 +1,3 @@ +defmodule CambiatusWeb.RichLinkView do + use CambiatusWeb, :view +end diff --git a/test/cambiatus_web/controllers/rich_link_controller_test.exs b/test/cambiatus_web/controllers/rich_link_controller_test.exs index 1a4811c5..7d7e264c 100644 --- a/test/cambiatus_web/controllers/rich_link_controller_test.exs +++ b/test/cambiatus_web/controllers/rich_link_controller_test.exs @@ -4,8 +4,6 @@ defmodule CambiatusWeb.RichLinkControllerTest do alias Cambiatus.Repo - @rich_link_file Path.expand("../../../lib/cambiatus_web/templates/rich_link.html.eex", __DIR__) - setup %{conn: conn} do {:ok, conn: put_req_header(conn, "accept", "application/json")} end @@ -13,73 +11,64 @@ defmodule CambiatusWeb.RichLinkControllerTest do describe "RichLink" do test "generate rich link for community", %{conn: conn} do - # Get community for DataCase.valid_community_and_user, - # pattern match community for name and subdomain, - # insert subdomain name into conn + # Insert community and extract data for the rich link community = insert(:community) |> Repo.preload(:subdomain) data = %{ - name: community.name, - description: community.description, + description: md_to_txt(community.description), title: community.name, url: community.subdomain.name, image: community.logo, locale: nil } - expected_response = - %{data | description: md_to_txt(data.description)} - |> Enum.into([]) - + # Submit GET request for a community rich link conn = %{conn | host: community.subdomain.name} |> get("/api/rich_link") response = html_response(conn, 200) - # Check http code 200 and if the community name served is the same generated + # Check http code 200 and if all the rich link fields are properly filled assert conn.status == 200 - assert EEx.eval_file(@rich_link_file, expected_response) == response + + Enum.each(data, fn {k, v} -> + assert String.match?(response, ~r/meta property=\"og:#{k}\" content=\"#{v}/) + end) end test "generate rich link for user", %{conn: conn} do - # Get community for DataCase.valid_community_and_user, - # pattern match community for name and subdomain, - # insert subdomain name into conn - # community = Repo.preload(community, :subdomain) + # Insert user and extract data for the rich link user = insert(:user) data = %{ - name: user.name, - description: user.bio, + description: md_to_txt(user.bio), title: user.name, url: user.email, image: user.avatar, locale: user.location } - expected_response = - %{data | description: md_to_txt(data.description)} - |> Enum.into([]) - + # Submit GET request for a user rich link conn = get(conn, "/api/rich_link/profile/#{user.account}") - response = html_response(conn, 200) - # Check http code 200 and if the community name served is the same generated + # Check http code 200 and if all the rich link fields are properly filled assert conn.status == 200 - assert EEx.eval_file(@rich_link_file, expected_response) == response + + Enum.each(data, fn {k, v} -> + assert String.match?(response, ~r/meta property=\"og:#{k}\" content=\"#{v}/) + end) end test "generate rich link for product", %{conn: conn} do - # Get community for DataCase.valid_community_and_user, - # pattern match community for name and subdomain, - # insert subdomain name into conn + # Insert product and extract data for the rich link + product = insert(:product) |> Repo.preload(:images) @@ -87,29 +76,28 @@ defmodule CambiatusWeb.RichLinkControllerTest do [image | _] = product.images data = %{ - name: product.title, - description: product.description, + description: md_to_txt(product.description), title: product.title, url: nil, image: image.uri, locale: nil } - expected_response = - %{data | description: md_to_txt(data.description)} - |> Enum.into([]) - - conn = get(conn, "/api/rich_link/shop?id=#{product.id}") - + # Submit GET request for a product rich link + conn = get(conn, "/api/rich_link/shop/#{product.id}") response = html_response(conn, 200) - # Check http code 200 and if the community name served is the same generated + # Check http code 200 and if all the rich link fields are properly filled assert conn.status == 200 - assert EEx.eval_file(@rich_link_file, expected_response) == response + + Enum.each(data, fn {k, v} -> + assert String.match?(response, ~r/meta property=\"og:#{k}\" content=\"#{v}/) + end) end end defp md_to_txt(markdown) do + # Convert markdown to plain text with {:ok, string, _} <- Earmark.as_html(markdown) do HtmlSanitizeEx.strip_tags(string) |> String.trim() From 79b4a78c8bfb073ae6e1812556732c892da04ad6 Mon Sep 17 00:00:00 2001 From: Matheus Buss Date: Fri, 13 May 2022 11:44:32 -0300 Subject: [PATCH 05/21] Moved sanitizer from controller to view --- .../controllers/rich_link_controller.ex | 16 ++-------------- .../templates/rich_link/rich_link.html.eex | 4 ++-- lib/cambiatus_web/views/rich_link_view.ex | 13 +++++++++++++ .../controllers/rich_link_controller_test.exs | 12 ++++++------ 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/lib/cambiatus_web/controllers/rich_link_controller.ex b/lib/cambiatus_web/controllers/rich_link_controller.ex index 19fb08a8..c706ef04 100644 --- a/lib/cambiatus_web/controllers/rich_link_controller.ex +++ b/lib/cambiatus_web/controllers/rich_link_controller.ex @@ -3,13 +3,12 @@ defmodule CambiatusWeb.RichLinkController do @moduledoc """ Get data and render html to be used for rich links (also known as Open Graphs). - These rich links show additional information about the website when shared on social media and must be compliant with the [Open Grap Protocol](https://ogp.me/) + These rich links show additional information about the website when shared on social media + and must be compliant with the [Open Grap Protocol](https://ogp.me/) """ alias CambiatusWeb.Resolvers.{Accounts, Commune, Shop} alias Cambiatus.Repo - require Earmark - require HtmlSanitizeEx def rich_link(conn, params) do data = @@ -29,7 +28,6 @@ defmodule CambiatusWeb.RichLinkController do case data do {:ok, data} -> - data = %{data | description: md_to_txt(data.description)} render(conn, "rich_link.html", %{data: data}) {:error, reason} -> @@ -90,14 +88,4 @@ defmodule CambiatusWeb.RichLinkController do {:error, reason} end end - - defp md_to_txt(markdown) do - with {:ok, string, _} <- Earmark.as_html(markdown) do - HtmlSanitizeEx.strip_tags(string) - |> String.trim() - else - {:error, _} -> - "" - end - end end diff --git a/lib/cambiatus_web/templates/rich_link/rich_link.html.eex b/lib/cambiatus_web/templates/rich_link/rich_link.html.eex index 33c23ca3..9fd9b2dc 100644 --- a/lib/cambiatus_web/templates/rich_link/rich_link.html.eex +++ b/lib/cambiatus_web/templates/rich_link/rich_link.html.eex @@ -6,8 +6,8 @@ - - + + diff --git a/lib/cambiatus_web/views/rich_link_view.ex b/lib/cambiatus_web/views/rich_link_view.ex index 3f542fd7..351a5117 100644 --- a/lib/cambiatus_web/views/rich_link_view.ex +++ b/lib/cambiatus_web/views/rich_link_view.ex @@ -1,3 +1,16 @@ defmodule CambiatusWeb.RichLinkView do use CambiatusWeb, :view + + require Earmark + require HtmlSanitizeEx + + def md_to_txt(markdown) do + with {:ok, string, _} <- Earmark.as_html(markdown) do + HtmlSanitizeEx.strip_tags(string) + |> String.trim() + else + {:error, _} -> + "" + end + end end diff --git a/test/cambiatus_web/controllers/rich_link_controller_test.exs b/test/cambiatus_web/controllers/rich_link_controller_test.exs index 7d7e264c..07028daa 100644 --- a/test/cambiatus_web/controllers/rich_link_controller_test.exs +++ b/test/cambiatus_web/controllers/rich_link_controller_test.exs @@ -16,7 +16,7 @@ defmodule CambiatusWeb.RichLinkControllerTest do insert(:community) |> Repo.preload(:subdomain) - data = %{ + expected_data = %{ description: md_to_txt(community.description), title: community.name, url: community.subdomain.name, @@ -34,7 +34,7 @@ defmodule CambiatusWeb.RichLinkControllerTest do # Check http code 200 and if all the rich link fields are properly filled assert conn.status == 200 - Enum.each(data, fn {k, v} -> + Enum.each(expected_data, fn {k, v} -> assert String.match?(response, ~r/meta property=\"og:#{k}\" content=\"#{v}/) end) end @@ -45,7 +45,7 @@ defmodule CambiatusWeb.RichLinkControllerTest do user = insert(:user) - data = %{ + expected_data = %{ description: md_to_txt(user.bio), title: user.name, url: user.email, @@ -60,7 +60,7 @@ defmodule CambiatusWeb.RichLinkControllerTest do # Check http code 200 and if all the rich link fields are properly filled assert conn.status == 200 - Enum.each(data, fn {k, v} -> + Enum.each(expected_data, fn {k, v} -> assert String.match?(response, ~r/meta property=\"og:#{k}\" content=\"#{v}/) end) end @@ -75,7 +75,7 @@ defmodule CambiatusWeb.RichLinkControllerTest do [image | _] = product.images - data = %{ + expected_data = %{ description: md_to_txt(product.description), title: product.title, url: nil, @@ -90,7 +90,7 @@ defmodule CambiatusWeb.RichLinkControllerTest do # Check http code 200 and if all the rich link fields are properly filled assert conn.status == 200 - Enum.each(data, fn {k, v} -> + Enum.each(expected_data, fn {k, v} -> assert String.match?(response, ~r/meta property=\"og:#{k}\" content=\"#{v}/) end) end From dca921a3e49d8a10526dfb15e77b7a3b0cdb923b Mon Sep 17 00:00:00 2001 From: Matheus Buss Date: Fri, 13 May 2022 12:05:04 -0300 Subject: [PATCH 06/21] Moved moduledoc on rich_link_controller --- lib/cambiatus_web/controllers/rich_link_controller.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cambiatus_web/controllers/rich_link_controller.ex b/lib/cambiatus_web/controllers/rich_link_controller.ex index c706ef04..70f69d4e 100644 --- a/lib/cambiatus_web/controllers/rich_link_controller.ex +++ b/lib/cambiatus_web/controllers/rich_link_controller.ex @@ -1,12 +1,12 @@ defmodule CambiatusWeb.RichLinkController do - use CambiatusWeb, :controller - @moduledoc """ Get data and render html to be used for rich links (also known as Open Graphs). These rich links show additional information about the website when shared on social media and must be compliant with the [Open Grap Protocol](https://ogp.me/) """ + use CambiatusWeb, :controller + alias CambiatusWeb.Resolvers.{Accounts, Commune, Shop} alias Cambiatus.Repo From 056e6a8ba125fbb236c0d2c0bacae0d47d119d12 Mon Sep 17 00:00:00 2001 From: Matheus Buss Date: Tue, 17 May 2022 09:58:10 -0300 Subject: [PATCH 07/21] Added nginx.conf and nginx instructions --- README.md | 23 ++++++ nginx/nginx.conf | 204 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 227 insertions(+) create mode 100644 nginx/nginx.conf diff --git a/README.md b/README.md index baaab326..c901264c 100755 --- a/README.md +++ b/README.md @@ -66,6 +66,10 @@ Here is our [GraphQL wiki](https://cambiatus.github.io/onboarding.md) page - EOS Blockchain main [documentation](https://developers.eos.io/welcome/latest/overview/index) page - Here is [our documentation](eos.md) on how we use EOS blockchain +**HTTP server** + +- [NGINX](https://nginx.org/en/docs/) main documentation page + ## Development Environment Setup To build and run this application locally follow the following steps! @@ -120,6 +124,25 @@ Now you can visit [`localhost:4000`](http://localhost:4000) from your browser. #Boom! Now you can hack away! +## NGINX setup + +To setup NGINX on your machine (as localhost) follow these steps! + +**Step 1** + +Replace the original configuration file (`nginx.conf`) with the one [inside this repo](/nginx/nginx.conf) + +- Note 1: To run on your local machine you'll need to update all `root` directives to reflect where the files are located on your machine (such as on line 104) + +- Note 2: For Windows users it is recommended to install NGINX under the C:\Program Files directory + +**Step 2** + +Open a terminal and `cd` into NGINX's installation directory and run +``` +nginx +``` +Now you can make HTTP requests to NGINX on your browser under localhost! ## Contributing When you are ready to make your first contribution please check out our [contribution guide](/.github/contributing.md), this will get your up to speed on where and how to start. diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 00000000..0d068f5c --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,204 @@ + +#user nobody; +worker_processes 1; + +#error_log logs/error.log; +#error_log logs/error.log notice; +#error_log logs/error.log info; + +#pid logs/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include mime.types; + default_type application/octet-stream; + + #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + # '$status $body_bytes_sent "$http_referer" ' + # '"$http_user_agent" "$http_x_forwarded_for"'; + + #access_log logs/access.log main; + + sendfile on; + #tcp_nopush on; + + #keepalive_timeout 0; + keepalive_timeout 65; + + #gzip on; + upstream netdataback { + server unix:/var/run/netdata/netdata.sock; + keepalive 64; + } + + server { + server_name dev-eosio.cambiatus.io; + location / { + proxy_pass http://127.0.0.1:58888/; + } + + listen 443 ssl; # managed by Certbot + ssl_certificate /etc/letsencrypt/live/dev-eosio.cambiatus.io/fullchain.pem; # managed by Certbot + ssl_certificate_key /etc/letsencrypt/live/dev-eosio.cambiatus.io/privkey.pem; # managed by Certbot + include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot + ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot + } + + server { + if ($host = dev-eosio.cambiatus.io) { + return 301 https://$host$request_uri; + } # managed by Certbot + + + listen 80; + server_name dev-eosio.cambiatus.io; + return 404; # managed by Certbot + + + } + + server { + listen 80; + server_name natus.cambiatus.io www.natus.cambiatus.io; + return 301 https://natus.cambiatus.io$request_uri; + } + + server { + listen 443 ssl http2; + server_name natus.cambiatus.io www.natus.cambiatus.io; + + root /home/ubuntu/apps/natus.webapp; + index index.html; + + location / { + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_pass http://127.0.0.1:8033; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + # asset delivery using NGINX + location ~* ^.+\.(css|cur|gif|gz|ico|jpg|jpeg|js|png|svg|woff|woff2)$ { + root /home/ubuntu/apps/natus.webapp/priv/static; + etag off; + expires max; + add_header Cache-Control public; + } + } + + ssl_certificate /etc/letsencrypt/live/natus.cambiatus.io/fullchain.pem; # managed by Certbot + ssl_certificate_key /etc/letsencrypt/live/natus.cambiatus.io/privkey.pem; # managed by Certbot + include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot + ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot + } + + + server { + root /home/ubuntu/apps/frontend/build; + index index.html; + + server_name staging.cambiatus.io *.staging.cambiatus.io; + + #add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Headers' 'Authorization, Origin, Accept, Community-Domain, X-Custom-Header, Upgrade-Insecure-Requests, X-Requested-With,User-Agent,Cache-Control,Content-Type'; + #add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, DELETE, PUT, HEAD'; + #add_header 'Access-Control-Allow-Credentials' 'true'; + #add_header Referrer-Policy "no-referrer-when-downgrade" always; + #add_header 'Access-Control-Allow-Headers' '*'; + #add_header X-Frame-Options "ALLOW-FROM https://*.staging.cambiatus.io"; + #add_header X-Frame-Options "ALLOW-FROM https://staging.cambiatus.io"; + #add_header X-Frame-Options "ALLOW-FROM http://staging.cambiatus.io"; + #add_header X-Frame-Options "ALLOW-FROM http://localhost"; + #add_header X-Frame-Options "SAMEORIGIN"; + #add_header Content-Security-Policy "frame-ancestors https://*.staging.cambiatus.io http://staging.cambiatus.io http://localhost;"; + #add_header Content-Security-Policy "frame-ancestors https://*.staging.cambiatus.io http://staging.cambiatus.io;"; + + location / { + try_files $uri $uri/ /index.html; + } + + error_page 404 500 502 503 504 /index.html; + + location /api/ { + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + #proxy_set_header Upgrade $http_upgrade; + #proxy_set_header X-Forwarded-For $remote_addr; + #proxy_redirect off; + #proxy_http_version 1.1; + #proxy_set_header Connection "upgrade"; + proxy_set_header Origin *; + proxy_pass http://127.0.0.1:8025; + client_max_body_size 10M; + } + + location /socket/ { + proxy_pass http://127.0.0.1:8025/socket/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header Origin ''; + proxy_redirect off; + } + + location /v1/ { + proxy_pass http://127.0.0.1:18888/v1/; + proxy_set_header HOST $host; + proxy_set_header X-Real-IP $remote_addr; + } + + location /globalstorage/ { + try_files $uri $uri/ /index.html; + } + + location = /netdata { + return 301 /netdata/; + } + + location ~ /netdata/(?.*) { + auth_basic "Protected"; + auth_basic_user_file passwords; + + proxy_redirect off; + proxy_set_header Host $host; + + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Server $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_pass http://netdataback/$ndpath$is_args$args; + proxy_http_version 1.1; + proxy_pass_request_headers on; + proxy_set_header Connection "keep-alive"; + proxy_store off; + gzip on; + gzip_proxied any; + gzip_types *; + } + + listen [::]:443 ssl ipv6only=on; # managed by Certbot + listen 443 ssl; # managed by Certbot + ssl_certificate /etc/letsencrypt/live/staging.cambiatus.io/fullchain.pem; # managed by Certbot + ssl_certificate_key /etc/letsencrypt/live/staging.cambiatus.io/privkey.pem; # managed by Certbot + include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot + ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot + } + + server { + listen 80; + listen [::]:80; + + server_name staging.cambiatus.io *.staging.cambiatus.io; + + return 301 https://$host$request_uri; + return 404; # managed by Certbot + } +} \ No newline at end of file From 65cd412c27e17758a78af2fa163825e8b617fd65 Mon Sep 17 00:00:00 2001 From: Matheus Buss Date: Tue, 17 May 2022 09:59:27 -0300 Subject: [PATCH 08/21] Added proxy_pass to /api/rich_link --- nginx/nginx.conf | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 0d068f5c..d709f634 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -31,6 +31,12 @@ http { keepalive_timeout 65; #gzip on; + + map $http_user_agent $rich_link_prefix { + default 0; + ~*(facebookexternalhit|twitterbot|telegrambot|linkedinbot|slackbot) /api/rich_link; + } + upstream netdataback { server unix:/var/run/netdata/netdata.sock; keepalive 64; @@ -121,6 +127,13 @@ http { #add_header Content-Security-Policy "frame-ancestors https://*.staging.cambiatus.io http://staging.cambiatus.io;"; location / { + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + + if ($rich_link_prefix != 0) { + proxy_pass http://127.0.0.1:4000$rich_link_prefix$request_uri; + } + try_files $uri $uri/ /index.html; } From 3f24d53dfb65cbcc4531c6f14c9e14f8f3db298b Mon Sep 17 00:00:00 2001 From: Matheus Buss Date: Tue, 17 May 2022 11:45:46 -0300 Subject: [PATCH 09/21] Updated url field for users and products --- .../controllers/rich_link_controller.ex | 28 ++++++++++--------- .../controllers/rich_link_controller_test.exs | 23 ++++++++++++--- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/lib/cambiatus_web/controllers/rich_link_controller.ex b/lib/cambiatus_web/controllers/rich_link_controller.ex index 70f69d4e..484afbc7 100644 --- a/lib/cambiatus_web/controllers/rich_link_controller.ex +++ b/lib/cambiatus_web/controllers/rich_link_controller.ex @@ -12,18 +12,20 @@ defmodule CambiatusWeb.RichLinkController do def rich_link(conn, params) do data = - case Map.get(params, "page") do - ["shop", id] -> - product_rich_link(id) + with community_subdomain <- conn.host do + case Map.get(params, "page") do + ["shop", id] -> + product_rich_link(id, community_subdomain) - ["profile", account] -> - user_rich_link(account) + ["profile", account] -> + user_rich_link(account, community_subdomain) - [] -> - community_rich_link(conn.host) + [] -> + community_rich_link(community_subdomain) - _ -> - send_resp(conn, 404, "Category not found") + _ -> + send_resp(conn, 404, "Category not found") + end end case data do @@ -35,7 +37,7 @@ defmodule CambiatusWeb.RichLinkController do end end - def product_rich_link(id) do + def product_rich_link(id, community_subdomain) do case Shop.get_product(nil, %{id: id}, nil) do {:ok, product} -> product = Repo.preload(product, :images) @@ -45,7 +47,7 @@ defmodule CambiatusWeb.RichLinkController do %{ description: product.description, title: product.title, - url: nil, + url: community_subdomain, image: image.uri, locale: nil }} @@ -55,14 +57,14 @@ defmodule CambiatusWeb.RichLinkController do end end - def user_rich_link(account) do + def user_rich_link(account, community_subdomain) do case Accounts.get_user(nil, %{account: account}, nil) do {:ok, user} -> {:ok, %{ description: user.bio, title: user.name, - url: user.email, + url: community_subdomain, image: user.avatar, locale: user.location }} diff --git a/test/cambiatus_web/controllers/rich_link_controller_test.exs b/test/cambiatus_web/controllers/rich_link_controller_test.exs index 07028daa..8f892af7 100644 --- a/test/cambiatus_web/controllers/rich_link_controller_test.exs +++ b/test/cambiatus_web/controllers/rich_link_controller_test.exs @@ -45,16 +45,24 @@ defmodule CambiatusWeb.RichLinkControllerTest do user = insert(:user) + community = + insert(:community) + |> Repo.preload(:subdomain) + expected_data = %{ description: md_to_txt(user.bio), title: user.name, - url: user.email, + url: community.subdomain.name, image: user.avatar, locale: user.location } # Submit GET request for a user rich link - conn = get(conn, "/api/rich_link/profile/#{user.account}") + + conn = + %{conn | host: community.subdomain.name} + |> get("/api/rich_link/profile/#{user.account}") + response = html_response(conn, 200) # Check http code 200 and if all the rich link fields are properly filled @@ -75,16 +83,23 @@ defmodule CambiatusWeb.RichLinkControllerTest do [image | _] = product.images + community = + insert(:community) + |> Repo.preload(:subdomain) + expected_data = %{ description: md_to_txt(product.description), title: product.title, - url: nil, + url: community.subdomain.name, image: image.uri, locale: nil } # Submit GET request for a product rich link - conn = get(conn, "/api/rich_link/shop/#{product.id}") + conn = + %{conn | host: community.subdomain.name} + |> get("/api/rich_link/shop/#{product.id}") + response = html_response(conn, 200) # Check http code 200 and if all the rich link fields are properly filled From 789940226f8ccddd1c3a96c73027adac54b27948 Mon Sep 17 00:00:00 2001 From: Matheus Buss Date: Tue, 24 May 2022 11:03:18 -0300 Subject: [PATCH 10/21] Updated NGINX documentation --- README.md | 34 ++++++-- nginx/nginx.conf | 217 ----------------------------------------------- 2 files changed, 27 insertions(+), 224 deletions(-) delete mode 100644 nginx/nginx.conf diff --git a/README.md b/README.md index c901264c..08528a8c 100755 --- a/README.md +++ b/README.md @@ -126,23 +126,43 @@ Now you can visit [`localhost:4000`](http://localhost:4000) from your browser. ## NGINX setup -To setup NGINX on your machine (as localhost) follow these steps! +We use NGINX to manage our server infrastructure. You can check out how to install and run it on their [official site](https://nginx.org/) + +We also use NGINX to redirect social media crawlers in order to dynamically serve rich links (or Open Graphs) in accordance to the [Open Graph Protocol](https://ogp.me/). To set this up on your NGINX follow these steps: + +**Step 0** + +Locate your NGINX configuration file (`nginx.conf`) and get ready to edit it **Step 1** -Replace the original configuration file (`nginx.conf`) with the one [inside this repo](/nginx/nginx.conf) +Add the following lines right before any of the server blocks are declared: -- Note 1: To run on your local machine you'll need to update all `root` directives to reflect where the files are located on your machine (such as on line 104) +``` +map $http_user_agent $rich_link_prefix { + default 0; + ~*(facebookexternalhit|twitterbot|telegrambot|linkedinbot|slackbot) /api/rich_link; +} +``` -- Note 2: For Windows users it is recommended to install NGINX under the C:\Program Files directory +This code is responsible for detecting a crawler from different social media websites based on the user agent issued on the http request. + +If a crawler is detected it saves the user agent to the `$rich_link_prefix` variable. **Step 2** -Open a terminal and `cd` into NGINX's installation directory and run +Inside the server block referring to `server_name block staging.cambiatus.io *.staging.cambiatus.io;` under `location /` insert: + ``` -nginx +proxy_set_header Host $http_host; +proxy_set_header X-Real-IP $remote_addr; +if ($rich_link_prefix != 0) { + proxy_pass http://127.0.0.1:4000$rich_link_prefix$request_uri; +} ``` -Now you can make HTTP requests to NGINX on your browser under localhost! + +This code redirects the identified crawler to the correct rich link URL. Nut if a crawler was not detected the server runs normally. + ## Contributing When you are ready to make your first contribution please check out our [contribution guide](/.github/contributing.md), this will get your up to speed on where and how to start. diff --git a/nginx/nginx.conf b/nginx/nginx.conf deleted file mode 100644 index d709f634..00000000 --- a/nginx/nginx.conf +++ /dev/null @@ -1,217 +0,0 @@ - -#user nobody; -worker_processes 1; - -#error_log logs/error.log; -#error_log logs/error.log notice; -#error_log logs/error.log info; - -#pid logs/nginx.pid; - - -events { - worker_connections 1024; -} - - -http { - include mime.types; - default_type application/octet-stream; - - #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - # '$status $body_bytes_sent "$http_referer" ' - # '"$http_user_agent" "$http_x_forwarded_for"'; - - #access_log logs/access.log main; - - sendfile on; - #tcp_nopush on; - - #keepalive_timeout 0; - keepalive_timeout 65; - - #gzip on; - - map $http_user_agent $rich_link_prefix { - default 0; - ~*(facebookexternalhit|twitterbot|telegrambot|linkedinbot|slackbot) /api/rich_link; - } - - upstream netdataback { - server unix:/var/run/netdata/netdata.sock; - keepalive 64; - } - - server { - server_name dev-eosio.cambiatus.io; - location / { - proxy_pass http://127.0.0.1:58888/; - } - - listen 443 ssl; # managed by Certbot - ssl_certificate /etc/letsencrypt/live/dev-eosio.cambiatus.io/fullchain.pem; # managed by Certbot - ssl_certificate_key /etc/letsencrypt/live/dev-eosio.cambiatus.io/privkey.pem; # managed by Certbot - include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot - ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot - } - - server { - if ($host = dev-eosio.cambiatus.io) { - return 301 https://$host$request_uri; - } # managed by Certbot - - - listen 80; - server_name dev-eosio.cambiatus.io; - return 404; # managed by Certbot - - - } - - server { - listen 80; - server_name natus.cambiatus.io www.natus.cambiatus.io; - return 301 https://natus.cambiatus.io$request_uri; - } - - server { - listen 443 ssl http2; - server_name natus.cambiatus.io www.natus.cambiatus.io; - - root /home/ubuntu/apps/natus.webapp; - index index.html; - - location / { - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header Host $http_host; - proxy_redirect off; - proxy_pass http://127.0.0.1:8033; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - - # asset delivery using NGINX - location ~* ^.+\.(css|cur|gif|gz|ico|jpg|jpeg|js|png|svg|woff|woff2)$ { - root /home/ubuntu/apps/natus.webapp/priv/static; - etag off; - expires max; - add_header Cache-Control public; - } - } - - ssl_certificate /etc/letsencrypt/live/natus.cambiatus.io/fullchain.pem; # managed by Certbot - ssl_certificate_key /etc/letsencrypt/live/natus.cambiatus.io/privkey.pem; # managed by Certbot - include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot - ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot - } - - - server { - root /home/ubuntu/apps/frontend/build; - index index.html; - - server_name staging.cambiatus.io *.staging.cambiatus.io; - - #add_header 'Access-Control-Allow-Origin' '*'; - add_header 'Access-Control-Allow-Headers' 'Authorization, Origin, Accept, Community-Domain, X-Custom-Header, Upgrade-Insecure-Requests, X-Requested-With,User-Agent,Cache-Control,Content-Type'; - #add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, DELETE, PUT, HEAD'; - #add_header 'Access-Control-Allow-Credentials' 'true'; - #add_header Referrer-Policy "no-referrer-when-downgrade" always; - #add_header 'Access-Control-Allow-Headers' '*'; - #add_header X-Frame-Options "ALLOW-FROM https://*.staging.cambiatus.io"; - #add_header X-Frame-Options "ALLOW-FROM https://staging.cambiatus.io"; - #add_header X-Frame-Options "ALLOW-FROM http://staging.cambiatus.io"; - #add_header X-Frame-Options "ALLOW-FROM http://localhost"; - #add_header X-Frame-Options "SAMEORIGIN"; - #add_header Content-Security-Policy "frame-ancestors https://*.staging.cambiatus.io http://staging.cambiatus.io http://localhost;"; - #add_header Content-Security-Policy "frame-ancestors https://*.staging.cambiatus.io http://staging.cambiatus.io;"; - - location / { - proxy_set_header Host $http_host; - proxy_set_header X-Real-IP $remote_addr; - - if ($rich_link_prefix != 0) { - proxy_pass http://127.0.0.1:4000$rich_link_prefix$request_uri; - } - - try_files $uri $uri/ /index.html; - } - - error_page 404 500 502 503 504 /index.html; - - location /api/ { - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - #proxy_set_header Upgrade $http_upgrade; - #proxy_set_header X-Forwarded-For $remote_addr; - #proxy_redirect off; - #proxy_http_version 1.1; - #proxy_set_header Connection "upgrade"; - proxy_set_header Origin *; - proxy_pass http://127.0.0.1:8025; - client_max_body_size 10M; - } - - location /socket/ { - proxy_pass http://127.0.0.1:8025/socket/; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header Host $host; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header Origin ''; - proxy_redirect off; - } - - location /v1/ { - proxy_pass http://127.0.0.1:18888/v1/; - proxy_set_header HOST $host; - proxy_set_header X-Real-IP $remote_addr; - } - - location /globalstorage/ { - try_files $uri $uri/ /index.html; - } - - location = /netdata { - return 301 /netdata/; - } - - location ~ /netdata/(?.*) { - auth_basic "Protected"; - auth_basic_user_file passwords; - - proxy_redirect off; - proxy_set_header Host $host; - - proxy_set_header X-Forwarded-Host $host; - proxy_set_header X-Forwarded-Server $host; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_pass http://netdataback/$ndpath$is_args$args; - proxy_http_version 1.1; - proxy_pass_request_headers on; - proxy_set_header Connection "keep-alive"; - proxy_store off; - gzip on; - gzip_proxied any; - gzip_types *; - } - - listen [::]:443 ssl ipv6only=on; # managed by Certbot - listen 443 ssl; # managed by Certbot - ssl_certificate /etc/letsencrypt/live/staging.cambiatus.io/fullchain.pem; # managed by Certbot - ssl_certificate_key /etc/letsencrypt/live/staging.cambiatus.io/privkey.pem; # managed by Certbot - include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot - ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot - } - - server { - listen 80; - listen [::]:80; - - server_name staging.cambiatus.io *.staging.cambiatus.io; - - return 301 https://$host$request_uri; - return 404; # managed by Certbot - } -} \ No newline at end of file From ec177544f16407cd7fa6be7ac8e126e8ab5adb54 Mon Sep 17 00:00:00 2001 From: Matheus Buss Date: Tue, 24 May 2022 11:04:05 -0300 Subject: [PATCH 11/21] Made requested changes to code --- lib/cambiatus_web/views/rich_link_view.ex | 3 ++- test/cambiatus_web/controllers/rich_link_controller_test.exs | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/cambiatus_web/views/rich_link_view.ex b/lib/cambiatus_web/views/rich_link_view.ex index 351a5117..e4667a4a 100644 --- a/lib/cambiatus_web/views/rich_link_view.ex +++ b/lib/cambiatus_web/views/rich_link_view.ex @@ -6,7 +6,8 @@ defmodule CambiatusWeb.RichLinkView do def md_to_txt(markdown) do with {:ok, string, _} <- Earmark.as_html(markdown) do - HtmlSanitizeEx.strip_tags(string) + string + |> HtmlSanitizeEx.strip_tags() |> String.trim() else {:error, _} -> diff --git a/test/cambiatus_web/controllers/rich_link_controller_test.exs b/test/cambiatus_web/controllers/rich_link_controller_test.exs index 8f892af7..c6337238 100644 --- a/test/cambiatus_web/controllers/rich_link_controller_test.exs +++ b/test/cambiatus_web/controllers/rich_link_controller_test.exs @@ -65,9 +65,7 @@ defmodule CambiatusWeb.RichLinkControllerTest do response = html_response(conn, 200) - # Check http code 200 and if all the rich link fields are properly filled - assert conn.status == 200 - + # Check if all the rich link fields are properly filled Enum.each(expected_data, fn {k, v} -> assert String.match?(response, ~r/meta property=\"og:#{k}\" content=\"#{v}/) end) From 438adf8bf761ad88a48f2a18c7936ba5a701b9ca Mon Sep 17 00:00:00 2001 From: Matheus Buss Date: Tue, 24 May 2022 16:18:21 -0300 Subject: [PATCH 12/21] Fixed title appearing in quotes --- lib/cambiatus_web/templates/rich_link/rich_link.html.eex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cambiatus_web/templates/rich_link/rich_link.html.eex b/lib/cambiatus_web/templates/rich_link/rich_link.html.eex index 9fd9b2dc..6582f4f1 100644 --- a/lib/cambiatus_web/templates/rich_link/rich_link.html.eex +++ b/lib/cambiatus_web/templates/rich_link/rich_link.html.eex @@ -14,5 +14,5 @@ - "<%= @data.title %>" + <%= @data.title %> From 1933e48445fe29122f5d56d6c8ab16c648867d08 Mon Sep 17 00:00:00 2001 From: Matheus Buss Date: Thu, 26 May 2022 00:29:30 -0300 Subject: [PATCH 13/21] Fixed underline showing as tag --- lib/cambiatus_web/views/rich_link_view.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cambiatus_web/views/rich_link_view.ex b/lib/cambiatus_web/views/rich_link_view.ex index e4667a4a..17c90fe2 100644 --- a/lib/cambiatus_web/views/rich_link_view.ex +++ b/lib/cambiatus_web/views/rich_link_view.ex @@ -5,7 +5,7 @@ defmodule CambiatusWeb.RichLinkView do require HtmlSanitizeEx def md_to_txt(markdown) do - with {:ok, string, _} <- Earmark.as_html(markdown) do + with {:ok, string, _} <- Earmark.as_html(markdown, escape: false) do string |> HtmlSanitizeEx.strip_tags() |> String.trim() From d7d99ada909fcf0e088897b7a976b9ffb678bb2c Mon Sep 17 00:00:00 2001 From: Matheus Buss Date: Thu, 26 May 2022 00:33:06 -0300 Subject: [PATCH 14/21] Removed unecessary lines on rich_link template --- lib/cambiatus_web/templates/rich_link/rich_link.html.eex | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/cambiatus_web/templates/rich_link/rich_link.html.eex b/lib/cambiatus_web/templates/rich_link/rich_link.html.eex index 6582f4f1..e25fbbf4 100644 --- a/lib/cambiatus_web/templates/rich_link/rich_link.html.eex +++ b/lib/cambiatus_web/templates/rich_link/rich_link.html.eex @@ -1,8 +1,6 @@ - - From f99fbe3e7c670a2621fb922a7e1d432480ab5b6a Mon Sep 17 00:00:00 2001 From: Matheus Buss Date: Thu, 26 May 2022 09:54:15 -0300 Subject: [PATCH 15/21] Added default image to products --- .../controllers/rich_link_controller.ex | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/cambiatus_web/controllers/rich_link_controller.ex b/lib/cambiatus_web/controllers/rich_link_controller.ex index 484afbc7..84732079 100644 --- a/lib/cambiatus_web/controllers/rich_link_controller.ex +++ b/lib/cambiatus_web/controllers/rich_link_controller.ex @@ -38,17 +38,24 @@ defmodule CambiatusWeb.RichLinkController do end def product_rich_link(id, community_subdomain) do + get_image = fn product -> + with product = Repo.preload(product, :images), + [image | _] <- product.images do + image.uri + else + _ -> + "https://buss.staging.cambiatus.io/images/logo-cambiatus-mobile.svg" + end + end + case Shop.get_product(nil, %{id: id}, nil) do {:ok, product} -> - product = Repo.preload(product, :images) - [image | _] = product.images - {:ok, %{ description: product.description, title: product.title, url: community_subdomain, - image: image.uri, + image: get_image.(product), locale: nil }} From bd5329a491d83299727c93c48852f4ad30c0e39f Mon Sep 17 00:00:00 2001 From: Matheus Buss Date: Thu, 26 May 2022 10:48:41 -0300 Subject: [PATCH 16/21] Updated rich_link_controller_test --- .../controllers/rich_link_controller_test.exs | 47 ++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/test/cambiatus_web/controllers/rich_link_controller_test.exs b/test/cambiatus_web/controllers/rich_link_controller_test.exs index c6337238..bd4c1805 100644 --- a/test/cambiatus_web/controllers/rich_link_controller_test.exs +++ b/test/cambiatus_web/controllers/rich_link_controller_test.exs @@ -31,9 +31,7 @@ defmodule CambiatusWeb.RichLinkControllerTest do response = html_response(conn, 200) - # Check http code 200 and if all the rich link fields are properly filled - assert conn.status == 200 - + # Check if all the rich link fields are properly filled Enum.each(expected_data, fn {k, v} -> assert String.match?(response, ~r/meta property=\"og:#{k}\" content=\"#{v}/) end) @@ -58,7 +56,6 @@ defmodule CambiatusWeb.RichLinkControllerTest do } # Submit GET request for a user rich link - conn = %{conn | host: community.subdomain.name} |> get("/api/rich_link/profile/#{user.account}") @@ -71,10 +68,9 @@ defmodule CambiatusWeb.RichLinkControllerTest do end) end - test "generate rich link for product", + test "generate rich link for product with image", %{conn: conn} do # Insert product and extract data for the rich link - product = insert(:product) |> Repo.preload(:images) @@ -100,19 +96,48 @@ defmodule CambiatusWeb.RichLinkControllerTest do response = html_response(conn, 200) - # Check http code 200 and if all the rich link fields are properly filled - assert conn.status == 200 - + # Check if all the rich link fields are properly filled Enum.each(expected_data, fn {k, v} -> assert String.match?(response, ~r/meta property=\"og:#{k}\" content=\"#{v}/) end) end end + test "generate rich link for product without image", + %{conn: conn} do + # Insert product without images and extract data for the rich link + product = insert(:product, images: []) + + community = + insert(:community) + |> Repo.preload(:subdomain) + + expected_data = %{ + description: md_to_txt(product.description), + title: product.title, + url: community.subdomain.name, + image: "https://buss.staging.cambiatus.io/images/logo-cambiatus-mobile.svg", + locale: nil + } + + # Submit GET request for a product rich link + conn = + %{conn | host: community.subdomain.name} + |> get("/api/rich_link/shop/#{product.id}") + + response = html_response(conn, 200) + + # Check if all the rich link fields are properly filled + Enum.each(expected_data, fn {k, v} -> + assert String.match?(response, ~r/meta property=\"og:#{k}\" content=\"#{v}/) + end) + end + defp md_to_txt(markdown) do # Convert markdown to plain text - with {:ok, string, _} <- Earmark.as_html(markdown) do - HtmlSanitizeEx.strip_tags(string) + with {:ok, string, _} <- Earmark.as_html(markdown, escape: false) do + string + |> HtmlSanitizeEx.strip_tags() |> String.trim() else {:error, _} -> From 683d35c063da625fbd019fc8850b20b3224eefe6 Mon Sep 17 00:00:00 2001 From: Matheus Buss Date: Fri, 27 May 2022 16:10:55 -0300 Subject: [PATCH 17/21] Added whatsapp to user agents list. Updated instructions --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 08528a8c..5aeaa913 100755 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ Add the following lines right before any of the server blocks are declared: ``` map $http_user_agent $rich_link_prefix { default 0; - ~*(facebookexternalhit|twitterbot|telegrambot|linkedinbot|slackbot) /api/rich_link; + ~*(facebookexternalhit|twitterbot|telegrambot|linkedinbot|slackbot|whatsapp) /api/rich_link; } ``` @@ -157,10 +157,12 @@ Inside the server block referring to `server_name block staging.cambiatus.io *.s proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; if ($rich_link_prefix != 0) { - proxy_pass http://127.0.0.1:4000$rich_link_prefix$request_uri; + proxy_pass http://127.0.0.1:#{backend_listening_port}$rich_link_prefix$request_uri; } ``` +Note: Replace `#{backend_listening_port}` with the port to which the backend server is setup to listen. + This code redirects the identified crawler to the correct rich link URL. Nut if a crawler was not detected the server runs normally. ## Contributing From 228c491a9cc2cc6f546ce320a931bd0000177905 Mon Sep 17 00:00:00 2001 From: Matheus Buss Date: Mon, 30 May 2022 17:04:43 -0300 Subject: [PATCH 18/21] Implemented community rich link as a fallback --- lib/cambiatus_web/controllers/rich_link_controller.ex | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/cambiatus_web/controllers/rich_link_controller.ex b/lib/cambiatus_web/controllers/rich_link_controller.ex index 84732079..bf549319 100644 --- a/lib/cambiatus_web/controllers/rich_link_controller.ex +++ b/lib/cambiatus_web/controllers/rich_link_controller.ex @@ -20,11 +20,8 @@ defmodule CambiatusWeb.RichLinkController do ["profile", account] -> user_rich_link(account, community_subdomain) - [] -> - community_rich_link(community_subdomain) - _ -> - send_resp(conn, 404, "Category not found") + community_rich_link(community_subdomain) end end From 505eebbce7680877e2673b07040f4958d9acd90b Mon Sep 17 00:00:00 2001 From: Matheus Buss Date: Tue, 31 May 2022 08:50:55 -0300 Subject: [PATCH 19/21] Updated canonical URL --- lib/cambiatus_web/controllers/rich_link_controller.ex | 4 ++-- .../cambiatus_web/controllers/rich_link_controller_test.exs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/cambiatus_web/controllers/rich_link_controller.ex b/lib/cambiatus_web/controllers/rich_link_controller.ex index bf549319..d3a7a7c7 100644 --- a/lib/cambiatus_web/controllers/rich_link_controller.ex +++ b/lib/cambiatus_web/controllers/rich_link_controller.ex @@ -51,7 +51,7 @@ defmodule CambiatusWeb.RichLinkController do %{ description: product.description, title: product.title, - url: community_subdomain, + url: community_subdomain <> "/shop/#{product.id}", image: get_image.(product), locale: nil }} @@ -68,7 +68,7 @@ defmodule CambiatusWeb.RichLinkController do %{ description: user.bio, title: user.name, - url: community_subdomain, + url: community_subdomain <> "/profile/#{user.account}", image: user.avatar, locale: user.location }} diff --git a/test/cambiatus_web/controllers/rich_link_controller_test.exs b/test/cambiatus_web/controllers/rich_link_controller_test.exs index bd4c1805..27c57b1e 100644 --- a/test/cambiatus_web/controllers/rich_link_controller_test.exs +++ b/test/cambiatus_web/controllers/rich_link_controller_test.exs @@ -50,7 +50,7 @@ defmodule CambiatusWeb.RichLinkControllerTest do expected_data = %{ description: md_to_txt(user.bio), title: user.name, - url: community.subdomain.name, + url: community.subdomain.name <> "/profile/#{user.account}", image: user.avatar, locale: user.location } @@ -84,7 +84,7 @@ defmodule CambiatusWeb.RichLinkControllerTest do expected_data = %{ description: md_to_txt(product.description), title: product.title, - url: community.subdomain.name, + url: community.subdomain.name <> "/shop/#{product.id}", image: image.uri, locale: nil } @@ -115,7 +115,7 @@ defmodule CambiatusWeb.RichLinkControllerTest do expected_data = %{ description: md_to_txt(product.description), title: product.title, - url: community.subdomain.name, + url: community.subdomain.name <> "/shop/#{product.id}", image: "https://buss.staging.cambiatus.io/images/logo-cambiatus-mobile.svg", locale: nil } From b45d456d1c261da4c0c13a8b49c666c8f5b6b5ee Mon Sep 17 00:00:00 2001 From: Matheus Buss Date: Tue, 31 May 2022 09:06:09 -0300 Subject: [PATCH 20/21] Accounted for null user names --- .../controllers/rich_link_controller.ex | 2 +- .../controllers/rich_link_controller_test.exs | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/cambiatus_web/controllers/rich_link_controller.ex b/lib/cambiatus_web/controllers/rich_link_controller.ex index d3a7a7c7..71c42776 100644 --- a/lib/cambiatus_web/controllers/rich_link_controller.ex +++ b/lib/cambiatus_web/controllers/rich_link_controller.ex @@ -67,7 +67,7 @@ defmodule CambiatusWeb.RichLinkController do {:ok, %{ description: user.bio, - title: user.name, + title: if(user.name, do: user.name, else: user.account), url: community_subdomain <> "/profile/#{user.account}", image: user.avatar, locale: user.location diff --git a/test/cambiatus_web/controllers/rich_link_controller_test.exs b/test/cambiatus_web/controllers/rich_link_controller_test.exs index 27c57b1e..4abff7e8 100644 --- a/test/cambiatus_web/controllers/rich_link_controller_test.exs +++ b/test/cambiatus_web/controllers/rich_link_controller_test.exs @@ -68,6 +68,37 @@ defmodule CambiatusWeb.RichLinkControllerTest do end) end + test "generate rich link for user without name", + %{conn: conn} do + # Insert user and extract data for the rich link + + user = insert(:user, name: nil) + + community = + insert(:community) + |> Repo.preload(:subdomain) + + expected_data = %{ + description: md_to_txt(user.bio), + title: user.account, + url: community.subdomain.name <> "/profile/#{user.account}", + image: user.avatar, + locale: user.location + } + + # Submit GET request for a user rich link + conn = + %{conn | host: community.subdomain.name} + |> get("/api/rich_link/profile/#{user.account}") + + response = html_response(conn, 200) + + # Check if all the rich link fields are properly filled + Enum.each(expected_data, fn {k, v} -> + assert String.match?(response, ~r/meta property=\"og:#{k}\" content=\"#{v}/) + end) + end + test "generate rich link for product with image", %{conn: conn} do # Insert product and extract data for the rich link From 8e13c49301933e3e2ec4f0442c23565329810fa9 Mon Sep 17 00:00:00 2001 From: Matheus Buss Date: Tue, 31 May 2022 11:47:22 -0300 Subject: [PATCH 21/21] Updated default image for products --- lib/cambiatus_web/controllers/rich_link_controller.ex | 2 +- test/cambiatus_web/controllers/rich_link_controller_test.exs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/cambiatus_web/controllers/rich_link_controller.ex b/lib/cambiatus_web/controllers/rich_link_controller.ex index 71c42776..f4b0e5e1 100644 --- a/lib/cambiatus_web/controllers/rich_link_controller.ex +++ b/lib/cambiatus_web/controllers/rich_link_controller.ex @@ -41,7 +41,7 @@ defmodule CambiatusWeb.RichLinkController do image.uri else _ -> - "https://buss.staging.cambiatus.io/images/logo-cambiatus-mobile.svg" + "https://cambiatus-uploads.s3.amazonaws.com/cambiatus-uploads/b214c106482a46ad89f3272761d3f5b5" end end diff --git a/test/cambiatus_web/controllers/rich_link_controller_test.exs b/test/cambiatus_web/controllers/rich_link_controller_test.exs index 4abff7e8..c34a49e1 100644 --- a/test/cambiatus_web/controllers/rich_link_controller_test.exs +++ b/test/cambiatus_web/controllers/rich_link_controller_test.exs @@ -147,7 +147,8 @@ defmodule CambiatusWeb.RichLinkControllerTest do description: md_to_txt(product.description), title: product.title, url: community.subdomain.name <> "/shop/#{product.id}", - image: "https://buss.staging.cambiatus.io/images/logo-cambiatus-mobile.svg", + image: + "https://cambiatus-uploads.s3.amazonaws.com/cambiatus-uploads/b214c106482a46ad89f3272761d3f5b5", locale: nil }