Skip to content

Commit

Permalink
Fix some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
loicknuchel committed Aug 14, 2023
1 parent 56be1c1 commit bcb582e
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 66 deletions.
2 changes: 1 addition & 1 deletion backend/lib/azimutt/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ defmodule Azimutt.Accounts do
if Azimutt.config(:global_organization) && Azimutt.config(:global_organization_alone) do
user.organizations |> Enum.filter(fn orga -> orga.id == Azimutt.config(:global_organization) end)
else
user.organizations
user.organizations |> Enum.filter(fn orga -> orga.deleted_at == nil end)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@ defmodule AzimuttWeb.Api.CleverCloudController do
use AzimuttWeb, :controller
require Logger
alias Azimutt.CleverCloud
alias Azimutt.Utils.Stringx
action_fallback AzimuttWeb.Api.FallbackController

# https://www.clever-cloud.com/doc/extend/add-ons-api/#provisioning
def create(conn, params) do
Logger.info("Api.CleverCloudController.create(#{Stringx.inspect(params)})")

case CleverCloud.create_resource(params) do
{:ok, resource} -> conn |> render("show.json", resource: resource, message: "Your Azimutt add-on is now provisioned.")
{:error, _err} -> conn |> send_resp(:unprocessable_entity, "")
end
end

# https://www.clever-cloud.com/doc/extend/add-ons-api/#plan-change
def update(conn, %{"resource_id" => resource_id, "plan" => plan} = params) do
Logger.info("Api.CleverCloudController.update(#{Stringx.inspect(params)})")
def update(conn, %{"resource_id" => resource_id, "plan" => plan}) do
now = DateTime.utc_now()

case CleverCloud.get_resource(resource_id) do
Expand All @@ -37,8 +33,7 @@ defmodule AzimuttWeb.Api.CleverCloudController do
end

# https://www.clever-cloud.com/doc/extend/add-ons-api/#deprovisioning
def delete(conn, %{"resource_id" => resource_id} = params) do
Logger.info("Api.CleverCloudController.delete(#{Stringx.inspect(params)})")
def delete(conn, %{"resource_id" => resource_id}) do
now = DateTime.utc_now()

case CleverCloud.get_resource(resource_id) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ defmodule AzimuttWeb.CleverCloudController do
action_fallback AzimuttWeb.FallbackController

