Skip to content

Commit

Permalink
Merge branch 'dev' into 41_add_SMTP_configuration_for_notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
stepchud authored Feb 21, 2025
2 parents 0ab3803 + 7082050 commit 59d861e
Show file tree
Hide file tree
Showing 40 changed files with 353 additions and 575 deletions.
21 changes: 13 additions & 8 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def logged_in?
def authorize_user(*roles)
return if roles.include?(current_user&.role) || %w[super_admin admin].include?(current_user&.role)

redirect_to dashboard_path, alert: I18n.t("access_denied")
redirect_to_landing_page(alert: I18n.t("access_denied"))
end

def redirect_admins_to_phoenix
Expand All @@ -44,6 +44,17 @@ def redirect_solvers_to_phoenix
redirect_to Rails.configuration.phx_interop[:phx_uri], allow_other_host: true
end

def redirect_to_landing_page(options = {})
case @current_user&.role
when "evaluator"
redirect_to evaluations_path, options
when "challenge_manager"
redirect_to phases_path, options
else
redirect_to "/", options
end
end

def sign_in(login_userinfo)
user = User.user_from_userinfo(login_userinfo)

Expand Down Expand Up @@ -73,18 +84,12 @@ def check_session_expiration

if session[:session_timeout_at].blank? || session[:session_timeout_at] < Time.current
sign_out
redirect_to dashboard_path, alert: I18n.t("session_expired_alert")
redirect_to "/", alert: I18n.t("session_expired_alert")
else
renew_session
end
end

def redirect_if_logged_in(path = "/dashboard")
return unless logged_in?

redirect_to path, notice: I18n.t("already_logged_in_notice")
end

def generate_user_jwt(user)
payload = {
email: user.email,
Expand Down
6 changes: 0 additions & 6 deletions app/controllers/dashboard_controller.rb

This file was deleted.

3 changes: 2 additions & 1 deletion app/controllers/dev/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def login
@current_user = User.find_by(email:)
renew_session
session[:userinfo] = [{ "email" => email, "sub" => @current_user.token }]
redirect_to dashboard_path

redirect_to_landing_page
end
end
end
47 changes: 13 additions & 34 deletions app/controllers/evaluation_forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ class EvaluationFormsController < ApplicationController
helper FormHelper

before_action -> { authorize_user('challenge_manager') }
before_action :set_phase
before_action :set_evaluation_form, only: %i[show edit update destroy]
before_action :set_evaluation_forms, only: %i[index]
before_action :set_available_phases, only: %i[new create edit update]

# GET /evaluation_forms or /evaluation_forms.json
def index; end

# GET /evaluation_forms/1 or /evaluation_forms/1.json
def show; end
Expand All @@ -27,16 +23,14 @@ def edit; end
def create
@evaluation_form = EvaluationForm.new(evaluation_form_params)

respond_to do |format|
if @evaluation_form.save
format.html do
redirect_to confirmation_evaluation_form_path(@evaluation_form), notice: I18n.t("evaluation_form_saved")
end
format.json { render :show, status: :created, location: @evaluation_form }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @evaluation_form.errors, status: :unprocessable_entity }
end
if @evaluation_form.save
redirect_to confirmation_phase_evaluation_form_path(
@evaluation_form.phase,
@evaluation_form
),
notice: I18n.t("evaluation_form_saved")
else
render :new, status: :unprocessable_entity, phase: @evaluation_form.phase
end
end

Expand All @@ -45,7 +39,8 @@ def update
respond_to do |format|
if @evaluation_form.update(evaluation_form_params)
format.html do
redirect_to confirmation_evaluation_form_path(@evaluation_form), notice: I18n.t("evaluation_form_saved")
redirect_to confirmation_phase_evaluation_form_path(@evaluation_form.phase, @evaluation_form),
notice: I18n.t("evaluation_form_saved")
end
format.json { render :show, status: :ok, location: @evaluation_form }
else
Expand Down Expand Up @@ -77,24 +72,8 @@ def set_evaluation_form
find(params[:id])
end

def set_evaluation_forms
@evaluation_forms = EvaluationForm.
by_user(current_user).
includes([:challenge, :phase])
end

