Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1360] New user role: Evaluator #1392

Merged
merged 8 commits into from
Sep 12, 2024
Merged
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ yarn.lock
# Erlang build files
/otp-OTP-24.0.2/
/otp-OTP-24.1.2/

/.nix-hex/
/.nix-mix/
175 changes: 85 additions & 90 deletions assets/yarn.lock
stepchud marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions lib/challenge_gov/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,21 @@ defmodule ChallengeGov.Accounts do

def is_challenge_manager?(_), do: false

@doc """
Check if a user is an evaluator

iex> Accounts.is_evaluator?(%User{role: "evaluator"})
true

iex> Accounts.is_evaluator?(%User{role: "evaluator"})
false
"""
def is_evaluator?(user)

def is_evaluator?(%{role: "evaluator"}), do: true

def is_evaluator?(_), do: false

@doc """
Check if a user is a solver

Expand Down
3 changes: 2 additions & 1 deletion lib/challenge_gov/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ defmodule ChallengeGov.Accounts.User do
%{id: "super_admin", label: "Super Admin", rank: 1},
%{id: "admin", label: "Admin", rank: 2},
%{id: "challenge_manager", label: "Challenge Manager", rank: 3},
%{id: "solver", label: "Solver", rank: 4}
%{id: "evaluator", label: "Evaluator", rank: 4},
%{id: "solver", label: "Solver", rank: 5}
]

@doc """
Expand Down
4 changes: 4 additions & 0 deletions lib/web/templates/dashboard/index.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
<%= recertification_warning(@conn, @current_user)%>
<% end %>

<%= if Accounts.is_evaluator?(@current_user) do %>
<%= evaluator_notice() %>
<% end %>

<%= dashboard_card_links(@current_user) %>
</section>
11 changes: 11 additions & 0 deletions lib/web/templates/page/dev_accounts.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
<%= button("Decertified", to: Routes.dev_accounts_page_path(@conn, :dev_account_sign_in, email: "[email protected]"), method: :post, class: "usa-button") %>
</div>
<br/>
<div>
<h1>Evaluator Accounts</h1>
<%= button("Active (.gov)", to: Routes.dev_accounts_page_path(@conn, :dev_account_sign_in, email: "[email protected]"), method: :post, class: "usa-button") %>
<%= button("Active", to: Routes.dev_accounts_page_path(@conn, :dev_account_sign_in, email: "[email protected]"), method: :post, class: "usa-button") %>
<%= button("Pending", to: Routes.dev_accounts_page_path(@conn, :dev_account_sign_in, email: "[email protected]"), method: :post, class: "usa-button") %>
<%= button("Suspended", to: Routes.dev_accounts_page_path(@conn, :dev_account_sign_in, email: "[email protected]"), method: :post, class: "usa-button") %>
<%= button("Revoked", to: Routes.dev_accounts_page_path(@conn, :dev_account_sign_in, email: "[email protected]"), method: :post, class: "usa-button") %>
<%= button("Deactivated", to: Routes.dev_accounts_page_path(@conn, :dev_account_sign_in, email: "[email protected]"), method: :post, class: "usa-button") %>
<%= button("Decertified", to: Routes.dev_accounts_page_path(@conn, :dev_account_sign_in, email: "[email protected]"), method: :post, class: "usa-button") %>
</div>
<br/>
<div>
<h1>Solver Accounts</h1>
<%= button("Solver Active", to: Routes.dev_accounts_page_path(@conn, :dev_account_sign_in, email: "[email protected]"), method: :post, class: "usa-button") %>
Expand Down
10 changes: 10 additions & 0 deletions lib/web/views/dashboard_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ defmodule Web.DashboardView do
)
end

def evaluator_notice do
~E"""
<div class="content-header">
<div class="container-fluid">
<p>This account is an evaluator and has no access on this site. If this is a mistake contact an admin.</p>
</div>
</div>
"""
end

def dashboard_header(user) do
wrapper_classes = "grid-col padding-top-3 padding-left-2"

Expand Down
23 changes: 22 additions & 1 deletion priv/repo/seed_modules/accounts.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ defmodule Seeds.SeedModules.Accounts do
privacy_guidelines: terms_and_privacy_for_role("challenge_manager")
})

# Evaluators
create_role_of_status("evaluator", "active")
create_role_of_status("evaluator", "pending")
create_role_of_status("evaluator", "suspended")
create_role_of_status("evaluator", "revoked")
create_role_of_status("evaluator", "deactivated")
create_role_of_status("evaluator", "decertified")

