Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/algora_web/controllers/user_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ defmodule AlgoraWeb.UserController do
alias Algora.Repo

def index(conn, %{"handle" => handle}) do
redirect_to_handle(conn, handle)
end

def profile(conn, %{"handle" => handle}) do
redirect_to_handle(conn, handle)
end

defp redirect_to_handle(conn, handle) do
user = Repo.get_by(User, handle: handle)

case user do
Expand Down
2 changes: 2 additions & 0 deletions lib/algora_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ defmodule AlgoraWeb.Router do
scope "/", AlgoraWeb do
pipe_through [:browser]

get "/profile/:handle", UserController, :profile

scope "/:repo_owner/:repo_name" do
get "/", RepoController, :index

Expand Down
27 changes: 27 additions & 0 deletions test/algora_web/controllers/user_controller_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
defmodule AlgoraWeb.UserControllerTest do
use AlgoraWeb.ConnCase

import Algora.Factory

test "redirects legacy profile paths for individuals", %{conn: conn} do
user = insert(:user)

conn = get(conn, "/profile/#{user.handle}")

assert redirected_to(conn) == "/#{user.handle}/profile"
end

test "redirects legacy profile paths for organizations", %{conn: conn} do
org = insert(:organization)

conn = get(conn, "/profile/#{org.handle}")

assert redirected_to(conn) == "/#{org.handle}/dashboard"
end

test "raises not found for unknown legacy profile handles", %{conn: conn} do
assert_raise AlgoraWeb.NotFoundError, fn ->
get(conn, "/profile/missing-profile-handle")
end
end
end