Hash :
f4b0129b
Author :
Thomas de Grivel
Date :
2022-02-19T17:55:22
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
defmodule KmxgitWeb.SlugController do
use KmxgitWeb, :controller
alias Kmxgit.OrganisationManager.Organisation
alias Kmxgit.RepositoryManager
alias Kmxgit.RepositoryManager.Repository
alias Kmxgit.SlugManager
alias Kmxgit.UserManager.User
alias KmxgitWeb.ErrorView
alias KmxgitWeb.OrganisationView
alias KmxgitWeb.UserView
def show(conn, params) do
current_user = conn.assigns.current_user
slug = SlugManager.get_slug(params["slug"])
if !slug do
not_found(conn)
else
user = slug.user
if user do
owned_repos = User.owned_repositories(user)
contributor_repos = RepositoryManager.list_contributor_repositories(user)
repos = owned_repos ++ contributor_repos
|> Enum.filter(fn repo ->
repo.public_access || Repository.member?(repo, current_user)
end)
conn
|> assign(:disk_usage, User.disk_usage(user))
|> assign(:disk_usage_all, Repository.disk_usage(repos))
|> assign(:repos, repos)
|> assign(:page_title, gettext("User %{login}", login: User.login(user)))
|> assign(:user, user)
|> put_view(UserView)
|> render("show.html")
else
org = slug.organisation
if org do
conn
|> assign(:current_organisation, org)
|> assign(:disk_usage, Organisation.disk_usage(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
end