Skip to content

Commit

Permalink
Merge branch 'dev' into dependabot/bundler/dev/jwt-2.9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
stepchud authored Oct 17, 2024
2 parents 9e93cad + 3a0e362 commit 4213f9c
Show file tree
Hide file tree
Showing 35 changed files with 314 additions and 117 deletions.
4 changes: 3 additions & 1 deletion .env_login
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export LOGOUT_REDIRECT_EVAL_URL=http://localhost:3000/

export PHOENIX_URI="http://localhost:4000"
export LOGIN_SECRET="f4d3c40a00a8e6ed72fae5204d9ddacd40f087865d40803a6fcfb935591a271838533f06081067dac24c0085c74123e7e1c8b3e0ab562c6645b17eb769854d0d"
export JWT_SECRET="fc28c5738ca45162f61126e770a8fbdbd938d0fedcfe8fbb9f851b855b0264866364a9130e96aca8b1977e9f58edf064f1aa435ceccf415ff22fd3c24adba320"
export JWT_SECRET="fc28c5738ca45162f61126e770a8fbdbd938d0fedcfe8fbb9f851b855b0264866364a9130e96aca8b1977e9f58edf064f1aa435ceccf415ff22fd3c24adba320"

export APP_DOMAIN="localhost"
7 changes: 6 additions & 1 deletion app/assets/stylesheets/application.sass.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
/* Backdrop is only displayed when dialog is opened with dialog.showModal() */
dialog::backdrop {
background: rgba(0, 0, 0, 0.5);
}
}

.usa-radio__input:checked + .usa-radio__label::before {
background-color: black;
border-color: black;
}
10 changes: 6 additions & 4 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,16 @@ def extract_phoenix_cookie_from_response(res)
def phoenix_session_cookie(phoenix_cookie)
cookies[:_challenge_gov_key] = {
value: phoenix_cookie[:value],
secure: true,
httponly: true,
same_site: :lax
domain: Rails.configuration.app_domain,
same_site: :lax,
secure: Rails.env.production?,
httponly: true
}
end
# :nocov:

def delete_phoenix_session_cookie
cookies.delete(:_challenge_gov_key)
cookies.delete(:_challenge_gov_key, domain: Rails.configuration.app_domain,
secure: Rails.env.production?)
end
end
20 changes: 17 additions & 3 deletions app/controllers/evaluation_forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def create
respond_to do |format|
if @evaluation_form.save
format.html do
redirect_to evaluation_form_url(@evaluation_form), notice: I18n.t("evaluation_form_saved")
redirect_to evaluation_forms_url, notice: I18n.t("evaluation_form_saved")
end
format.json { render :show, status: :created, location: @evaluation_form }
else
Expand Down Expand Up @@ -74,7 +74,21 @@ def set_evaluation_forms

# Only allow a list of trusted parameters through.
def evaluation_form_params
params.require(:evaluation_form).permit(:title, :instructions, :challenge_phase, :status, :comments_required,
:weighted_scoring, :publication_date, :closing_date, :challenge_id)
permitted = params.require(:evaluation_form).
permit(:title, :instructions, :phase_id, :status, :comments_required,
:weighted_scoring, :publication_date, :closing_date, :challenge_id)
closing_date = parse_closing_date(permitted[:closing_date])
closing_date ? permitted.merge({ closing_date: }) : permitted
end

def parse_closing_date(input_date)
case input_date
when %r{\A\d\d?/\d\d?/\d\d\d\d\z} # mm/dd/yyyy, also accepts single digit month/day
(month, day, year) = input_date.split("/")
# nicely formatted iso8601 with 2 digit day and month
"#{year}-#{month.rjust(2, '0')}-#{day.rjust(2, '0')}"
else
input_date
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class SessionsController < ApplicationController
before_action :check_error_result, :require_code_param, :exchange_token, only: [:result]
skip_before_action :check_session_expiration, only: [:timeout]
skip_before_action :check_session_expiration, only: [:timeout, :destroy]

SESSION_TIMEOUT_IN_MINUTES = 15

Expand Down
17 changes: 9 additions & 8 deletions app/helpers/evaluation_forms_helper.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# frozen_string_literal: true

module EvaluationFormsHelper
def status_colors
{
draft: "FireBrick",
ready: "DarkGoldenRod",
published: "green"
}
def challenge_with_phase(evaluation_form)
challenge_phase_title(evaluation_form.challenge, evaluation_form.phase)
end

def challenge_with_phase(evaluation_form)
"#{evaluation_form.challenge.title} - Phase #{evaluation_form.challenge_phase}"
def challenge_phase_title(challenge, phase)
"#{challenge.title} - Phase #{phase_number(phase)}"
end