def set_available_phases
current_phase_id = @evaluation_form&.phase_id

@available_phases =
current_user.challenge_manager_challenges.includes(:phases).map do |challenge|
{
challenge:,
phases: challenge.phases.reject do |phase|
current_phase_id != phase.id && EvaluationForm.exists?(phase_id: phase.id)
end
}
end
def set_phase
@phase = Phase.find(params[:phase_id])
end

# Only allow a list of trusted parameters through.
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def index
path = "#{BASE_URL}/#{params[:path]}/"
reverse_proxy(HOST, path:, reset_accept_encoding: true, headers: { host: DOMAIN }) do |config|
config.on_missing do |_code, _response|
redirect_to "/dashboard"
redirect_to "/"
return true
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/phases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class PhasesController < ApplicationController
before_action :set_phase, except: [:index]

def index
@challenges = current_user.challenge_manager_challenges.includes([phases: [:evaluation_form]])
@challenges = current_user.challenge_manager_challenges.includes([phases: [:evaluation_form, :evaluators]])
end

def submissions
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def destroy

def result
sign_in(@login_userinfo)
redirect_to dashboard_path
redirect_to_landing_page
end

def renew
Expand Down
39 changes: 0 additions & 39 deletions app/helpers/dashboard_helper.rb

This file was deleted.

12 changes: 12 additions & 0 deletions app/helpers/phases_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,16 @@ def phase_number(challenge, phase)
def phase_has_recused_evaluator?(phase)
phase.evaluator_submission_assignments.recused.exists?
end

def statuses
{
draft: "Draft",
gsa_review: "GSA review",
approved: "Approved",
edits_requested: "Edits requested",
unpublished: "Unpublished",
published: "Published",
archived: "Archived"
}
end
end
26 changes: 0 additions & 26 deletions app/javascript/controllers/evaluation_form_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,6 @@ import { Controller } from "@hotwired/stimulus";

