Skip to content

Commit 1e0b91f

Browse files
committed
Fix maintenance for admin
1 parent c11a4c0 commit 1e0b91f

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

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

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
defmodule CodebattleWeb.Plugs.MaintenanceMode do
2+
@moduledoc false
3+
use Gettext, backend: CodebattleWeb.Gettext
4+
5+
import Phoenix.Controller
6+
import Plug.Conn
7+
8+
alias Codebattle.User
9+
10+
@spec init(Keyword.t()) :: Keyword.t()
11+
def init(opts), do: opts
12+
13+
@spec call(Plug.Conn.t(), Keyword.t()) :: Plug.Conn.t()
14+
def call(conn, _opts) do
15+
cond do
16+
User.admin?(conn.assigns.current_user) ->
17+
conn
18+
19+
FunWithFlags.enabled?(:maintenance_mode) ->
20+
conn
21+
|> put_status(:service_unavailable)
22+
|> put_layout({CodebattleWeb.LayoutView, "landing.html"})
23+
|> put_view(CodebattleWeb.RootView)
24+
|> render("maintenance.html")
25+
|> halt()
26+
27+
:default ->
28+
conn
29+
end
30+
end
31+
end

services/app/apps/codebattle/lib/codebattle_web/router.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ defmodule CodebattleWeb.Router do
2828
plug(:fetch_session)
2929
plug(:fetch_flash)
3030
plug(:fetch_live_flash)
31-
plug(MaintenanceMode)
3231
plug(AssignCurrentUser)
32+
plug(MaintenanceMode)
3333
plug(ForceRedirect)
3434
plug(:protect_from_forgery)
3535
plug(:put_secure_browser_headers)

0 commit comments

Comments
 (0)