def inline_error(evaluation_form, field)
error = evaluation_form.errors[field].present? ? evaluation_form.errors[field].first : ""
tag.span(error, class: "text-secondary font-body-2xs", id: "evaluation_form_#{field}_error")
end
end
4 changes: 0 additions & 4 deletions app/helpers/evaluations_helper.rb

This file was deleted.

7 changes: 7 additions & 0 deletions app/helpers/phases_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module PhasesHelper
def phase_number(phase)
phase.challenge.phase_ids.index(phase.id) + 1
end
end
1 change: 1 addition & 0 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./controllers"
9 changes: 9 additions & 0 deletions app/javascript/controllers/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Application } from "@hotwired/stimulus"

const application = Application.start()

// Configure Stimulus development experience
application.debug = false
window.Stimulus = application

export { application }
44 changes: 44 additions & 0 deletions app/javascript/controllers/evaluation_form_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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}`)

this.updateErrorMessage("evaluation_form_challenge_id", "")
this.updateErrorMessage("evaluation_form_phase_id", "")
} else {
this.updateErrorMessage("evaluation_form_challenge_id", "can't be blank")
this.startDateTarget.innerHTML = "mm/dd/yyyy"
}
}

validatePresence(e) {
if (!e.target.value) {
e.target.classList.add("border-secondary")
this.updateErrorMessage(e.target.id, "can't be blank")

} else {
e.target.classList.remove("border-secondary")
this.updateErrorMessage(e.target.id, "")
}
}

updateErrorMessage(field, message) {
document.getElementById(field + "_error").innerHTML = message
}
}
9 changes: 9 additions & 0 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This file is auto-generated by ./bin/rails stimulus:manifest:update
// Run that command whenever you add a new controller or create them with
// ./bin/rails generate stimulus controllerName

import { application } from "./application"

import EvaluationFormController from "./evaluation_form_controller"
application.register("evaluation-form", EvaluationFormController)

3 changes: 1 addition & 2 deletions app/models/challenge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,13 @@ class Challenge < ApplicationRecord
has_many :federal_partners, dependent: :delete_all
has_many :federal_partner_agencies, through: :federal_partners, source: :agency
has_many :non_federal_partners, dependent: :delete_all
has_many :phases, dependent: :destroy
has_many :phases, -> { order(:start_date) }, inverse_of: :challenge, dependent: :destroy
has_many :submissions, dependent: :destroy
has_many :submission_exports, dependent: :destroy

# JSON fields
attribute :types, :jsonb
attribute :timeline_events, :jsonb
attribute :phases, :jsonb

attribute :status, :string, default: "draft"
attribute :prize_total, :integer, default: 0
Expand Down
9 changes: 4 additions & 5 deletions app/models/evaluation_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# id :bigint not null, primary key
# title :string
# instructions :string
# challenge_phase :integer
# phase_id :integer
# comments_required :boolean default(FALSE)
# weighted_scoring :boolean default(FALSE)
# closing_date :date
Expand All @@ -17,16 +17,15 @@
#
class EvaluationForm < ApplicationRecord
belongs_to :challenge
has_many :evaluation_criteria, dependent: :destroy
belongs_to :phase
has_many :evaluation_criteria, dependent: :destroy, class_name: "EvaluationCriterion"

scope :by_user, lambda { |user|
joins(challenge: :challenge_manager_users).
where(challenge_manager_users: { id: user.id })
}

validates :title, presence: true
validates :title, presence: true, length: { maximum: 150 }
validates :instructions, presence: true
validates :closing_date, presence: true
validates :challenge_phase, presence: true
validates :challenge_phase, uniqueness: { scope: :challenge_id }
end
2 changes: 1 addition & 1 deletion app/models/phase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Phase < ApplicationRecord
attribute :open_to_submissions, :boolean
attribute :judging_criteria, :text
attribute :how_to_enter, :text
attribute :challenge_id, :uuid
attribute :challenge_uuid, :uuid

# Virtual fields
attribute :judging_criteria_length, :integer, default: 0
Expand Down
4 changes: 2 additions & 2 deletions app/views/evaluation_forms/_evaluation_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</p>

<p>
<strong>Challenge phase:</strong>
<%= evaluation_form.challenge_phase %>
<strong>Phase ID:</strong>
<%= evaluation_form.phase_id %>
</p>

<p>
Expand Down
2 changes: 1 addition & 1 deletion app/views/evaluation_forms/_evaluation_form.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

json.extract!(evaluation_form, :id, :title, :instructions, :challenge_phase, :status, :comments_required,
json.extract!(evaluation_form, :id, :title, :instructions, :phase_id, :status, :comments_required,
:weighted_scoring, :publication_date, :closing_date, :challenge_id, :created_at, :updated_at)
json.url(evaluation_form_url(evaluation_form, format: :json))
Loading

0 comments on commit 4213f9c

Please sign in to comment.