# .gov Evaluators
Accounts.system_create(%{
token: Ecto.UUID.generate(),
role: "evaluator",
status: "active",
email: "[email protected]",
first_name: generate_name("evaluator"),
last_name: generate_name("active"),
last_active: last_active_for_role("evaluator"),
terms_of_use: terms_and_privacy_for_role("evaluator"),
privacy_guidelines: terms_and_privacy_for_role("evaluator")
})

# Solvers
create_role_of_status("solver", "active")
create_role_of_status("solver", "pending")
Expand Down Expand Up @@ -95,4 +116,4 @@ defmodule Seeds.SeedModules.Accounts do
end
end

Seeds.SeedModules.Accounts.run()
Seeds.SeedModules.Accounts.run()
25 changes: 24 additions & 1 deletion test/challenge_gov/accounts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -81,32 +81,44 @@ defmodule ChallengeGov.AccountsTest do
assert Accounts.get_role_rank("super_admin") === 1
assert Accounts.get_role_rank("admin") === 2
assert Accounts.get_role_rank("challenge_manager") === 3
assert Accounts.get_role_rank("solver") === 4
assert Accounts.get_role_rank("evaluator") === 4
assert Accounts.get_role_rank("solver") === 5
end

test "role at or above" do
user = %{role: "super_admin"}
assert Accounts.role_at_or_above(user, "super_admin")
assert Accounts.role_at_or_above(user, "admin")
assert Accounts.role_at_or_above(user, "challenge_manager")
assert Accounts.role_at_or_above(user, "evaluator")
assert Accounts.role_at_or_above(user, "solver")

user = %{role: "admin"}
assert !Accounts.role_at_or_above(user, "super_admin")
assert Accounts.role_at_or_above(user, "admin")
assert Accounts.role_at_or_above(user, "challenge_manager")
assert Accounts.role_at_or_above(user, "evaluator")
assert Accounts.role_at_or_above(user, "solver")

user = %{role: "challenge_manager"}
assert !Accounts.role_at_or_above(user, "super_admin")
assert !Accounts.role_at_or_above(user, "admin")
assert Accounts.role_at_or_above(user, "challenge_manager")
assert Accounts.role_at_or_above(user, "evaluator")
assert Accounts.role_at_or_above(user, "solver")

user = %{role: "evaluator"}
assert !Accounts.role_at_or_above(user, "super_admin")
assert !Accounts.role_at_or_above(user, "admin")
assert !Accounts.role_at_or_above(user, "challenge_manager")
assert Accounts.role_at_or_above(user, "evaluator")
assert Accounts.role_at_or_above(user, "solver")

user = %{role: "solver"}
assert !Accounts.role_at_or_above(user, "super_admin")
assert !Accounts.role_at_or_above(user, "admin")
assert !Accounts.role_at_or_above(user, "challenge_manager")
assert !Accounts.role_at_or_above(user, "evaluator")
assert Accounts.role_at_or_above(user, "solver")
end

Expand All @@ -115,24 +127,35 @@ defmodule ChallengeGov.AccountsTest do
assert Accounts.role_at_or_below(user, "super_admin")
assert !Accounts.role_at_or_below(user, "admin")
assert !Accounts.role_at_or_below(user, "challenge_manager")
assert !Accounts.role_at_or_below(user, "evaluator")
assert !Accounts.role_at_or_below(user, "solver")

user = %{role: "admin"}
assert Accounts.role_at_or_below(user, "super_admin")
assert Accounts.role_at_or_below(user, "admin")
assert !Accounts.role_at_or_below(user, "challenge_manager")
assert !Accounts.role_at_or_below(user, "evaluator")
assert !Accounts.role_at_or_below(user, "solver")

user = %{role: "challenge_manager"}
assert Accounts.role_at_or_below(user, "super_admin")
assert Accounts.role_at_or_below(user, "admin")
assert Accounts.role_at_or_below(user, "challenge_manager")
assert !Accounts.role_at_or_below(user, "evaluator")
assert !Accounts.role_at_or_below(user, "solver")

user = %{role: "evaluator"}
assert Accounts.role_at_or_below(user, "super_admin")
assert Accounts.role_at_or_below(user, "admin")
assert Accounts.role_at_or_below(user, "challenge_manager")
assert Accounts.role_at_or_below(user, "evaluator")
assert !Accounts.role_at_or_below(user, "solver")

user = %{role: "solver"}
assert Accounts.role_at_or_below(user, "super_admin")
assert Accounts.role_at_or_below(user, "admin")
assert Accounts.role_at_or_below(user, "challenge_manager")
assert Accounts.role_at_or_below(user, "evaluator")
assert Accounts.role_at_or_below(user, "solver")
end
end
Expand Down