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

[72] Non-gov access for Evaluators on Rails #440

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ def authorize_user(*roles)
redirect_to_landing_page(alert: I18n.t("access_denied"))
end

def check_gov_access
return unless current_user.non_gov_restricted?

redirect_to_landing_page(alert: I18n.t("access_denied"))
end

def redirect_admins_to_phoenix
return unless %w[super_admin admin].include?(current_user&.role)

Expand Down
1 change: 1 addition & 0 deletions app/controllers/submission_materials_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Controller for displaying submission materials to managers and evaluators.
class SubmissionMaterialsController < ApplicationController
before_action -> { authorize_user('challenge_manager', 'evaluator') }
before_action -> { check_gov_access }

def show
@submission = Submission.by_user(current_user).find(params[:id])
Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ def self.default_challenge_manager?(email)
/\.(gov|mil)$/.match?(email)
end

def non_gov_restricted?
!/\.(gov|mil)$/.match?(email)
end

def full_name(format: :default)
return email if first_name.blank? && last_name.blank?

Expand Down
16 changes: 10 additions & 6 deletions app/views/evaluations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
<h1>Submission ID <%= @submission.id %></h1>
<h2 class="font-body-sm text-normal">View submission materials and provide your scores to evaluate the submission.</h2>

<%= render partial: "layouts/hotdog", locals: {
name: 'Submission Materials',
left: 'evaluations/form',
right: 'submission_materials/right_panel',
additional_action: 'submission_materials/open_in_new_tab'
} %>
<% if @current_user.non_gov_restricted? %>
<%= render partial: "evaluations/form" %>
<% else %>
<%= render partial: "layouts/hotdog", locals: {
name: 'Submission Materials',
left: 'evaluations/form',
right: 'submission_materials/right_panel',
additional_action: 'submission_materials/open_in_new_tab'
} %>
<% end %>
5 changes: 4 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
<% if logged_in? %>
<%= render "layouts/utility_menu" %>
<% end %>
<%= render "shared/flash" %>

<section role="region" aria-label="Site notifications">
<%= render "shared/flash" %>
</section>

<main id="main-content" class="grid-container" tabindex="-1">
<%= yield %>
Expand Down
18 changes: 9 additions & 9 deletions app/views/submission_materials/_submission_materials.html.erb
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
<h3>Brief Description:</h3>
<h2>Brief Description:</h2>
<p class="text-normal"><%= @submission.brief_description %></p>

<h3>Description:</h3>
<h2>Description:</h2>
<p class="text-normal"><%= @submission.description %></p>

<h3>Uploaded Files:</h3>
<h2>Uploaded Files:</h2>
<% @submission&.documents.each do |document| %>
<p class="text-normal">
<%= link_to document.display_name, document.external_url, target: "_blank", download:true %>
</p>
<% end %>

<h3>External URL:</h3>
<h2>External URL:</h2>
<a href=<%= @submission.external_url %>><%= @submission.external_url %></a>

<h3>Status:</h3>
<h2>Status:</h2>
<p class="text-normal"><%= @submission.status.capitalize %></p>

<h3>Submitter:</h3>
<h2>Submitter:</h2>
<p class="text-normal"><%= @submission.submitter.email %></p>

<h3>Last Updated Date:</h3>
<h2>Last Updated Date:</h2>
<p class="text-normal"><%= @submission.updated_at %></p>

<h3>Submission ID:</h3>
<h2>Submission ID:</h2>
<p class="text-normal"><%= @submission.id %></p>

<h3>Title:</h3>
<h2>Title:</h2>
<p class="text-normal"><%= @submission.title %></p>
22 changes: 21 additions & 1 deletion spec/factories/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Fields
first_name { Faker::Name.first_name }
last_name { Faker::Name.last_name }
email { Faker::Internet.email }
email { generate_user_email }
phone_number { Faker::PhoneNumber.cell_phone }
token { SecureRandom.uuid }
role { User::ROLES.sample }
Expand Down Expand Up @@ -52,5 +52,25 @@
email_verified_at { Time.zone.now }
email_verification_token { nil }
end

trait :gov do
email { generate_user_email(type: :gov) }
end

trait :non_gov do
email { generate_user_email(type: :non_gov) }
end
end
end

def generate_user_email(type: :default)
case type
when :default
Faker::Internet.email
when :gov
domain = "example.#{%w[gov mil].sample}"
Faker::Internet.email(domain:)
when :non_gov
Faker::Internet.email(domain: "example.com")
end
end
12 changes: 12 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,16 @@
end
end
end

describe 'non_gov_restricted?' do
it 'returns true if non .gov/.mil email' do
user = create(:user, :non_gov)
expect(user).to be_non_gov_restricted
end

it 'returns false if .gov/.mil email' do
user = create(:user, :gov)
expect(user).not_to be_non_gov_restricted
end
end
end
43 changes: 43 additions & 0 deletions spec/requests/evaluation_overrides_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'rails_helper'

RSpec.describe "EvaluationOverrides" do
describe "GET /evaluations/:id/revision #show" do
context "as a challenge_manager" do
before do
create_and_log_in_user(role: "challenge_manager")
end

context "with an associated and complete evaluation" do
it "renders the blank override form" do
end
end

context "that has already revised the evaluation" do
it "renders the override form with data that was filled" do
end
end

context "trying to view a non-associated evaluation" do
it "redirects to the submission path with an alert" do
end
end

context "trying to view a non-complete evaluation" do
it "redirects to the submission path with an alert" do
end
end
end

context "as an evaluator" do
it "redirects to the dashboard path with an alert" do
end
end
end

describe "PATCH /evaluations/:id/revision #update" do
context "" do
it "" do
end
end
end
end
60 changes: 45 additions & 15 deletions spec/requests/submission_materials_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

expect(response).to have_http_status(:success)
expect(response.body).to have_css("h1", text: "Submission ID #{submission.id}")
expect(response.body).to have_css("h3", text: "Brief Description:")
expect(response.body).to have_css("h2", text: "Brief Description:")
end
end

Expand All @@ -50,23 +50,53 @@
create_and_log_in_user(role: "evaluator")
end

it "does not show submission when evaluator is not assigned" do
get materials_submission_path(submission)
expect(response).to have_http_status(:not_found)
context "with a gov email" do
before do
user.update(email: generate_user_email(type: :gov))
end

it "does not show submission when evaluator is not assigned" do
get materials_submission_path(submission)
expect(response).to have_http_status(:not_found)
end

it "renders the submission view when assigned" do
create(
:evaluator_submission_assignment,
submission: submission,
evaluator: user,
status: :assigned
)
get materials_submission_path(submission)

expect(response).to have_http_status(:success)
expect(response.body).to have_css("h1", text: "Submission ID #{submission.id}")
expect(response.body).to have_css("h2", text: "Brief Description:")
end
end

it "renders the submission view when assigned" do
create(
:evaluator_submission_assignment,
submission: submission,
evaluator: user,
status: :assigned
)
get materials_submission_path(submission)
context "with a non gov email" do
before do
user.update(email: generate_user_email(type: :non_gov))
end

expect(response).to have_http_status(:success)
expect(response.body).to have_css("h1", text: "Submission ID #{submission.id}")
expect(response.body).to have_css("h3", text: "Brief Description:")
it "does not show submission when evaluator is not assigned" do
get materials_submission_path(submission)

expect(response).to have_http_status(:redirect)
end

it "redirects away from submission view" do
create(
:evaluator_submission_assignment,
submission: submission,
evaluator: user,
status: :assigned
)
get materials_submission_path(submission)

expect(response).to have_http_status(:redirect)
end
end
end

Expand Down
Loading