diff --git a/lib/discord.ex b/lib/discord.ex
index 14cdb55..b9e5033 100644
--- a/lib/discord.ex
+++ b/lib/discord.ex
@@ -1,5 +1,7 @@
defmodule Discord do
+ alias Kmxgit.UserManager.User
+
def headers_to_string(headers), do: headers_to_string(headers, [])
def headers_to_string([], acc), do: acc |> Enum.reverse() |> Enum.join("\n")
def headers_to_string([{name, value} | rest], acc) do
@@ -9,7 +11,7 @@ defmodule Discord do
def error(conn, params) do
req_path = conn.request_path
user = if conn.assigns[:current_user] do
- conn.assigns.current_user.slug.slug
+ User.login(conn.assigns.current_user)
else
"_anonymous"
end
diff --git a/lib/kmxgit/git_manager.ex b/lib/kmxgit/git_manager.ex
index 54cce2f..07f26e9 100644
--- a/lib/kmxgit/git_manager.ex
+++ b/lib/kmxgit/git_manager.ex
@@ -23,11 +23,15 @@ defmodule Kmxgit.GitManager do
def rename_dir(from, to) do
dir_from = "#{@git_root}/#{from}/"
- dir_to = "#{@git_root}/#{to}/"
- if File.exists?(dir_to) do
- {:error, "file exists"}
+ if File.exists?(dir_from) do
+ dir_to = "#{@git_root}/#{to}/"
+ if File.exists?(dir_to) do
+ {:error, "file exists"}
+ else
+ File.rename(dir_from, dir_to)
+ end
else
- File.rename(dir_from, dir_to)
+ :ok
end
end
diff --git a/lib/kmxgit/organisation_manager.ex b/lib/kmxgit/organisation_manager.ex
index 56098ab..8234f0b 100644
--- a/lib/kmxgit/organisation_manager.ex
+++ b/lib/kmxgit/organisation_manager.ex
@@ -6,13 +6,11 @@ defmodule Kmxgit.OrganisationManager do
alias Kmxgit.OrganisationManager.Organisation
alias Kmxgit.Pagination
alias Kmxgit.Repo
- alias Kmxgit.SlugManager.Slug
alias Kmxgit.UserManager
def list_all_organisations() do
from(org in Organisation)
- |> join(:inner, [org], s in Slug, on: s.organisation_id == org.id)
- |> order_by([org, s], [asc_nulls_last: fragment("lower(?)", s.slug)])
+ |> order_by([org], [asc_nulls_last: fragment("lower(?)", org.slug_)])
|> preload([:owned_repositories, :slug])
|> Repo.all()
end
@@ -20,32 +18,31 @@ defmodule Kmxgit.OrganisationManager do
def list_organisations(params \\ %IndexParams{}) do
update_disk_usage()
from(org in Organisation)
- |> join(:inner, [org], s in Slug, on: s.organisation_id == org.id)
|> search(params)
|> index_order_by(params)
- |> Pagination.page(params, preload: [:owned_repositories, :slug])
+ |> Pagination.page(params, preload: [:owned_repositories])
end
def search(query, %IndexParams{search: search}) do
expr = "%#{search}%"
query
- |> where([org, s], ilike(org.name, ^expr) or ilike(s.slug, ^expr))
+ |> where([org], ilike(org.name, ^expr) or ilike(org.slug_, ^expr))
end
def index_order_by(query, %{column: "id", reverse: true}) do
order_by(query, [desc: :id])
end
def index_order_by(query, %{column: "name", reverse: true}) do
- order_by(query, [org, s], [desc_nulls_last: fragment("lower(?)", org.name)])
+ order_by(query, [org], [desc_nulls_last: fragment("lower(?)", org.name)])
end
def index_order_by(query, %{column: "name"}) do
- order_by(query, [org, s], [asc_nulls_last: fragment("lower(?)", org.name)])
+ order_by(query, [org], [asc_nulls_last: fragment("lower(?)", org.name)])
end
def index_order_by(query, %{column: "slug", reverse: true}) do
- order_by(query, [org, s], [desc_nulls_last: fragment("lower(?)", s.slug)])
+ order_by(query, [org], [desc_nulls_last: fragment("lower(?)", org.slug_)])
end
def index_order_by(query, %{column: "slug"}) do
- order_by(query, [org, s], [asc_nulls_last: fragment("lower(?)", s.slug)])
+ order_by(query, [org], [asc_nulls_last: fragment("lower(?)", org.slug_)])
end
def index_order_by(query, %{column: "du", reverse: true}) do
order_by(query, [desc: :disk_usage])
@@ -58,7 +55,7 @@ defmodule Kmxgit.OrganisationManager do
end
def update_disk_usage() do
- Repo.all(from org in Organisation, preload: :slug)
+ Repo.all(from org in Organisation)
|> Enum.map(fn org ->
org
|> Ecto.Changeset.cast(%{}, [])
@@ -82,10 +79,9 @@ defmodule Kmxgit.OrganisationManager do
def get_organisation(id) do
Repo.one from organisation in Organisation,
where: [id: ^id],
- preload: [:slug,
- owned_repositories: [organisation: :slug,
- user: :slug],
- users: :slug],
+ preload: [:users,
+ owned_repositories: [:organisation,
+ :user]],
limit: 1
end
@@ -93,8 +89,8 @@ defmodule Kmxgit.OrganisationManager do
get_organisation(id) || raise Ecto.NoResultsError
end
- def change_organisation(organisation \\ %Organisation{}) do
- Organisation.changeset(organisation, %{})
+ def change_organisation(organisation \\ %Organisation{}, attrs \\ %{}) do
+ Organisation.changeset(organisation, attrs)
end
def create_organisation(user, attrs \\ %{}) do
@@ -112,13 +108,10 @@ defmodule Kmxgit.OrganisationManager do
def get_organisation_by_slug(slug) do
Repo.one from o in Organisation,
- join: s in Slug,
- on: s.organisation_id == o.id,
- where: fragment("lower(?)", s.slug) == ^String.downcase(slug),
- preload: [:slug,
- owned_repositories: [organisation: :slug,
- user: :slug],
- users: :slug],
+ where: o.slug_ == ^slug,
+ preload: [:users,
+ owned_repositories: [:organisation,
+ :user]],
limit: 1
end
@@ -159,4 +152,14 @@ defmodule Kmxgit.OrganisationManager do
|> Organisation.changeset(attrs)
|> Repo.insert()
end
+
+ def update_slug_() do
+ for org <- list_all_organisations() do
+ if (org.slug) do
+ update_organisation(org, %{slug_: org.slug.slug})
+ else
+ delete_organisation(org)
+ end
+ end
+ end
end
diff --git a/lib/kmxgit/organisation_manager/organisation.ex b/lib/kmxgit/organisation_manager/organisation.ex
index b966b54..5a3b72c 100644
--- a/lib/kmxgit/organisation_manager/organisation.ex
+++ b/lib/kmxgit/organisation_manager/organisation.ex
@@ -12,20 +12,21 @@ defmodule Kmxgit.OrganisationManager.Organisation do
field :description, :string
field :disk_usage, :integer, default: 0
field :name, :string
- has_many :owned_repositories, Repository
+ has_many :owned_repositories, Repository, on_delete: :delete_all
many_to_many :users, User, join_through: "users_organisations", on_replace: :delete, on_delete: :delete_all
has_one :slug, Slug, on_delete: :delete_all
+ field :slug_, :string
timestamps()
end
@doc false
def changeset(organisation, attrs \\ %{}) do
organisation
- |> cast(attrs, [:description, :name])
- |> cast_assoc(:slug)
- |> validate_required([:slug])
+ |> cast(attrs, [:description, :name, :slug_])
+ |> validate_required([:slug_])
|> Markdown.validate_markdown(:description)
|> foreign_key_constraint(:owned_repositories, name: :repositories_organisation_id_fkey)
+ |> validate_format(:slug_, ~r/^[A-Za-z][-_+.0-9A-Za-z]{1,64}$/)
end
def owner?(org, user) do
@@ -46,7 +47,7 @@ defmodule Kmxgit.OrganisationManager.Organisation do
def disk_usage(org) do
if org do
- Git.dir_disk_usage(org.slug.slug)
+ Git.dir_disk_usage(org.slug_)
else
0
end
diff --git a/lib/kmxgit/repository_manager/repository.ex b/lib/kmxgit/repository_manager/repository.ex
index 87fcb51..7f66d1e 100644
--- a/lib/kmxgit/repository_manager/repository.ex
+++ b/lib/kmxgit/repository_manager/repository.ex
@@ -86,7 +86,7 @@ defmodule Kmxgit.RepositoryManager.Repository do
user = get_field(changeset, :user)
owner = org || user
slug = get_field(changeset, :slug)
- if repo = RepositoryManager.get_repository_by_owner_and_slug(owner.slug.slug, slug) do
+ if repo = RepositoryManager.get_repository_by_owner_and_slug(owner.slug_, slug) do
if repo.id != changeset.data.id do
changeset
|> add_error(:slug, "is already taken")
@@ -109,7 +109,7 @@ defmodule Kmxgit.RepositoryManager.Repository do
end
def owner_slug(repo) do
- owner(repo).slug.slug
+ owner(repo).slug_
end
def full_slug(repo) do
@@ -174,7 +174,7 @@ defmodule Kmxgit.RepositoryManager.Repository do
full_slug = full_slug(repo)
auth = members(repo)
|> Enum.sort(fn a, b ->
- a.slug.slug < b.slug.slug
+ a.slug_ < b.slug_
end)
|> Enum.map(fn user ->
mode = if user.deploy_only do
@@ -182,7 +182,7 @@ defmodule Kmxgit.RepositoryManager.Repository do
else
"rw"
end
- auth_line(user.slug.slug, mode, full_slug)
+ auth_line(User.login(user), mode, full_slug)
end)
auth ++ [auth_line(deploy_user(repo), "r", full_slug)]
end
diff --git a/lib/kmxgit/slug_manager.ex b/lib/kmxgit/slug_manager.ex
index 766e46e..f19ce19 100644
--- a/lib/kmxgit/slug_manager.ex
+++ b/lib/kmxgit/slug_manager.ex
@@ -3,18 +3,24 @@ defmodule Kmxgit.SlugManager do
import Ecto.Query, warn: false
alias Kmxgit.Repo
+ alias Kmxgit.OrganisationManager.Organisation
alias Kmxgit.SlugManager.Slug
- def list_slugs do
+ def list_all_slugs do
Slug
|> Repo.all
end
- def create_slug(slug) do
+ def create_slug(slug) when is_binary(slug) do
%Slug{}
|> Slug.changeset(%{slug: slug})
|> Repo.insert()
end
+ def create_slug(%Organisation{id: id, slug_: slug}) do
+ %Slug{}
+ |> Slug.create_changeset(%{slug: slug, organisation_id: id})
+ |> Repo.insert()
+ end
def update_slug(slug, attrs) do
slug
@@ -22,23 +28,31 @@ defmodule Kmxgit.SlugManager do
|> Repo.update()
end
+ def rename_slug(from, to) do
+ slug = Repo.one from s in Slug,
+ where: s.slug == ^from
+ update_slug(slug, %{slug: to})
+ end
+
def get_slug(slug) do
Repo.one from s in Slug,
- where: fragment("lower(?)", s.slug) == ^String.downcase(slug),
- preload: [organisation: [:slug,
- owned_repositories: [members: :slug,
- organisation: [:slug,
- :users],
- user: :slug],
- users: :slug],
- user: [:slug,
- organisations: :slug,
- owned_repositories: [members: :slug,
- organisation: :slug,
- user: :slug]]],
+ where: s.slug == ^slug,
+ preload: [organisation: [:users,
+ owned_repositories: [:members,
+ :user,
+ organisation: [:users]]],
+ user: [:organisations,
+ owned_repositories: [:members,
+ :organisation,
+ :user]]],
limit: 1
end
+ def delete_slug(slug) when is_binary(slug) do
+ s = Repo.one from s in Slug,
+ where: s.slug == ^slug
+ if s, do: Repo.delete(s), else: :ok
+ end
def delete_slug(%Slug{} = slug) do
Repo.delete(slug)
end
diff --git a/lib/kmxgit/slug_manager/slug.ex b/lib/kmxgit/slug_manager/slug.ex
index 521df40..421269d 100644
--- a/lib/kmxgit/slug_manager/slug.ex
+++ b/lib/kmxgit/slug_manager/slug.ex
@@ -6,17 +6,28 @@ defmodule Kmxgit.SlugManager.Slug do
alias Kmxgit.UserManager.User
schema "slugs" do
- field :slug, :string, unique: true
+ field :slug, :string
belongs_to :organisation, Organisation
belongs_to :user, User
timestamps()
end
+ def common_changeset(changeset) do
+ changeset
+ |> validate_required([:slug])
+ |> validate_format(:slug, ~r/^[A-Za-z][-_+.0-9A-Za-z]{1,64}$/)
+ |> unique_constraint(:slug)
+ end
+
def changeset(slug, attrs \\ %{}) do
slug
|> cast(attrs, [:slug])
- |> validate_required([:slug])
- |> validate_format(:slug, ~r/^[A-Za-z][-_+.0-9A-Za-z]{1,64}$/)
- |> unique_constraint(:slug, name: "slugs__lower_slug_index")
+ |> common_changeset()
+ end
+
+ def create_changeset(slug, attrs \\ %{}) do
+ slug
+ |> cast(attrs, [:slug, :organisation_id, :user_id])
+ |> common_changeset()
end
end
diff --git a/lib/kmxgit/user_manager.ex b/lib/kmxgit/user_manager.ex
index 37719d6..decd7d8 100644
--- a/lib/kmxgit/user_manager.ex
+++ b/lib/kmxgit/user_manager.ex
@@ -409,4 +409,10 @@ defmodule Kmxgit.UserManager do
false
end
end
+
+ def update_slug_() do
+ for u <- list_all_users() do
+ Kmxgit.UserManager.update_user(u, %{slug_: u.slug.slug})
+ end
+ end
end
diff --git a/lib/kmxgit/user_manager/user.ex b/lib/kmxgit/user_manager/user.ex
index 5a6a4fd..16a2e07 100644
--- a/lib/kmxgit/user_manager/user.ex
+++ b/lib/kmxgit/user_manager/user.ex
@@ -24,6 +24,7 @@ defmodule Kmxgit.UserManager.User do
field :password_confirmation, :string, virtual: true, redact: true
many_to_many :repositories, Repository, join_through: "users_repositories", on_delete: :delete_all
has_one :slug, Slug, on_delete: :delete_all
+ field :slug_, :string
field :ssh_keys, :string
many_to_many :organisations, Organisation, join_through: "users_organisations", on_delete: :delete_all
timestamps()
@@ -179,10 +180,11 @@ defmodule Kmxgit.UserManager.User do
defp common_changeset(changeset) do
changeset
|> cast_assoc(:slug)
- |> validate_required([:deploy_only, :email, :hashed_password, :is_admin, :totp_secret, :slug])
+ |> validate_required([:deploy_only, :email, :hashed_password, :is_admin, :totp_secret, :slug, :slug_])
|> validate_email()
|> Markdown.validate_markdown(:description)
|> foreign_key_constraint(:owned_repositories, name: :repositories_user_id_fkey)
+ |> validate_format(:slug_, ~r/^[A-Za-z][-_+.0-9A-Za-z]{1,64}$/)
end
defp generate_totp_secret(changeset) do
@@ -192,13 +194,13 @@ defmodule Kmxgit.UserManager.User do
def changeset(user, attrs \\ %{}) do
user
- |> cast(attrs, [:deploy_only, :description, :name, :ssh_keys])
+ |> cast(attrs, [:deploy_only, :description, :name, :slug_, :ssh_keys])
|> common_changeset()
end
def admin_changeset(user, attrs \\ %{}, opts \\ []) do
user
- |> cast(attrs, [:deploy_only, :description, :email, :is_admin, :name, :password, :ssh_keys])
+ |> cast(attrs, [:deploy_only, :description, :email, :is_admin, :name, :password, :slug_, :ssh_keys])
|> validate_email()
|> maybe_validate_password(opts)
|> common_changeset()
@@ -206,7 +208,7 @@ defmodule Kmxgit.UserManager.User do
def admin_create_user_changeset(user, attrs \\ %{}, opts \\ []) do
user
- |> cast(attrs, [:deploy_only, :description, :email, :is_admin, :name, :password, :ssh_keys])
+ |> cast(attrs, [:deploy_only, :description, :email, :is_admin, :name, :password, :slug_, :ssh_keys])
|> generate_totp_secret()
|> validate_email()
|> maybe_validate_password(opts)
@@ -223,7 +225,7 @@ defmodule Kmxgit.UserManager.User do
|> Enum.map(fn line ->
line1 = String.replace(line, "\r", "")
if Regex.match?(~r/^[ \t]*ssh-/, line1) do
- "environment=\"GIT_AUTH_ID=#{user.slug.slug}\" #{line1}"
+ "environment=\"GIT_AUTH_ID=#{login(user)}\" #{line1}"
else
line1
end
@@ -237,15 +239,7 @@ defmodule Kmxgit.UserManager.User do
end
def login(user) do
- if user do
- if user.slug do
- user.slug.slug || raise ArgumentError, "no slug for user !"
- else
- raise ArgumentError, "no slug for user"
- end
- else
- raise ArgumentError, "no slug for nil user"
- end
+ user.slug_
end
def totp_verify(%__MODULE__{totp_secret: secret}, token) do
diff --git a/lib/kmxgit_web.ex b/lib/kmxgit_web.ex
index 46c5b7d..5045be6 100644
--- a/lib/kmxgit_web.ex
+++ b/lib/kmxgit_web.ex
@@ -59,7 +59,7 @@ defmodule KmxgitWeb do
def disk_usage(size) do
units = {:kb, :mb, :gb, :tb}
- index = min(3, trunc(:math.log2(abs(size)) / 10))
+ index = min(3, trunc(:math.log2(abs(size) + 4) / 10))
unit = elem(units, index)
FileSize.new(size, :kb)
|> FileSize.convert(unit)
diff --git a/lib/kmxgit_web/controllers/admin/organisation_controller.ex b/lib/kmxgit_web/controllers/admin/organisation_controller.ex
index 74ee36f..5202b9e 100644
--- a/lib/kmxgit_web/controllers/admin/organisation_controller.ex
+++ b/lib/kmxgit_web/controllers/admin/organisation_controller.ex
@@ -80,8 +80,8 @@ defmodule KmxgitWeb.Admin.OrganisationController do
case Repo.transaction(fn ->
case OrganisationManager.update_organisation(org, params["organisation"]) do
{:ok, org1} ->
- if org.slug.slug != org1.slug.slug do
- case GitManager.rename_dir(org.slug.slug, org1.slug.slug) do
+ if org.slug_ != org1.slug_ do
+ case GitManager.rename_dir(org.slug_, org1.slug_) do
:ok ->
GitAuth.update()
org1
diff --git a/lib/kmxgit_web/controllers/organisation_controller.ex b/lib/kmxgit_web/controllers/organisation_controller.ex
index 40ff9ac..ba641b6 100644
--- a/lib/kmxgit_web/controllers/organisation_controller.ex
+++ b/lib/kmxgit_web/controllers/organisation_controller.ex
@@ -6,6 +6,8 @@ defmodule KmxgitWeb.OrganisationController do
alias Kmxgit.OrganisationManager
alias Kmxgit.OrganisationManager.Organisation
alias Kmxgit.Repo
+ alias Kmxgit.SlugManager
+ alias Kmxgit.UserManager.User
def new(conn, _params) do
_ = conn.assigns.current_user
@@ -18,11 +20,25 @@ defmodule KmxgitWeb.OrganisationController do
def create(conn, params) do
current_user = conn.assigns.current_user
- case OrganisationManager.create_organisation(current_user, params["organisation"]) do
+ case Repo.transaction(fn ->
+ case OrganisationManager.create_organisation(current_user, params["organisation"]) do
+ {:ok, organisation} ->
+ case SlugManager.create_slug(organisation) do
+ {:ok, _slug} -> organisation
+ {:error, err} ->
+ {message, _} = err.errors[:slug]
+ changeset = OrganisationManager.change_organisation(%Organisation{}, params["organisation"])
+ |> Ecto.Changeset.add_error(:slug_, message)
+ Repo.rollback(changeset)
+ end
+ {:error, err} -> Repo.rollback(err)
+ end
+ end) do
{:ok, organisation} ->
conn
- |> redirect(to: Routes.slug_path(conn, :show, organisation.slug.slug))
+ |> redirect(to: Routes.slug_path(conn, :show, organisation.slug_))
{:error, changeset} ->
+ IO.inspect(changeset)
conn
|> assign(:action, Routes.organisation_path(conn, :create))
|> assign(:changeset, changeset)
@@ -36,7 +52,7 @@ defmodule KmxgitWeb.OrganisationController do
changeset = OrganisationManager.change_organisation(org)
if org && Organisation.owner?(org, current_user) do
conn
- |> assign(:action, Routes.organisation_path(conn, :update, org.slug.slug))
+ |> assign(:action, Routes.organisation_path(conn, :update, org.slug_))
|> assign(:changeset, changeset)
|> assign(:current_organisation, org)
|> render("edit.html")
@@ -52,11 +68,15 @@ defmodule KmxgitWeb.OrganisationController do
case Repo.transaction(fn ->
case OrganisationManager.update_organisation(org, params["organisation"]) do
{:ok, org1} ->
- if org.slug.slug != org1.slug.slug do
- case GitManager.rename_dir(org.slug.slug, org1.slug.slug) do
- :ok ->
- GitAuth.update()
- org1
+ if org.slug_ != org1.slug_ do
+ case SlugManager.rename_slug(org.slug_, org1.slug_) do
+ {:ok, _} ->
+ case GitManager.rename_dir(org.slug_, org1.slug_) do
+ :ok ->
+ GitAuth.update()
+ org1
+ {:error, err} -> Repo.rollback(err)
+ end
{:error, err} -> Repo.rollback(err)
end
else
@@ -67,10 +87,10 @@ defmodule KmxgitWeb.OrganisationController do
end) do
{:ok, org1} ->
conn
- |> redirect(to: Routes.slug_path(conn, :show, org1.slug.slug))
+ |> redirect(to: Routes.slug_path(conn, :show, org1.slug_))
{:error, changeset} ->
conn
- |> assign(:action, Routes.organisation_path(conn, :update, org.slug.slug))
+ |> assign(:action, Routes.organisation_path(conn, :update, org.slug_))
|> assign(:changeset, changeset)
|> render("edit.html")
end
@@ -101,7 +121,7 @@ defmodule KmxgitWeb.OrganisationController do
{:ok, org} ->
GitAuth.update()
conn
- |> redirect(to: Routes.slug_path(conn, :show, org.slug.slug))
+ |> redirect(to: Routes.slug_path(conn, :show, org.slug_))
{:error, _e} ->
conn
|> assign(:action, Routes.organisation_path(conn, :add_user_post, params["slug"]))
@@ -135,7 +155,7 @@ defmodule KmxgitWeb.OrganisationController do
{:ok, org} ->
GitAuth.update()
conn
- |> redirect(to: Routes.slug_path(conn, :show, org.slug.slug))
+ |> redirect(to: Routes.slug_path(conn, :show, org.slug_))
{:error, _} ->
conn
|> assign(:action, Routes.organisation_path(conn, :remove_user_post, params["slug"]))
@@ -154,21 +174,26 @@ defmodule KmxgitWeb.OrganisationController do
case Repo.transaction(fn ->
case OrganisationManager.delete_organisation(org) do
{:ok, _} ->
- case GitManager.delete_dir(org.slug.slug) do
+ case SlugManager.delete_slug(org.slug_) do
:ok ->
- GitAuth.update()
- :ok
- {:error, out} -> Repo.rollback(status: out)
+ case GitManager.delete_dir(org.slug_) do
+ :ok ->
+ GitAuth.update()
+ :ok
+ {:error, out} -> Repo.rollback(status: out)
+ end
+ {:error, e} -> Repo.rollback(e)
end
{:error, e} -> Repo.rollback(e)
end
end) do
{:ok, _} ->
conn
- |> redirect(to: Routes.slug_path(conn, :show, current_user.slug.slug))
- {:error, _} ->
+ |> redirect(to: Routes.slug_path(conn, :show, User.login(current_user)))
+ {:error, err} ->
+ IO.inspect(err)
conn
- |> redirect(to: Routes.organisation_path(conn, :edit, org.slug.slug))
+ |> redirect(to: Routes.organisation_path(conn, :edit, org.slug_))
end
else
not_found(conn)
diff --git a/lib/kmxgit_web/controllers/repository_controller.ex b/lib/kmxgit_web/controllers/repository_controller.ex
index e20a476..a946b5f 100644
--- a/lib/kmxgit_web/controllers/repository_controller.ex
+++ b/lib/kmxgit_web/controllers/repository_controller.ex
@@ -84,11 +84,11 @@ defmodule KmxgitWeb.RepositoryController do
GitAuth.update()
:ok = GitManager.public_access(Repository.full_slug(repo), repo.public_access)
conn
- |> redirect(to: Routes.repository_path(conn, :show, owner.slug.slug, Repository.splat(repo)))
+ |> redirect(to: Routes.repository_path(conn, :show, owner.slug_, Repository.splat(repo)))
{:error, changeset} ->
IO.inspect changeset
conn
- |> assign(:action, Routes.repository_path(conn, :create, owner.slug.slug))
+ |> assign(:action, Routes.repository_path(conn, :create, owner.slug_))
|> assign(:changeset, changeset)
|> assign_current_organisation(owner)
|> assign(:owner, owner)
@@ -778,7 +778,7 @@ defmodule KmxgitWeb.RepositoryController do
{:ok, repo} ->
GitAuth.update()
conn
- |> redirect(to: Routes.repository_path(conn, :show, owner.slug.slug, Repository.splat(repo)))
+ |> redirect(to: Routes.repository_path(conn, :show, owner.slug_, Repository.splat(repo)))
{:error, changeset} ->
IO.inspect changeset
conn
diff --git a/lib/kmxgit_web/controllers/slug_controller.ex b/lib/kmxgit_web/controllers/slug_controller.ex
index a7806db..9db7073 100644
--- a/lib/kmxgit_web/controllers/slug_controller.ex
+++ b/lib/kmxgit_web/controllers/slug_controller.ex
@@ -46,12 +46,12 @@ defmodule KmxgitWeb.SlugController do
|> assign(:current_organisation, org)
|> assign(:disk_usage, Organisation.disk_usage(org))
|> assign(:org, org)
- |> assign(:page_title, org.name || org.slug.slug)
+ |> assign(:page_title, org.name || org.slug_)
|> assign(:repos, repos)
|> put_view(OrganisationView)
|> render("show.html")
else
- not_found(conn)
+ raise "invalid slug"
end
end
end
diff --git a/lib/kmxgit_web/controllers/user_controller.ex b/lib/kmxgit_web/controllers/user_controller.ex
index d254dce..1d1274d 100644
--- a/lib/kmxgit_web/controllers/user_controller.ex
+++ b/lib/kmxgit_web/controllers/user_controller.ex
@@ -32,7 +32,7 @@ defmodule KmxgitWeb.UserController do
conn
|> assign(:changeset, changeset)
|> assign(:email_changeset, email_changeset)
- |> assign(:page_title, gettext("Edit user %{login}", login: user.slug.slug))
+ |> assign(:page_title, gettext("Edit user %{login}", login: User.login(user)))
|> assign(:password_changeset, password_changeset)
|> assign(:user, user)
|> render("edit.html")
@@ -65,7 +65,7 @@ defmodule KmxgitWeb.UserController do
|> redirect(to: Routes.slug_path(conn, :show, User.login(user)))
{:error, changeset} ->
conn
- |> assign(:page_title, gettext("Edit user %{login}", login: user.slug.slug))
+ |> assign(:page_title, gettext("Edit user %{login}", login: User.login(user)))
|> assign(:changeset, changeset)
|> assign(:user, user)
|> render("edit.html")
@@ -150,11 +150,11 @@ defmodule KmxgitWeb.UserController do
def delete(conn, params) do
current_user = conn.assigns.current_user
- if params["login"] == current_user.slug.slug do
+ if params["login"] == User.login(current_user) do
case Repo.transaction(fn ->
case UserManager.delete_user(current_user) do
{:ok, _} ->
- case GitManager.delete_dir(current_user.slug.slug) do
+ case GitManager.delete_dir(User.login(current_user)) do
:ok -> :ok
{:error, out} -> Repo.rollback(status: out)
end
@@ -168,7 +168,7 @@ defmodule KmxgitWeb.UserController do
{:error, changeset} ->
conn
|> assign(:changeset, changeset)
- |> assign(:page_title, gettext("Edit user %{login}", login: current_user.slug.slug))
+ |> assign(:page_title, gettext("Edit user %{login}", login: User.login(current_user)))
|> render("edit.html")
end
else
diff --git a/lib/kmxgit_web/templates/admin/organisation/add_user.html.heex b/lib/kmxgit_web/templates/admin/organisation/add_user.html.heex
index 3ff78fa..e5d788b 100644
--- a/lib/kmxgit_web/templates/admin/organisation/add_user.html.heex
+++ b/lib/kmxgit_web/templates/admin/organisation/add_user.html.heex
@@ -1,6 +1,6 @@
<div class="container-fluid">
- <h1><%= gettext "Add user to %{org}", org: @org.name || @org.slug.slug %></h1>
+ <h1><%= gettext "Add user to %{org}", org: @org.name || @org.slug_ %></h1>
<%= form_for :organisation, @action, fn f -> %>
diff --git a/lib/kmxgit_web/templates/admin/organisation/edit.html.heex b/lib/kmxgit_web/templates/admin/organisation/edit.html.heex
index 107b1b1..38bc83a 100644
--- a/lib/kmxgit_web/templates/admin/organisation/edit.html.heex
+++ b/lib/kmxgit_web/templates/admin/organisation/edit.html.heex
@@ -1,5 +1,5 @@
<div class="container-fluid">
- <h1><%= gettext("Edit organisation %{organisation}", organisation: @org.name || @org.slug.slug) %></h1>
+ <h1><%= gettext("Edit organisation %{organisation}", organisation: @org.name || @org.slug_) %></h1>
<%= render("form.html", assigns) %>
</div>
diff --git a/lib/kmxgit_web/templates/admin/organisation/index.html.heex b/lib/kmxgit_web/templates/admin/organisation/index.html.heex
index 7ff9178..07fd206 100644
--- a/lib/kmxgit_web/templates/admin/organisation/index.html.heex
+++ b/lib/kmxgit_web/templates/admin/organisation/index.html.heex
@@ -24,10 +24,10 @@
<tr>
<td><%= link org.id, to: Routes.admin_organisation_path(@conn, :show, org) %></td>
<td><%= link org.name, to: Routes.admin_organisation_path(@conn, :show, org) %></td>
- <td><%= link org.slug.slug, to: Routes.admin_organisation_path(@conn, :show, org) %></td>
+ <td><%= link org.slug_, to: Routes.admin_organisation_path(@conn, :show, org) %></td>
<td><%= disk_usage(org.disk_usage) %></td>
<td>
- <%= link gettext("Show"), to: Routes.slug_path(@conn, :show, org.slug.slug), class: "btn btn-sm btn-primary" %>
+ <%= link gettext("Show"), to: Routes.slug_path(@conn, :show, org.slug_), class: "btn btn-sm btn-primary" %>
</td>
</tr>
<% end %>
diff --git a/lib/kmxgit_web/templates/admin/organisation/remove_user.html.heex b/lib/kmxgit_web/templates/admin/organisation/remove_user.html.heex
index 96339ff..8eddb16 100644
--- a/lib/kmxgit_web/templates/admin/organisation/remove_user.html.heex
+++ b/lib/kmxgit_web/templates/admin/organisation/remove_user.html.heex
@@ -1,6 +1,6 @@
<div class="container-fluid">
- <h1><%= gettext "Remove user from %{org}", org: @org.name || @org.slug.slug %></h1>
+ <h1><%= gettext "Remove user from %{org}", org: @org.name || @org.slug_ %></h1>
<%= form_for :organisation, @action, fn f -> %>
diff --git a/lib/kmxgit_web/templates/admin/organisation/show.html.heex b/lib/kmxgit_web/templates/admin/organisation/show.html.heex
index c53a439..f2cb2a7 100644
--- a/lib/kmxgit_web/templates/admin/organisation/show.html.heex
+++ b/lib/kmxgit_web/templates/admin/organisation/show.html.heex
@@ -1,5 +1,5 @@
<div class="container-fluid">
- <h1><%= gettext("Organisation %{org}", org: @org.name || @org.slug.slug) %></h1>
+ <h1><%= gettext("Organisation %{org}", org: @org.name || @org.slug_) %></h1>
<table class="table admin-properties">
<tr>
@@ -12,7 +12,7 @@
</tr>
<tr>
<th><%= gettext "Slug" %></th>
- <td><%= @org.slug.slug %></td>
+ <td><%= @org.slug_ %></td>
</tr>
<tr>
<th><%= gettext "Description" %></th>
@@ -26,7 +26,7 @@
<th><%= gettext "Users" %></th>
<td>
<%= for user <- @org.users do %>
- <%= link(user.slug.slug, to: Routes.admin_user_path(@conn, :show, user), class: "user") %>
+ <%= link(User.login(user), to: Routes.admin_user_path(@conn, :show, user), class: "user") %>
<% end %>
<%= link "-",
to: Routes.admin_organisation__path(@conn, :remove_user, @org),
@@ -65,6 +65,6 @@
class: "btn btn-primary" %>
<%= link gettext("Show"),
- to: Routes.slug_path(@conn, :show, @org.slug.slug),
+ to: Routes.slug_path(@conn, :show, @org.slug_),
class: "btn btn-primary" %>
</div>
diff --git a/lib/kmxgit_web/templates/admin/repository/index.html.heex b/lib/kmxgit_web/templates/admin/repository/index.html.heex
index c962b7e..b281113 100644
--- a/lib/kmxgit_web/templates/admin/repository/index.html.heex
+++ b/lib/kmxgit_web/templates/admin/repository/index.html.heex
@@ -19,9 +19,9 @@
<td>
<%= case owner = Repository.owner(repo) do %>
<% %Organisation{} -> %>
- <%= link owner.name || owner.slug.slug, to: Routes.admin_organisation_path(@conn, :show, owner) %>
+ <%= link owner.name || owner.slug_, to: Routes.admin_organisation_path(@conn, :show, owner) %>
<% %User{} -> %>
- <%= link owner.slug.slug, to: Routes.admin_user_path(@conn, :show, owner) %>
+ <%= link User.login(owner), to: Routes.admin_user_path(@conn, :show, owner) %>
<% end %>
</td>
<td><%= link Repository.full_slug(repo), to: Routes.admin_repository_path(@conn, :show, repo) %></td>
diff --git a/lib/kmxgit_web/templates/admin/repository/show.html.heex b/lib/kmxgit_web/templates/admin/repository/show.html.heex
index 3867ca4..b64214a 100644
--- a/lib/kmxgit_web/templates/admin/repository/show.html.heex
+++ b/lib/kmxgit_web/templates/admin/repository/show.html.heex
@@ -12,10 +12,10 @@
<%= case owner = Repository.owner(@repo) do %>
<% %Organisation{} -> %>
<%= gettext "Organisation" %>
- <%= link owner.name || owner.slug.slug, to: Routes.admin_organisation_path(@conn, :show, owner) %>
+ <%= link owner.name || owner.slug_, to: Routes.admin_organisation_path(@conn, :show, owner) %>
<% %User{} -> %>
<%= gettext "User" %>
- <%= link owner.slug.slug, to: Routes.admin_user_path(@conn, :show, owner) %>
+ <%= link User.login(owner), to: Routes.admin_user_path(@conn, :show, owner) %>
<% end %>
</td>
</tr>
@@ -55,7 +55,7 @@
<th><%= gettext "Members" %></th>
<td>
<%= for user <- @members do %>
- <%= link(user.slug.slug, to: Routes.admin_user_path(@conn, :show, user), class: "user") %>
+ <%= link(User.login(user), to: Routes.admin_user_path(@conn, :show, user), class: "user") %>
<% end %>
<%= link "-",
to: Routes.admin_repository__path(@conn, :remove_user, @repo),
diff --git a/lib/kmxgit_web/templates/admin/user/edit.html.heex b/lib/kmxgit_web/templates/admin/user/edit.html.heex
index b6d247f..5313e7d 100644
--- a/lib/kmxgit_web/templates/admin/user/edit.html.heex
+++ b/lib/kmxgit_web/templates/admin/user/edit.html.heex
@@ -1,5 +1,5 @@
<div class="container-fluid">
- <h1><%= gettext "Edit user" %> <%= @user.slug.slug %></h1>
+ <h1><%= gettext "Edit user" %> <%= User.login(@user) %></h1>
<%= render("form.html", assigns) %>
</div>
diff --git a/lib/kmxgit_web/templates/admin/user/edit_password.html.heex b/lib/kmxgit_web/templates/admin/user/edit_password.html.heex
index 5731463..007e605 100644
--- a/lib/kmxgit_web/templates/admin/user/edit_password.html.heex
+++ b/lib/kmxgit_web/templates/admin/user/edit_password.html.heex
@@ -1,5 +1,5 @@
<div class="container-fluid">
- <h1><%= gettext "Edit user" %> <%= @user.slug.slug %></h1>
+ <h1><%= gettext "Edit user" %> <%= User.login(@user) %></h1>
<%= form_for @changeset, Routes.admin_user__path(@conn, :update_password, @user), fn f -> %>
<div class="mb-3">
diff --git a/lib/kmxgit_web/templates/admin/user/show.html.heex b/lib/kmxgit_web/templates/admin/user/show.html.heex
index 7f62197..79f3407 100644
--- a/lib/kmxgit_web/templates/admin/user/show.html.heex
+++ b/lib/kmxgit_web/templates/admin/user/show.html.heex
@@ -32,7 +32,7 @@
</th>
<td>
<%= for org <- @user.organisations do %>
- <%= link(org.name || org.slug.slug, to: Routes.admin_organisation_path(@conn, :show, org), class: "org") %>
+ <%= link(org.name || org.slug_, to: Routes.admin_organisation_path(@conn, :show, org), class: "org") %>
<% end %>
</td>
</tr>
diff --git a/lib/kmxgit_web/templates/layout/nav_connected.html.heex b/lib/kmxgit_web/templates/layout/nav_connected.html.heex
index c7481f9..0b64dc8 100644
--- a/lib/kmxgit_web/templates/layout/nav_connected.html.heex
+++ b/lib/kmxgit_web/templates/layout/nav_connected.html.heex
@@ -7,13 +7,13 @@
<% end %>
<%= if @conn.assigns[:current_organisation] do %>
<li class="nav-item">
- <%= link @current_organisation.name || @current_organisation.slug.slug,
- to: Routes.slug_path(@conn, :show, @current_organisation.slug.slug),
+ <%= link @current_organisation.name || @current_organisation.slug_,
+ to: Routes.slug_path(@conn, :show, @current_organisation.slug_),
class: "nav-link" %>
</li>
<% end %>
<li class="nav-item">
- <%= link @current_user.slug.slug, to: Routes.slug_path(@conn, :show, @current_user.slug.slug), class: "nav-link" %>
+ <%= link User.login(@current_user), to: Routes.slug_path(@conn, :show, User.login(@current_user)), class: "nav-link" %>
</li>
<%= if @current_user.is_admin do %>
<li class="nav-item">
diff --git a/lib/kmxgit_web/templates/organisation/add_user.html.heex b/lib/kmxgit_web/templates/organisation/add_user.html.heex
index 4694f90..36734d0 100644
--- a/lib/kmxgit_web/templates/organisation/add_user.html.heex
+++ b/lib/kmxgit_web/templates/organisation/add_user.html.heex
@@ -1,6 +1,6 @@
<div class="container-fluid">
- <h1><%= gettext "Add user to %{org}", org: @current_organisation.name || @current_organisation.slug.slug %></h1>
+ <h1><%= gettext "Add user to %{org}", org: @current_organisation.name || @current_organisation.slug_ %></h1>
<%= form_for :organisation, @action, fn f -> %>
diff --git a/lib/kmxgit_web/templates/organisation/edit.html.heex b/lib/kmxgit_web/templates/organisation/edit.html.heex
index d3d369c..222578c 100644
--- a/lib/kmxgit_web/templates/organisation/edit.html.heex
+++ b/lib/kmxgit_web/templates/organisation/edit.html.heex
@@ -1,4 +1,4 @@
<div class="container-fluid">
- <h1><%= gettext("Edit organisation %{organisation}", organisation: @current_organisation.name || @current_organisation.slug.slug) %></h1>
+ <h1><%= gettext("Edit organisation %{organisation}", organisation: @current_organisation.name || @current_organisation.slug_) %></h1>
<%= render "form.html", assigns %>
</div>
diff --git a/lib/kmxgit_web/templates/organisation/form.html.heex b/lib/kmxgit_web/templates/organisation/form.html.heex
index 0f316af..95b5cde 100644
--- a/lib/kmxgit_web/templates/organisation/form.html.heex
+++ b/lib/kmxgit_web/templates/organisation/form.html.heex
@@ -1,12 +1,10 @@
<%= form_for @changeset, @action, fn f -> %>
- <%= inputs_for f, :slug, fn ff -> %>
- <div class="mb-3">
- <%= label ff, :slug, class: "form-label" %>
- <%= text_input ff, :slug, class: "form-control" %>
- <%= error_tag ff, :slug %>
- </div>
- <% end %>
+ <div class="mb-3">
+ <%= label f, :slug_, class: "form-label" %>
+ <%= text_input f, :slug_, class: "form-control" %>
+ <%= error_tag f, :slug_ %>
+ </div>
<div class="mb-3">
<%= label f, :name, class: "form-label" %>
@@ -23,16 +21,16 @@
<div class="mb-3">
<%= if @conn.assigns[:current_organisation] do %>
<%= link gettext("Cancel"),
- to: Routes.slug_path(@conn, :show, @current_organisation.slug.slug),
+ to: Routes.slug_path(@conn, :show, @current_organisation.slug_),
class: "btn btn-secondary" %>
<%= link gettext("Delete organisation"),
- to: Routes.organisation_path(@conn, :delete, @current_organisation.slug.slug),
+ to: Routes.organisation_path(@conn, :delete, @current_organisation.slug_),
method: :delete,
class: "btn btn-danger",
- data: [confirm: gettext("Are you sure you want to delete the organisation %{org} ?", org: @current_organisation.name || @current_organisation.slug.slug)] %>
+ data: [confirm: gettext("Are you sure you want to delete the organisation %{org} ?", org: @current_organisation.name || @current_organisation.slug_)] %>
<% else %>
<%= link gettext("Cancel"),
- to: Routes.slug_path(@conn, :show, @current_user.slug.slug),
+ to: Routes.slug_path(@conn, :show, User.login(@current_user)),
class: "btn btn-secondary" %>
<% end %>
<%= submit gettext("Submit"), class: "btn btn-primary" %>
diff --git a/lib/kmxgit_web/templates/organisation/remove_user.html.heex b/lib/kmxgit_web/templates/organisation/remove_user.html.heex
index 47e3321..50a8e29 100644
--- a/lib/kmxgit_web/templates/organisation/remove_user.html.heex
+++ b/lib/kmxgit_web/templates/organisation/remove_user.html.heex
@@ -1,6 +1,6 @@
<div class="container-fluid">
- <h1><%= gettext "Remove user from %{org}", org: @current_organisation.name || @current_organisation.slug.slug %></h1>
+ <h1><%= gettext "Remove user from %{org}", org: @current_organisation.name || @current_organisation.slug_ %></h1>
<%= form_for :organisation, @action, fn f -> %>
diff --git a/lib/kmxgit_web/templates/organisation/show.html.heex b/lib/kmxgit_web/templates/organisation/show.html.heex
index 862975e..e7e7072 100644
--- a/lib/kmxgit_web/templates/organisation/show.html.heex
+++ b/lib/kmxgit_web/templates/organisation/show.html.heex
@@ -1,13 +1,13 @@
<div class="container-fluid">
<div class="row">
<div class="col col-12">
- <h1><%= @org.name || @org.slug.slug %></h1>
+ <h1><%= @org.name || @org.slug_ %></h1>
<%= if Organisation.owner?(@org, @current_user) do %>
<%= link gettext("New repository"),
- to: Routes.repository_path(@conn, :new, @org.slug.slug),
+ to: Routes.repository_path(@conn, :new, @org.slug_),
class: "btn btn-primary" %>
<%= link gettext("Edit"),
- to: Routes.organisation_path(@conn, :edit, @org.slug.slug),
+ to: Routes.organisation_path(@conn, :edit, @org.slug_),
class: "btn btn-primary" %>
<% end %>
</div>
@@ -19,7 +19,7 @@
<ul>
<%= for repo <- @repos do %>
<li>
- <%= link Repository.full_slug(repo), to: Routes.repository_path(@conn, :show, @org.slug.slug, Repository.splat(repo)) %>
+ <%= link Repository.full_slug(repo), to: Routes.repository_path(@conn, :show, @org.slug_, Repository.splat(repo)) %>
</li>
<% end %>
</ul>
@@ -33,7 +33,7 @@
</tr>
<tr>
<th><%= gettext "Slug" %></th>
- <td><%= @org.slug.slug %></td>
+ <td><%= @org.slug_ %></td>
</tr>
<tr>
<th><%= gettext "Description" %></th>
@@ -48,16 +48,16 @@
<%= gettext "Users" %><br/>
<%= if Organisation.owner?(@org, @current_user) do %>
<%= link "-",
- to: Routes.organisation_path(@conn, :remove_user, @org.slug.slug),
+ to: Routes.organisation_path(@conn, :remove_user, @org.slug_),
class: "btn btn-danger btn-sm" %>
<%= link "+",
- to: Routes.organisation_path(@conn, :add_user, @org.slug.slug),
+ to: Routes.organisation_path(@conn, :add_user, @org.slug_),
class: "btn btn-primary btn-sm" %>
<% end %>
</th>
<td>
<%= for user <- @org.users do %>
- <%= render(KmxgitWeb.UserView, "avatar.html", conn: @conn, email: user.email, size: 48, title: user.slug.slug, class: "") %>
+ <%= render(KmxgitWeb.UserView, "avatar.html", conn: @conn, email: user.email, size: 48, title: User.login(user), class: "") %>
<% end %>
</td>
</tr>
diff --git a/lib/kmxgit_web/templates/page/sitemap.txt.eex b/lib/kmxgit_web/templates/page/sitemap.txt.eex
index e2908ad..e757c15 100644
--- a/lib/kmxgit_web/templates/page/sitemap.txt.eex
+++ b/lib/kmxgit_web/templates/page/sitemap.txt.eex
@@ -1,6 +1,6 @@
<%= Routes.page_url(@conn, :index) %>
-<%= for user <- @users do %><%= Routes.slug_url(@conn, :show, user.slug.slug) %>
-<%= for repo <- user.owned_repositories do %><%= if repo.public_access do %><%= Routes.repository_url(@conn, :show, user.slug.slug, Repository.splat(repo)) %>
-<% end %><% end %><% end %><%= for org <- @orgs do %><%= Routes.slug_url(@conn, :show, org.slug.slug) %>
-<%= for repo <- org.owned_repositories do %><%= if repo.public_access do %><%= Routes.repository_url(@conn, :show, org.slug.slug, Repository.splat(repo)) %>
+<%= for user <- @users do %><%= Routes.slug_url(@conn, :show, User.login(user)) %>
+<%= for repo <- user.owned_repositories do %><%= if repo.public_access do %><%= Routes.repository_url(@conn, :show, User.login(user), Repository.splat(repo)) %>
+<% end %><% end %><% end %><%= for org <- @orgs do %><%= Routes.slug_url(@conn, :show, org.slug_) %>
+<%= for repo <- org.owned_repositories do %><%= if repo.public_access do %><%= Routes.repository_url(@conn, :show, org.slug_, Repository.splat(repo)) %>
<% end %><% end %><% end %>
diff --git a/lib/kmxgit_web/templates/repository/form.html.heex b/lib/kmxgit_web/templates/repository/form.html.heex
index c21780e..08c3228 100644
--- a/lib/kmxgit_web/templates/repository/form.html.heex
+++ b/lib/kmxgit_web/templates/repository/form.html.heex
@@ -51,7 +51,7 @@
data: [confirm: gettext("Are you sure you want to delete the repository %{repo} ?", repo: Repository.full_slug(@current_repository))] %>
<% else %>
<%= link gettext("Cancel"),
- to: Routes.slug_path(@conn, :show, @owner.slug.slug),
+ to: Routes.slug_path(@conn, :show, @owner.slug_),
class: "btn btn-secondary" %>
<% end %>
<%= submit gettext("Submit"), class: "btn btn-primary" %>
diff --git a/lib/kmxgit_web/templates/repository/new.html.heex b/lib/kmxgit_web/templates/repository/new.html.heex
index 61acd57..48e0203 100644
--- a/lib/kmxgit_web/templates/repository/new.html.heex
+++ b/lib/kmxgit_web/templates/repository/new.html.heex
@@ -1,9 +1,9 @@
<div class="container-fluid">
<h1>
<%= if @conn.assigns[:current_organisation] do %>
- <%= gettext("New repository for organisation %{org}", org: @current_organisation.name || @current_organisation.slug.slug) %>
+ <%= gettext("New repository for organisation %{org}", org: @current_organisation.name || @current_organisation.slug_) %>
<% else %>
- <%= gettext("New repository for user %{login}", login: @owner.slug.slug) %>
+ <%= gettext("New repository for user %{login}", login: User.login(@owner)) %>
<% end %>
</h1>
<%= render "form.html", assigns %>
diff --git a/lib/kmxgit_web/templates/repository/show_properties.html.heex b/lib/kmxgit_web/templates/repository/show_properties.html.heex
index 8940434..e0fd1e8 100644
--- a/lib/kmxgit_web/templates/repository/show_properties.html.heex
+++ b/lib/kmxgit_web/templates/repository/show_properties.html.heex
@@ -33,16 +33,16 @@
<%= gettext "Users" %><br/>
<%= if Repository.owner?(@repo, @current_user) do %>
<%= link "-",
- to: Routes.repository_path(@conn, :remove_user, @owner.slug.slug, Repository.splat(@repo)),
+ to: Routes.repository_path(@conn, :remove_user, @owner.slug_, Repository.splat(@repo)),
class: "btn btn-danger btn-sm" %>
<%= link "+",
- to: Routes.repository_path(@conn, :add_user, @owner.slug.slug, Repository.splat(@repo)),
+ to: Routes.repository_path(@conn, :add_user, @owner.slug_, Repository.splat(@repo)),
class: "btn btn-primary btn-sm" %>
<% end %>
</th>
<td>
<%= for user <- @members do %>
- <%= render(KmxgitWeb.UserView, "avatar.html", conn: @conn, email: user.email, size: 48, title: user.slug.slug, class: "") %>
+ <%= render(KmxgitWeb.UserView, "avatar.html", conn: @conn, email: user.email, size: 48, title: User.login(user), class: "") %>
<% end %>
</td>
</tr>
diff --git a/lib/kmxgit_web/templates/user/show.html.heex b/lib/kmxgit_web/templates/user/show.html.heex
index f2c83ae..b0b86d6 100644
--- a/lib/kmxgit_web/templates/user/show.html.heex
+++ b/lib/kmxgit_web/templates/user/show.html.heex
@@ -2,7 +2,7 @@
<div class="row">
<div class="col col-12">
<%= render("avatar.html", conn: @conn, email: @user.email, size: 256, title: User.login(@user), class: "avatar-lg") %>
- <h1><%= @user.name %> (<%= @user.slug.slug %>)</h1>
+ <h1><%= @user.name %> (<%= User.login(@user) %>)</h1>
<div class="col col-12 col-md-8">
<%= if @user.description do %>
<%= raw Markdown.to_html!(@user.description) %>
@@ -10,10 +10,10 @@
</div>
<%= if @current_user && @user.id == @current_user.id do %>
<%= link gettext("New repository"),
- to: Routes.repository_path(@conn, :new, @user.slug.slug),
+ to: Routes.repository_path(@conn, :new, User.login(@user)),
class: "btn btn-primary" %>
<%= link gettext("Edit"),
- to: Routes.user_path(@conn, :edit, @user.slug.slug),
+ to: Routes.user_path(@conn, :edit, User.login(@user)),
class: "btn btn-primary" %>
<% end %>
</div>
@@ -38,7 +38,7 @@
</tr>
<tr>
<th><%= gettext "Login" %></th>
- <td><%= @user.slug.slug %></td>
+ <td><%= User.login(@user) %></td>
</tr>
<tr>
<th><%= gettext "Deploy only" %></th>
@@ -53,10 +53,10 @@
</th>
<td>
<ul>
- <%= for org <- Enum.sort_by(@user.organisations, & &1.slug.slug) do %>
+ <%= for org <- Enum.sort_by(@user.organisations, & &1.slug_) do %>
<li>
- <%= link(org.name || org.slug.slug,
- to: Routes.slug_path(@conn, :show, org.slug.slug),
+ <%= link(org.name || org.slug_,
+ to: Routes.slug_path(@conn, :show, org.slug_),
class: "org") %>
</li>
<% end %>
diff --git a/lib/kmxgit_web/templates/user_settings/edit.html.heex b/lib/kmxgit_web/templates/user_settings/edit.html.heex
index 83f8500..db10e3b 100644
--- a/lib/kmxgit_web/templates/user_settings/edit.html.heex
+++ b/lib/kmxgit_web/templates/user_settings/edit.html.heex
@@ -1,7 +1,7 @@
<div class="container-fluid">
<h1>
<%= gettext "Edit user" %>
- <%= @current_user.slug.slug %>
+ <%= User.login(@current_user) %>
</h1>
<h2><%= gettext "Change email" %></h2>
diff --git a/priv/repo/migrations/20220617110054_slug_.exs b/priv/repo/migrations/20220617110054_slug_.exs
new file mode 100644
index 0000000..b9e2c91
--- /dev/null
+++ b/priv/repo/migrations/20220617110054_slug_.exs
@@ -0,0 +1,15 @@
+defmodule Kmxgit.Repo.Migrations.Slug do
+ use Ecto.Migration
+
+ def change do
+ alter table(:organisations) do
+ add :slug_, :citext
+ end
+ alter table(:users) do
+ add :slug_, :citext
+ end
+ alter table(:slugs) do
+ modify :slug, :citext, null: false
+ end
+ end
+end
diff --git a/priv/repo/migrations/20220618074810_slug_2.exs b/priv/repo/migrations/20220618074810_slug_2.exs
new file mode 100644
index 0000000..9fd921f
--- /dev/null
+++ b/priv/repo/migrations/20220618074810_slug_2.exs
@@ -0,0 +1,8 @@
+defmodule Kmxgit.Repo.Migrations.Slug2 do
+ use Ecto.Migration
+
+ def change do
+ drop index(:slugs, ["(lower(slug))"], unique: true)
+ create index(:slugs, [:slug], unique: true)
+ end
+end