Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/bundler/puma-6.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuchal authored Apr 22, 2024
2 parents 437ef49 + e04fd05 commit aeb7b9d
Show file tree
Hide file tree
Showing 38 changed files with 1,636 additions and 35 deletions.
13 changes: 13 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@
margin-bottom: 0;
}

.light-button {
border: 2px solid #3a67e8;
color: #3a67e8;
background-color: inherit;
border-radius: 3px;
margin-bottom: 0;
}

.light-button:hover {
background-color: #3a67e8;
color: white;
}

.active-topic {
background-color: #F3F2F1;
padding: 20px 0;
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def disable_feedback
@disable_feedback = true
end

def disable_current_topic
@active_current_topic = nil
end

private

def set_default_metadata
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
class Apps::PresidentVoteApp::ApplicationFormsController < ApplicationController
helper FormatDaysHelper
before_action :set_metadata, :check_inactive_president_application, :disable_current_topic
before_action :disable_feedback, only: [:show, :delivery, :create]

def show
render_step('start')
end

def delivery
return render_self if request.post?
render_step('delivery')
end

def permanent_resident
return render_self if request.post?
render_step('permanent_resident')
end

def create
render_self
end

private def render_self
@application_form = Apps::PresidentVoteApp::ApplicationForm.new(form_params)
@application_form.run(self)
end

private def render_step(step)
@application_form = Apps::PresidentVoteApp::ApplicationForm.new(step: step)
render step
end

private def form_params
params.require(:apps_president_vote_app_application_form).permit(
:step,
:place_first_round,
:place_second_round,
:sk_citizen,
:delivery,
:full_name, :pin, :nationality, :maiden_name,
:authorized_person_full_name, :authorized_person_pin,
:street, :pobox, :municipality,
:same_delivery_address,
:delivery_street, :delivery_pobox, :delivery_municipality, :delivery_country,
:municipality_email,
:municipality_email_verified,
:permanent_resident,
:back
)
end

private def set_metadata
@metadata.og.title = 'Žiadosť o hlasovací preukaz'
@metadata.og.image = 'https://volby.digital/images/share-2024.png'
@metadata.og.description = 'Aj keď budete počas volieb mimo trvalého pobytu, voliť sa dá. Stačí požiadať.'
end

private def check_inactive_president_application
return if Apps::PresidentVoteApp::ApplicationForm.active?
return redirect_to apps_president_vote_app_application_forms_path if action_name != "show"
render 'inactive'
end
end
41 changes: 40 additions & 1 deletion app/controllers/health_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
class HealthController < ApplicationController

def index
head :ok
database_check_results = check_db_connections
if all_database_healthy?(database_check_results)
render json: {status: "ok"}, status: :ok
else
render json: {status: "fail"}, status: :internal_server_error
end
rescue StandardError
render json: {status: "fail"}, status: :internal_server_error
end

private
def all_database_healthy?(database_check_results)
database_check_results.values.all? { |status| status[:status] == "ok" }
end

def check_db_connections
db_status = {}
databases.each do |role, connection|
db_status[role] = perform_health_check(connection)
ensure
ActiveRecord::Base.clear_active_connections!
end
db_status
end

def databases
{
primary: ActiveRecord::Base.connected_to(role: :writing) { ApplicationRecord.connection },
datahub: ActiveRecord::Base.connected_to(role: :reading) { DatahubRecord.connection }
}
end

def perform_health_check(connection)
if connection
connection.execute('SELECT 1')
{status: 'ok'}
else
{status: 'fail'}
end
end
end
14 changes: 12 additions & 2 deletions app/helpers/format_days_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ def format_remaining_days(remaining_days)
"Dnes je posledný možný termín."
end
end
end


def format_remaining_days_count(remaining_days)
if remaining_days > 4
"#{remaining_days} dní"
elsif remaining_days > 1
"#{remaining_days} dni"
elsif remaining_days == 1
"1 deň"
elsif remaining_days == 0
"posledný deň"
end
end
end
43 changes: 40 additions & 3 deletions app/models/apps/parliament_vote_app/application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ApplicationForm
on: [:identity, :world_sk_permanent_resident, :world_abroad_permanent_resident, :authorized_person]
validates_presence_of :pin, message: 'Rodné číslo je povinná položka',
on: [:identity, :world_sk_permanent_resident, :world_abroad_permanent_resident, :authorized_person]
# validate :pin_is_ok, on: [:identity, :world_sk_permanent_resident, :world_abroad_permanent_resident, :authorized_person]
validates_presence_of :street, message: 'Zadajte ulicu alebo názov obce ak obec nemá ulice',
on: [:identity, :world_sk_permanent_resident, :authorized_person]
validates_presence_of :pobox, message: 'Zadajte poštové smerové čislo',
Expand Down Expand Up @@ -155,6 +156,33 @@ def world_sk_resident_email_body
)
end

private def pin_is_ok
return errors.add(:pin, 'Rodné číslo je pocinná položka') if pin.blank?

begin
pin.to_i
rescue ArgumentError
return errors.add(:pin, 'Rodné číslo obsahuje neplatné znaky')
end

pin = self.pin.gsub(%r{/}, '')
return errors.add(:pin, 'Rodné číslo nie je deliteľné číslom 11') if pin.length == 10 and pin.to_i % 11 != 0
return errors.add(:pin, 'Rodné číslo má nesprávnu dĺžku') if pin.length != 10 and pin.length != 9

case pin[2..3].to_i
when 0, 13..50, 63..99
return errors.add(:pin, 'Rodné číslo obsahuje neplatný mesiac')
end

month = pin[2..3].to_i % 50
year = pin[0..1].to_i + (pin[2..3].to_i > 12 ? 1900 : 2000)
begin
Date.new(year, month, pin[4..5].to_i)
rescue ArgumentError
errors.add(:pin, 'Rodné číslo obsahuje neplatný dátum')
end
end

def run(listener)
case step
when 'start'
Expand Down Expand Up @@ -192,7 +220,10 @@ def run(listener)
end

private def sk_citizen_step(listener)
if valid?(:sk_citizen)
if go_back?
self.step = 'start'
listener.render :start
elsif valid?(:sk_citizen)
case sk_citizen
when 'yes'
self.step = 'permanent_resident'
Expand All @@ -206,7 +237,10 @@ def run(listener)
end

private def permanent_resident_step(listener)
if valid?(:permanent_resident)
if go_back?
self.step = 'sk_citizen'
listener.render :sk_citizen
elsif valid?(:permanent_resident)
case permanent_resident
when 'yes'
self.step = 'place'
Expand Down Expand Up @@ -241,7 +275,10 @@ def run(listener)

# Home flow
private def delivery_step(listener)
if valid?(:delivery)
if go_back?
self.step = 'place'
listener.render :place
elsif valid?(:delivery)
case delivery
when 'post'
self.step = 'identity'
Expand Down
Loading

0 comments on commit aeb7b9d

Please sign in to comment.