Skip to content

Commit af72eac

Browse files
committed
Allow test games
1 parent 6d96a75 commit af72eac

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

services/app/apps/codebattle/lib/codebattle_web/plugs/assign_current_user.ex

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,32 @@ defmodule CodebattleWeb.Plugs.AssignCurrentUser do
4444
end
4545
end
4646

47+
@allowed_paths [
48+
~r{^\/games\/\d+\/?$},
49+
~r{^\/games\/training\/?$}
50+
]
4751
defp handle_guest(conn) do
48-
if FunWithFlags.enabled?(:restrict_guests_access) do
49-
url = Application.get_env(:codebattle, :guest_user_force_redirect_url)
52+
restrict_guests_access? = FunWithFlags.enabled?(:restrict_guests_access)
53+
allow_test_game? = FunWithFlags.enabled?(:allow_test_game)
54+
url = Application.get_env(:codebattle, :guest_user_force_redirect_url)
55+
56+
cond do
57+
restrict_guests_access? && allow_test_game? && Enum.any?(@allowed_paths, &Regex.match?(&1, conn.request_path)) ->
58+
assign(conn, :current_user, User.build_guest())
59+
5060
# redirect to login page if there is now custom guest_auth_url
51-
if url in [nil, ""] do
61+
restrict_guests_access? && url in [nil, ""] ->
5262
conn
5363
|> redirect(to: Routes.session_path(conn, :new))
5464
|> halt()
55-
else
65+
66+
restrict_guests_access? ->
5667
conn
5768
|> redirect(external: url)
5869
|> halt()
59-
end
60-
else
61-
assign(conn, :current_user, User.build_guest())
70+
71+
:default ->
72+
assign(conn, :current_user, User.build_guest())
6273
end
6374
end
6475
end

services/app/apps/codebattle/lib/codebattle_web/plugs/force_redirect.ex

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ defmodule CodebattleWeb.Plugs.ForceRedirect do
2424
~r{^\/api\/v1\/playbook\/\d+\/?$}
2525
]
2626

27-
# @allowed_banned_paths [
28-
# ~r{^\/$},
29-
# ~r{^\/e\/\S+\/?$},
30-
# ~r{^\/maintenance\/?$},
31-
# ~r{^\/api\/v1\/events\/.+$},
32-
# ~r{^\/auth\/token\/?$}
33-
# ]
27+
@allowed_banned_paths [
28+
# ~r{^\/$},
29+
# ~r{^\/e\/\S+\/?$},
30+
~r{^\/maintenance\/?$},
31+
# ~r{^\/api\/v1\/events\/.+$},
32+
# ~r{^\/auth\/token\/?$}
33+
]
3434

3535
@spec init(Keyword.t()) :: Keyword.t()
3636
def init(opts), do: opts
@@ -43,7 +43,7 @@ defmodule CodebattleWeb.Plugs.ForceRedirect do
4343
User.admin?(conn.assigns.current_user) ->
4444
conn
4545

46-
conn.assigns.current_user.subscription_type == :banned ->
46+
conn.assigns.current_user.subscription_type == :banned && !Enum.any?(@allowed_banned_paths, &Regex.match?(&1, conn.request_path)) ->
4747
conn
4848
|> redirect(to: "/maintenance")
4949
|> halt()

0 commit comments

Comments
 (0)