-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dependabot/bundler/puma-6.4.2
- Loading branch information
Showing
38 changed files
with
1,636 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
app/controllers/apps/president_vote_app/application_forms_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.