# helper to ease clever cloud testing in local
def index(conn, params) do
Logger.info("CleverCloudController.index(#{Stringx.inspect(params)})")
def index(conn, _params) do
# defined as env variable (see .env), don't use env vars to make leak impossible
clever_cloud = %{
addon_id: "azimutt-dev",
Expand All @@ -28,7 +27,6 @@ defmodule AzimuttWeb.CleverCloudController do
# https://www.clever-cloud.com/doc/extend/add-ons-api/#sso
# TODO: how to get user_id in SSO? Get it from the resource? What happen if several users from Clever Cloud???
def login(conn, %{"id" => resource_id, "token" => token, "timestamp" => timestamp, "email" => email} = params) do
Logger.info("CleverCloudController.login(#{Stringx.inspect(params)})")
now = DateTime.utc_now()
now_ts = System.os_time(:second)
salt = Azimutt.config(:clever_cloud_sso_salt)
Expand Down Expand Up @@ -91,8 +89,7 @@ defmodule AzimuttWeb.CleverCloudController do
end
end

def show(conn, %{"resource_id" => resource_id} = params) do
Logger.info("CleverCloudController.show(#{Stringx.inspect(params)})")
def show(conn, %{"resource_id" => resource_id}) do
current_user = conn.assigns.current_user
resource = conn.assigns.clever_cloud

Expand Down
7 changes: 1 addition & 6 deletions backend/lib/azimutt_web/controllers/user_auth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ defmodule AzimuttWeb.UserAuth do
alias Azimutt.Heroku
alias Azimutt.Tracking
alias Azimutt.Utils.Result
alias Azimutt.Utils.Stringx
alias AzimuttWeb.Router.Helpers, as: Routes

@seconds 1
Expand All @@ -25,7 +24,7 @@ defmodule AzimuttWeb.UserAuth do

# cf https://www.clever-cloud.com/doc/extend/add-ons-api/#sso
@clever_cloud_cookie "_azimutt_clever_cloud_sso"
@clever_cloud_options [sign: true, max_age: 90 * @minutes, same_site: "Lax"]
@clever_cloud_options [sign: true, max_age: 90 * @minutes, same_site: "None", secure: true]

# cf https://devcenter.heroku.com/articles/add-on-single-sign-on
@heroku_cookie "_azimutt_heroku_sso"
Expand Down Expand Up @@ -211,8 +210,6 @@ defmodule AzimuttWeb.UserAuth do
do: require_basic_auth(conn, "Heroku", Azimutt.config(:heroku_addon_id), Azimutt.config(:heroku_password))

defp require_basic_auth(conn, name, expected_user, expected_pass) do
Logger.info("UserAuth.require_basic_auth(#{Stringx.inspect(%{name: name, user: expected_user, pass: expected_pass})})")

if expected_user && expected_pass do
case Plug.BasicAuth.parse_basic_auth(conn) do
{user, pass} ->
Expand Down Expand Up @@ -269,8 +266,6 @@ defmodule AzimuttWeb.UserAuth do
end

def require_clever_cloud_resource(conn, _opts) do
Logger.info("UserAuth.require_clever_cloud_resource()")

if conn.assigns[:clever_cloud] do
conn
else
Expand Down
9 changes: 7 additions & 2 deletions backend/lib/azimutt_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ defmodule AzimuttWeb.Router do
end

scope "/clevercloud", AzimuttWeb do
pipe_through([:browser, :require_clever_cloud_resource, :require_authed_user])
pipe_through([:browser, :require_clever_cloud_resource, :require_authed_user, AllowCrossOriginIframe])
get("/resources/:resource_id", CleverCloudController, :show)
end

Expand Down Expand Up @@ -306,8 +306,13 @@ defmodule AzimuttWeb.Router do
get("/create", ElmController, :create)
get("/new", ElmController, :new)
get("/:organization_id", ElmController, :orga_show)
get("/:organization_id/create", ElmController, :orga_create)
get("/:organization_id/new", ElmController, :orga_new)
end

# allow cross origin iframe for Clever Cloud
scope "/", AzimuttWeb do
pipe_through([:browser, :enforce_user_requirements, :elm_root_layout, AllowCrossOriginIframe])
get("/:organization_id/create", ElmController, :orga_create)
get("/:organization_id/:project_id", ElmController, :project_show)
end
end
41 changes: 16 additions & 25 deletions backend/lib/azimutt_web/templates/website/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,20 @@
<!-- Hero section -->
<div class="relative">
<div class="my-32">
<div class="flex justify-center mb-8 -mt-20">
<%= if @conn.query_params["ref"] == "producthunt" do %>
<p class="relative rounded-full px-4 py-1.5 text-sm leading-6 text-gray-600 ring-1 ring-inset ring-orange-600">
<span class="hidden md:inline">Hello Product Hunt user! <span class="font-semibold text-orange-600">Happy to see you there</span> 😉</span>
</p>
<% else %>
<p class="relative rounded-full px-4 py-1.5 text-sm leading-6 text-gray-600 ring-2 ring-inset ring-orange-500 hover:shadow hover:shadow-orange-600/50">
<span class="hidden md:inline">🎉 We are live on Product Hunt</span>
<a href="https://www.producthunt.com/posts/azimutt" class="font-semibold text-orange-600"><span class="absolute inset-0" aria-hidden="true"></span>See our launch <span aria-hidden="true">&rarr;</span></a>
</p>
<% end %>
</div>
<div class="px-6 mx-auto max-w-7xl lg:px-8">
<div class="max-w-2xl mx-auto text-center">
<h1 class="text-4xl font-bold tracking-tight text-gray-900 sm:text-6xl">
Boost your <span class="text-indigo-600">database</span> productivity. Right now!
</h1>
<div class="flex justify-center mb-4 space-x-6">
<a href={Azimutt.config(:github_url)} target="_blank" rel="noopener" class="px-3 py-1 text-sm font-semibold leading-6 text-gray-600 transition duration-300 ease-in-out rounded-full bg-gray-50 ring-1 ring-inset ring-gray-200 hover:bg-gray-100 hover:shadow-lg hover:scale-105">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" class="inline -mt-1"><path d="M11.86 1.6c1.9 0 3.67.44 5.3 1.31a9.8 9.8 0 015.24 8.75c0 2.27-.65 4.32-1.96 6.12a9.95 9.95 0 01-5.09 3.73c-.23.05-.4.03-.53-.07a.52.52 0 01-.2-.42v-3.46c0-.89-.22-1.5-.7-1.9 1.03-.1 1.8-.25 2.3-.42.79-.27 1.39-.7 1.81-1.24.48-.71.7-1.7.7-2.94 0-.52-.1-.99-.3-1.36-.14-.27-.4-.61-.8-1.03.1-.28.18-.62.2-1a4.67 4.67 0 00-.3-1.82c-.22-.05-.62.02-1.13.22-.32.15-.72.32-1.18.57l-.55.37a9.73 9.73 0 00-5.27 0l-.55-.37a8.54 8.54 0 00-1.2-.57c-.5-.2-.88-.24-1.13-.17a3.9 3.9 0 00-.3 1.83c0 .4.05.69.17.94-.32.42-.57.79-.73 1.13-.15.35-.22.77-.22 1.31 0 1.24.22 2.2.68 2.9.4.56.97 1 1.75 1.28.5.17 1.26.3 2.26.42-.35.32-.58.79-.68 1.4-.47.23-.92.3-1.38.25a2.02 2.02 0 01-1.68-1.1c-.17-.3-.4-.55-.68-.75l-.62-.3-.3-.05c-.3 0-.48.05-.48.15-.03.1.05.2.2.32l.2.18c.2.1.4.3.58.54.17.2.3.42.42.67l.18.32c.15.42.4.74.8.94a3 3 0 001.2.37c.33.02.69.02 1.06-.05l.45-.05.05 2.52c0 .17-.07.3-.2.42-.12.1-.3.15-.52.07a10.13 10.13 0 01-5.17-3.73 10.34 10.34 0 01-1.96-6.15c0-1.88.45-3.58 1.33-5.11a9.93 9.93 0 013.69-3.64 10.53 10.53 0 015.24-1.33zM5.21 15.51c.05-.05.13-.07.2-.02.08.05.1.1.08.17-.03.07-.1.07-.2.02s-.1-.12-.08-.17zm.45.35c.05-.05.13-.05.2.05.08.07.1.14.06.2-.05.04-.13.04-.2-.06-.1-.07-.1-.14-.06-.2zm.43.52c.05-.03.1-.03.15-.03a.2.2 0 01.1.1c.08.1.08.2 0 .25a.08.08 0 01-.1 0c-.02-.03-.1-.05-.15-.08-.05-.12-.05-.22 0-.24zm.5.59c.03-.03.08-.03.13-.03l.15.08c.05.05.07.1.07.15.03.05 0 .1-.02.12-.08.07-.18.07-.3-.05a.22.22 0 01-.08-.17c0-.08.03-.08.05-.1zm.68.52c.03-.1.1-.15.25-.1.15.05.2.1.2.17-.02.08-.05.13-.1.15-.05.02-.1.02-.17 0-.08-.02-.1-.07-.15-.1-.05-.05-.05-.07-.03-.12zm1.28.17c0-.02-.02-.05-.08-.07a.4.4 0 00-.2-.05c-.15 0-.2.05-.2.17 0 .1.08.15.23.15.17-.03.25-.08.25-.2zm.55-.25c.15 0 .23.05.23.13.02.07-.05.15-.2.2-.05 0-.1 0-.15-.03-.05-.02-.08-.07-.08-.15 0-.07.08-.12.2-.15z" fill="currentColor"></path></svg>
611 stars
</a>
<a href={Azimutt.config(:slack_url)} target="_blank" rel="noopener" class="px-3 py-1 text-sm font-semibold leading-6 text-gray-600 transition duration-300 ease-in-out rounded-full bg-gray-50 ring-1 ring-inset ring-gray-200 hover:bg-gray-100 hover:shadow-lg hover:scale-105">
<div class="flex justify-center mb-8 -mt-24">
<a href="https://www.producthunt.com/posts/azimutt?utm_source=badge-top-post-topic-badge&utm_medium=badge&utm_souce=badge-azimutt" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/top-post-topic-badge.svg?post_id=390699&theme=light&period=weekly&topic_id=267" alt="Azimutt - Easily&#0032;explore&#0032;and&#0032;analyze&#0032;your&#0032;database&#0032;with&#0032;your&#0032;team | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
</div>
<div class="px-6 mx-auto max-w-7xl lg:px-8">
<div class="max-w-2xl mx-auto text-center">
<h1 class="text-4xl font-bold tracking-tight text-gray-900 sm:text-6xl">
Boost your <span class="text-indigo-600">database</span> productivity. Right now!
</h1>
<div class="flex justify-center mb-4 space-x-6">
<a href={Azimutt.config(:github_url)} target="_blank" rel="noopener" class="px-3 py-1 text-sm font-semibold leading-6 text-gray-600 transition duration-300 ease-in-out rounded-full bg-gray-50 ring-1 ring-inset ring-gray-200 hover:bg-gray-100 hover:shadow-lg hover:scale-105">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" class="inline -mt-1"><path d="M11.86 1.6c1.9 0 3.67.44 5.3 1.31a9.8 9.8 0 015.24 8.75c0 2.27-.65 4.32-1.96 6.12a9.95 9.95 0 01-5.09 3.73c-.23.05-.4.03-.53-.07a.52.52 0 01-.2-.42v-3.46c0-.89-.22-1.5-.7-1.9 1.03-.1 1.8-.25 2.3-.42.79-.27 1.39-.7 1.81-1.24.48-.71.7-1.7.7-2.94 0-.52-.1-.99-.3-1.36-.14-.27-.4-.61-.8-1.03.1-.28.18-.62.2-1a4.67 4.67 0 00-.3-1.82c-.22-.05-.62.02-1.13.22-.32.15-.72.32-1.18.57l-.55.37a9.73 9.73 0 00-5.27 0l-.55-.37a8.54 8.54 0 00-1.2-.57c-.5-.2-.88-.24-1.13-.17a3.9 3.9 0 00-.3 1.83c0 .4.05.69.17.94-.32.42-.57.79-.73 1.13-.15.35-.22.77-.22 1.31 0 1.24.22 2.2.68 2.9.4.56.97 1 1.75 1.28.5.17 1.26.3 2.26.42-.35.32-.58.79-.68 1.4-.47.23-.92.3-1.38.25a2.02 2.02 0 01-1.68-1.1c-.17-.3-.4-.55-.68-.75l-.62-.3-.3-.05c-.3 0-.48.05-.48.15-.03.1.05.2.2.32l.2.18c.2.1.4.3.58.54.17.2.3.42.42.67l.18.32c.15.42.4.74.8.94a3 3 0 001.2.37c.33.02.69.02 1.06-.05l.45-.05.05 2.52c0 .17-.07.3-.2.42-.12.1-.3.15-.52.07a10.13 10.13 0 01-5.17-3.73 10.34 10.34 0 01-1.96-6.15c0-1.88.45-3.58 1.33-5.11a9.93 9.93 0 013.69-3.64 10.53 10.53 0 015.24-1.33zM5.21 15.51c.05-.05.13-.07.2-.02.08.05.1.1.08.17-.03.07-.1.07-.2.02s-.1-.12-.08-.17zm.45.35c.05-.05.13-.05.2.05.08.07.1.14.06.2-.05.04-.13.04-.2-.06-.1-.07-.1-.14-.06-.2zm.43.52c.05-.03.1-.03.15-.03a.2.2 0 01.1.1c.08.1.08.2 0 .25a.08.08 0 01-.1 0c-.02-.03-.1-.05-.15-.08-.05-.12-.05-.22 0-.24zm.5.59c.03-.03.08-.03.13-.03l.15.08c.05.05.07.1.07.15.03.05 0 .1-.02.12-.08.07-.18.07-.3-.05a.22.22 0 01-.08-.17c0-.08.03-.08.05-.1zm.68.52c.03-.1.1-.15.25-.1.15.05.2.1.2.17-.02.08-.05.13-.1.15-.05.02-.1.02-.17 0-.08-.02-.1-.07-.15-.1-.05-.05-.05-.07-.03-.12zm1.28.17c0-.02-.02-.05-.08-.07a.4.4 0 00-.2-.05c-.15 0-.2.05-.2.17 0 .1.08.15.23.15.17-.03.25-.08.25-.2zm.55-.25c.15 0 .23.05.23.13.02.07-.05.15-.2.2-.05 0-.1 0-.15-.03-.05-.02-.08-.07-.08-.15 0-.07.08-.12.2-.15z" fill="currentColor"></path></svg>
710 stars
</a>
<a href={Azimutt.config(:slack_url)} target="_blank" rel="noopener" class="px-3 py-1 text-sm font-semibold leading-6 text-gray-600 transition duration-300 ease-in-out rounded-full bg-gray-50 ring-1 ring-inset ring-gray-200 hover:bg-gray-100 hover:shadow-lg hover:scale-105">
<svg xmlns="http://www.w3.org/2000/svg" width="17" height="16" fill="none" class="inline -mt-1"><path fill="#E01E5A" d="M4.441 9.847c0 .809-.661 1.47-1.47 1.47-.81 0-1.471-.661-1.471-1.47 0-.81.661-1.471 1.47-1.471h1.471v1.47zm.739 0c0-.81.66-1.471 1.47-1.471.81 0 1.47.661 1.47 1.47v3.683c0 .81-.66 1.47-1.47 1.47-.81 0-1.47-.66-1.47-1.47V9.847z"></path><path fill="#36C5F0" d="M6.65 3.942c-.81 0-1.47-.662-1.47-1.47C5.18 1.661 5.84 1 6.65 1c.81 0 1.47.662 1.47 1.471v1.47H6.65zm.003.741c.81 0 1.47.66 1.47 1.47 0 .81-.66 1.47-1.47 1.47H2.97c-.81 0-1.471-.66-1.471-1.47 0-.81.661-1.47 1.47-1.47h3.683z"></path><path fill="#2EB67D" d="M12.555 6.153c0-.81.66-1.47 1.47-1.47.81 0 1.47.66 1.47 1.47 0 .81-.66 1.47-1.47 1.47h-1.47v-1.47zm-.739 0c0 .81-.661 1.47-1.47 1.47-.81 0-1.471-.66-1.471-1.47V2.471c0-.81.661-1.47 1.47-1.47.81 0 1.471.66 1.471 1.47v3.682z"></path><path fill="#ECB22E" d="M10.346 12.058c.809 0 1.47.661 1.47 1.47 0 .81-.661 1.471-1.47 1.471-.81 0-1.471-.66-1.471-1.47v-1.47h1.47zm0-.741c-.81 0-1.471-.661-1.471-1.47 0-.81.661-1.471 1.47-1.471h3.683c.81 0 1.47.661 1.47 1.47 0 .81-.66 1.471-1.47 1.471h-3.682z"></path></svg>
Slack community
</a>
Expand Down Expand Up @@ -177,7 +168,7 @@
<a href={"mailto:#{Azimutt.config(:support_email)}"} target="_blank" rel="noopener" class="underline">Email</a>.
</p>
<div class="flex items-center justify-center mt-10 gap-x-6">
<a href={Routes.user_session_path(@conn, :new)} class="rounded-md bg-indigo-600 px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">Join 1000+ early adopters</a>
<a href={Routes.user_session_path(@conn, :new)} class="rounded-md bg-indigo-600 px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">Join 1500+ early adopters</a>
<a href={Routes.gallery_path(@conn, :index)} class="text-sm font-semibold leading-6 text-gray-900">Browse samples <span aria-hidden="true">→</span></a>
</div>
</div>
Expand All @@ -186,4 +177,4 @@
</div>

<%= render "_footer.html", conn: @conn %>
<%= render "_heroku_addon.html" %>
<%= # render "_heroku_addon.html" %>
4 changes: 2 additions & 2 deletions frontend/src/Models/Project/TableId.elm
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ toString ( s, t ) =
fromString : String -> Maybe TableId
fromString id =
case String.split "." id of
s :: t :: [] ->
Just ( s, t )
s :: t :: rest ->
Just ( s, (t :: rest) |> String.join "." )

_ ->
Nothing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ viewNavbar gConf maybeUser eConf virtualRelation erd projects model args =
, Just { action = Left Conf.constants.azimuttFeatureRequests, content = text "Suggest a feature 🚀", hotkeys = [] }
]
|> List.filterMap identity

