From bc5d0343888e2c8339cc80d5f411dcd91e14b604 Mon Sep 17 00:00:00 2001 From: jdonis Date: Mon, 9 Sep 2024 23:53:37 -0400 Subject: [PATCH] NG can't submit or create new Challenges --- lib/web/controllers/challenge_controller.ex | 32 +++++++++++++-------- lib/web/templates/challenge/index.html.eex | 2 ++ lib/web/views/dashboard_view.ex | 23 +++++++++------ 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/lib/web/controllers/challenge_controller.ex b/lib/web/controllers/challenge_controller.ex index f2028a15d..a5263e291 100644 --- a/lib/web/controllers/challenge_controller.ex +++ b/lib/web/controllers/challenge_controller.ex @@ -74,22 +74,30 @@ defmodule Web.ChallengeController do ) end + # create new challenge def new(conn, params) do %{current_user: user} = conn.assigns - show_info = Map.get(params, "show_info", false) - {:ok, wizard_info} = SiteContent.get("challenge_wizard_info") + if Challenges.is_allowed_to_view_submission?(user) do + show_info = Map.get(params, "show_info", false) + {:ok, wizard_info} = SiteContent.get("challenge_wizard_info") - render(conn, "wizard.html", - user: user, - changeset: Challenges.new(user), - path: Routes.challenge_path(conn, :create), - action: action_name(conn), - section: "general", - show_info: show_info, - wizard_info: wizard_info, - challenge: nil - ) + render(conn, "wizard.html", + user: user, + changeset: Challenges.new(user), + path: Routes.challenge_path(conn, :create), + action: action_name(conn), + section: "general", + show_info: show_info, + wizard_info: wizard_info, + challenge: nil + ) + else + conn + |> assign(:user, user) + |> put_flash(:error, "You are not allowed to create challenges") + |> redirect(to: Routes.challenge_path(conn, :index)) + end end def create( diff --git a/lib/web/templates/challenge/index.html.eex b/lib/web/templates/challenge/index.html.eex index cda039ecc..3ba2ba592 100644 --- a/lib/web/templates/challenge/index.html.eex +++ b/lib/web/templates/challenge/index.html.eex @@ -27,7 +27,9 @@
All Challenges
+ <%= if Challenges.is_allowed_to_view_submission?(@user) do %> <%= link "New", to: Routes.challenge_path(@conn, :new, show_info: true), class: "usa-button" %> + <% end %> Filter <%= if is_map(@filter) && map_size(@filter) > 0 do %> <%= link "Clear filters", to: Routes.challenge_path(@conn, :index), class: "usa-button usa-button--outline" %> diff --git a/lib/web/views/dashboard_view.ex b/lib/web/views/dashboard_view.ex index c9dd913a1..2573f110b 100644 --- a/lib/web/views/dashboard_view.ex +++ b/lib/web/views/dashboard_view.ex @@ -1,6 +1,7 @@ defmodule Web.DashboardView do use Web, :view + alias ChallengeGov.Challenges alias ChallengeGov.CertificationLogs alias ChallengeGov.Accounts alias ChallengeGov.MessageContextStatuses @@ -114,7 +115,7 @@ defmodule Web.DashboardView do admin_card_links() Accounts.is_challenge_manager?(user) -> - challenge_manager_card_links() + challenge_manager_card_links(user) Accounts.is_solver?(user) -> solver_card_links(user) @@ -201,7 +202,7 @@ defmodule Web.DashboardView do ] end - defp challenge_manager_card_links() do + defp challenge_manager_card_links(user) do [ content_tag :div, class: "grid-row" do [ @@ -212,13 +213,17 @@ defmodule Web.DashboardView do title: "Challenge management", description: "Manage and view all open and archived challenges." ), - render("_card_link.html", - to: Routes.challenge_path(Endpoint, :new), - target: "", - icon: my_icon("add"), - title: "Create a new challenge", - description: nil - ) + if Challenges.is_allowed_to_view_submission?(user) do + render("_card_link.html", + to: Routes.challenge_path(Endpoint, :new), + target: "", + icon: my_icon("add"), + title: "Create a new challenge", + description: nil + ) + else + "" + end ] end, content_tag :div, class: "grid-row" do