Hash :
60c50e63
Author :
Thomas de Grivel
Date :
2021-11-19T17:46:49
users repositories
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
defmodule KmxgitWeb.SlugController do
use KmxgitWeb, :controller
alias Kmxgit.OrganisationManager
alias Kmxgit.SlugManager
alias KmxgitWeb.ErrorView
alias KmxgitWeb.OrganisationView
alias KmxgitWeb.UserView
defp not_found(conn) do
conn
|> put_status(:not_found)
|> put_view(ErrorView)
|> render(:"404")
end
def show(conn, params) do
slug = SlugManager.get_slug(params["slug"])
if !slug do
not_found(conn)
else
user = slug.user
if user do
conn
|> assign(:page_title, gettext("User %{login}", login: user.slug.slug))
|> assign(:user, user)
|> put_view(UserView)
|> render("show.html")
else
org = slug.organisation
if org do
conn
|> assign(:current_organisation, org)
|> assign(:org, org)
|> assign(:page_title, org.name || org.slug.slug)
|> put_view(OrganisationView)
|> render("show.html")
else
not_found(conn)
end
end
end
end
def delete(conn, params) do
current_user = conn.assigns.current_user
slug = SlugManager.get_slug(params["slug"])
if slug do
org = slug.organisation
if org && Enum.find(org.users, &(&1.id == current_user.id)) do
{:ok, _} = OrganisationManager.delete_organisation(org)
conn
|> redirect(to: Routes.slug_path(conn, :show, current_user.slug.slug))
else
not_found(conn)
end
else
not_found(conn)
end
end
end