notCleverCloud : Bool
notCleverCloud =
(erd.project.organization |> Maybe.andThen .cleverCloud) /= Nothing
in
nav [ css [ "az-navbar relative z-max bg-primary-600" ] ]
[ div [ css [ "mx-auto px-2", sm [ "px-4" ], lg [ "px-8" ] ] ]
[ div [ class "relative flex items-center justify-between h-16" ]
[ div [ css [ "flex items-center px-2", lg [ "px-0" ] ] ]
[ viewNavbarBrand (erd.project.organization |> Maybe.map .id |> Maybe.orElse urlOrganization |> Maybe.filter (\id -> userOrganizations |> List.member id)) eConf
[ viewNavbarBrand (erd.project.organization |> Maybe.map .id |> Maybe.orElse urlOrganization |> Maybe.filter (\id -> userOrganizations |> List.member id)) (eConf.dashboardLink && notCleverCloud)
, Lazy.lazy8 viewNavbarSearch erd.settings.defaultSchema model.search erd.tables erd.relations erd.metadata (erd |> Erd.currentLayout |> .tables) (htmlId ++ "-search") (openedDropdown |> String.filterStartsWith (htmlId ++ "-search"))
, viewNavbarHelp
]
Expand All @@ -109,12 +113,12 @@ viewNavbar gConf maybeUser eConf virtualRelation erd projects model args =
]


viewNavbarBrand : Maybe OrganizationId -> ErdConf -> Html msg
viewNavbarBrand organization conf =
viewNavbarBrand : Maybe OrganizationId -> Bool -> Html msg
viewNavbarBrand organization dashboardLink =
let
attrs : List (Attribute msg)
attrs =
if conf.dashboardLink then
if dashboardLink then
[ href (organization |> Backend.organizationUrl) ]

else
Expand Down

0 comments on commit bcb582e

Please sign in to comment.