Skip to content

Commit

Permalink
Merge branch 'staging' into 1427-DOM-text-code-scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
kkrug authored Sep 17, 2024
2 parents 423b192 + bc5d034 commit 59e6fad
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
32 changes: 20 additions & 12 deletions lib/web/controllers/challenge_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions lib/web/templates/challenge/index.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
<div class="grid-col-6">
<div class="font-ui-xl padding-1">All Challenges</div>
<div class="btn-group">
<%= if Challenges.is_allowed_to_view_submission?(@user) do %>
<%= link "New", to: Routes.challenge_path(@conn, :new, show_info: true), class: "usa-button" %>
<% end %>
<a class="usa-button" data-widget="control-sidebar" href="#">Filter</a>
<%= if is_map(@filter) && map_size(@filter) > 0 do %>
<%= link "Clear filters", to: Routes.challenge_path(@conn, :index), class: "usa-button usa-button--outline" %>
Expand Down
23 changes: 14 additions & 9 deletions lib/web/views/dashboard_view.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule Web.DashboardView do
use Web, :view

alias ChallengeGov.Challenges
alias ChallengeGov.CertificationLogs
alias ChallengeGov.Accounts
alias ChallengeGov.MessageContextStatuses
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
[
Expand All @@ -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
Expand Down

0 comments on commit 59e6fad

Please sign in to comment.