Skip to content

Commit

Permalink
Lock add/ delete behind :test_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jere0500 committed Jun 8, 2024
1 parent be85147 commit 42c4b76
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
8 changes: 7 additions & 1 deletion lib/teiserver_web/controllers/admin/user_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ defmodule TeiserverWeb.Admin.UserController do
|> redirect(to: ~p"/teiserver/admin/user")
end

if allow?(conn, "Server") do
if allow?(conn, "Server") and Application.get_env(:teiserver, Teiserver)[:test_mode] do
password =
if is_nil(params["password"]) or String.trim(params["password"]) == "" do
"password"
Expand Down Expand Up @@ -1162,6 +1162,12 @@ defmodule TeiserverWeb.Admin.UserController do

@spec delete_user(Plug.Conn.t(), map()) :: Plug.Conn.t()
def delete_user(conn, %{"id" => id}) do
if not Application.get_env(:teiserver, Teiserver)[:test_mode] do
conn
|> put_flash(:danger, "not in testmode")
|> redirect(to: ~p"/teiserver/admin/user")
end

user = Account.get_user_by_id(id)

case Teiserver.Account.UserLib.has_access(user, conn) do
Expand Down
11 changes: 8 additions & 3 deletions lib/teiserver_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,9 @@ defmodule TeiserverWeb.Router do
# User stuff
put("/users/gdpr_clean/:id", UserController, :gdpr_clean)

delete("/users/delete_user/:id", UserController, :delete_user)
if Application.compile_env(:teiserver, Teiserver)[:test_mode] do
delete("/users/delete_user/:id", UserController, :delete_user)
end
end

scope "/teiserver/admin", TeiserverWeb.Admin, as: :admin do
Expand Down Expand Up @@ -619,8 +621,11 @@ defmodule TeiserverWeb.Router do
get("/tools/falist", ToolController, :falist)
get("/tools/test_page", ToolController, :test_page)

get("/users/create_form", UserController, :create_form)
post("/users/create_post", UserController, :create_post)
if Application.compile_env(:teiserver, Teiserver)[:test_mode] do
get("/users/create_form", UserController, :create_form)
post("/users/create_post", UserController, :create_post)
end

get("/users/rename_form/:id", UserController, :rename_form)
put("/users/rename_post/:id", UserController, :rename_post)
get("/users/reset_password/:id", UserController, :reset_password)
Expand Down
4 changes: 3 additions & 1 deletion lib/teiserver_web/templates/admin/user/actions.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@
</.link>

<.link
:if={allow?(@current_user, "Server")}
:if={
allow?(@current_user, "Server") and Application.get_env(:teiserver, Teiserver)[:test_mode]
}
href={~p"/admin/users/delete_user/#{@user.id}"}
data-confirm="Are you sure?"
method="delete"
Expand Down
6 changes: 3 additions & 3 deletions lib/teiserver_web/templates/admin/user/index.html.heex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% bsname = view_colour()
is_moderator = allow?(@conn, "Moderator")
is_system = allow?(@conn, "System") %>
allow_delete = allow?(@conn, "Server") and Application.get_env(:teiserver, Teiserver)[:test_mode] %>

<script type="text/javascript" charset="utf-8">
$(function() {
Expand Down Expand Up @@ -72,7 +72,7 @@ is_system = allow?(@conn, "System") %>
<% else %>
<th>&nbsp;</th>
<% end %>
<%= if is_system do %>
<%= if allow_delete do %>
<th colspan="1">&nbsp;</th>
<% end %>
</tr>
Expand Down Expand Up @@ -131,7 +131,7 @@ is_system = allow?(@conn, "System") %>
</a>
</td>
<% end %>
<%= if is_system do %>
<%= if allow_delete do %>
<td>
<.link
href={~p"/admin/users/delete_user/#{user.id}"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
) %>
<% end %>

<%= if allow?(@current_user, "admin") do %>
<%= if allow?(@current_user, "server") and Application.get_env(:teiserver, Teiserver)[:test_mode] do %>
<%= central_component("section_menu_button",
name: "add_user",
label: "Add user",
Expand Down

0 comments on commit 42c4b76

Please sign in to comment.