// Connects to data-controller="evaluation-form"
export default class extends Controller {
static targets = ["challengeID", "phaseID", "startDate", "datePicker"];

handleChallengeSelect(e) {
let id, phase_id, end_date;
[id, phase_id, end_date] = e.target.value.split(".");
if (id) {
// set values of hidden form fields
this.challengeIDTarget.value = id;
this.phaseIDTarget.value = phase_id;

// set the start date of the evaluation form
// to be the challenge's end date
this.startDateTarget.innerHTML = end_date || "mm/dd/yyyy";
let day, month, year;
[month, day, year] = end_date.split("/");
this.datePickerTarget.setAttribute(
"data-min-date",
`${year}-${month}-${day}`
);
} else {
this.challengeIDTarget.value = null;
this.phaseIDTarget.value = null;

this.startDateTarget.innerHTML = "mm/dd/yyyy";
}
}

// Opens all accordions, remove existing points/weights, update max points/weights values
updateMaxPoints(e) {
Expand Down
15 changes: 15 additions & 0 deletions app/models/phase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,19 @@ class Phase < ApplicationRecord

# Validations
validates :title, :start_date, :end_date, presence: true

def evaluation_status
eligible_for_evaluation_exists = submissions.eligible_for_evaluation.exists?
in_progress_or_completed_exists = submissions.eligible_for_evaluation.exists?(evaluation_status: [:in_progress,
:completed])
in_progress_exists = submissions.eligible_for_evaluation.exists?(evaluation_status: :in_progress)
if !eligible_for_evaluation_exists || !in_progress_or_completed_exists
# no submissions are eligible for evaluation, or if they do they are all currently not_started
:not_started
elsif !in_progress_exists
:completed
else
:in_progress
end
end
end
9 changes: 0 additions & 9 deletions app/views/dashboard/_dashboard.html.erb

This file was deleted.

15 changes: 0 additions & 15 deletions app/views/dashboard/_dashboard_card.html.erb

This file was deleted.

7 changes: 0 additions & 7 deletions app/views/dashboard/index.html.erb

This file was deleted.

36 changes: 6 additions & 30 deletions app/views/evaluation_forms/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_with(model: evaluation_form, data: { controller: "evaluation-form modal form-validation" }) do |form| %>
<%= form_with(url: url, model: evaluation_form, data: { controller: "evaluation-form modal form-validation" }) do |form| %>
<% if evaluation_form.errors.any? %>
<div style="color: darkred">
<div class="usa-alert usa-alert--error" role="alert">
Expand Down Expand Up @@ -43,32 +43,8 @@
<%= inline_error(form, :title) %>
</div>

<div class="usa-form-group">
<div class="display-flex flex-align-center text-bold">
<%= form.label :phase, "Select a Challenge", class: "margin-right-05 #{label_error_class(form, :phase)}", for: "challenge-combo" %>
<span class="margin-right-05" style="color: darkred;">*</span>
</div>
<div class="usa-hint">Choose the challenge this form will evaluate.</div>

<div class="usa-combo-box" data-default-value="<%= combo_box_default_value %>">
<%= select_tag(
'challenge-combo',
options_for_select(options_for_available_phases(@available_phases)),
class: "usa-select #{input_error_class(form, :phase)}",
title: 'challenge-combo',
data: {
action: "evaluation-form#handleChallengeSelect form-validation#validatePresence focusout->form-validation#validatePresence",
field_name: "evaluation_form_phase"
},
disabled: disabled
) %>
</div>

<%= inline_error(form, :phase) %>

<%= form.hidden_field :phase_id, {data: { "evaluation-form-target": 'phaseID'}} %>
<%= form.hidden_field :challenge_id, {data: { "evaluation-form-target": 'challengeID'}} %>
</div>
<%= form.hidden_field :phase_id, value: @phase.id %>
<%= form.hidden_field :challenge_id, value: @phase.challenge.id %>

<div class="usa-form-group">
<div class="usa-character-count">
Expand Down Expand Up @@ -192,7 +168,7 @@
</p>

<div class="usa-label text-bold font-sans-sm">Evaluation Start Date:</div>
<div class="usa-hint" data-evaluation-form-target="startDate">mm/dd/yyyy</div>
<div class="usa-hint"><%= @phase.end_date.strftime('%m/%d/%Y') %></div>

<div class="usa-form-group">
<div class="display-flex flex-align-center text-bold">
Expand All @@ -201,7 +177,7 @@
</div>
<div class="usa-hint" id="evaluation_form_closing_date_hint">mm/dd/yyyy</div>

<div data-evaluation-form-target="datePicker" class="usa-date-picker" data-default-value="<%= evaluation_form.closing_date %>" data-min-date="<%= if evaluation_form.challenge then evaluation_form.challenge.end_date end %>">
<div data-evaluation-form-target="datePicker" class="usa-date-picker" data-default-value="<%= evaluation_form.closing_date %>" data-min-date="<%= @phase.end_date %>">
<input
class="usa-input <%= input_error_class(form, :closing_date) %>"
id="evaluation_form_closing_date"
Expand Down Expand Up @@ -237,7 +213,7 @@
description: "Your evaluation form will not be saved and any entered information will be lost.",
confirm_text: "Yes",
cancel_text: "Close",
confirm_redirect: evaluation_forms_path
confirm_redirect: phases_path
%>

<%= render "modals/confirmation",
Expand Down
4 changes: 2 additions & 2 deletions app/views/evaluation_forms/_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<% @evaluation_forms.each do |evaluation_form| %>
<tr>
<th data-label="Form Title" scope="row">
<%= link_to edit_evaluation_form_path(evaluation_form) do %>
<%= link_to edit_phase_evaluation_form_path(evaluation_form.phase, evaluation_form) do %>
<%= evaluation_form.title %>
<% end %>
</th>
Expand All @@ -28,7 +28,7 @@

<td>
<div class="display-flex flex-wrap grid-row grid-gap-1">
<%= button_to edit_evaluation_form_path(evaluation_form), method: :get, class: "usa-button width-full", form: {class: "grid-col-12"} do %>
<%= button_to edit_phase_evaluation_form_path(evaluation_form.phase, evaluation_form), method: :get, class: "usa-button width-full", form: {class: "grid-col-12"} do %>
<%= image_tag(
"images/usa-icons/edit.svg",
class: "usa-icon icon-white",
Expand Down
Loading

0 comments on commit 59d861e

Please sign in to comment.