-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into bulk-eligibility-stat…
…us-change
- Loading branch information
Showing
43 changed files
with
841 additions
and
156 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Admin::ProtectedFilesController < Admin::BaseController | ||
include ProtectedFileMixin | ||
end |
101 changes: 101 additions & 0 deletions
101
app/controllers/admin/statistics/nominations_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,101 @@ | ||
class Admin::Statistics::NominationsController < Admin::BaseController | ||
def index | ||
authorize :statistics, :index? | ||
|
||
@search = NominationStatsSearch.new(FormAnswer.all).search(permitted_params) | ||
end | ||
|
||
def create | ||
authorize :statistics, :send? | ||
|
||
@search = NominationStatsSearch.new(FormAnswer.all).search(permitted_params) | ||
|
||
data = generate_csv(@search.results) | ||
file = current_admin.protected_files.create_from_raw_data(data, "nomination-statistics-export.csv") | ||
|
||
Admin::Statistics::NominationMailer.notify(current_admin.id, file.id).deliver_now | ||
|
||
redirect_to admin_statistics_nominations_path(search: permitted_params), success: "CSV with nomination statistics has been sent to #{current_admin.email}." | ||
end | ||
|
||
private | ||
|
||
def permitted_params | ||
params.fetch(:search, NominationStatsSearch.default_search).permit! | ||
end | ||
|
||
def generate_csv(data) | ||
CSV.generate(encoding: "UTF-8", force_quotes: true) do |csv| | ||
csv << csv_mapping.map { |m| m[:label] } | ||
data.each do |row| | ||
csv << csv_mapping.map do |m| | ||
func = m[:method] | ||
row[func] | ||
end | ||
end | ||
|
||
csv << csv_mapping.map do |m| | ||
func = m[:method] | ||
|
||
if func == :ceremonial_county_name | ||
"Total" | ||
else | ||
data.sum(&func) | ||
end | ||
end | ||
end | ||
end | ||
|
||
def csv_mapping | ||
[ | ||
{ | ||
label: "Lieutenancy", | ||
method: :ceremonial_county_name | ||
}, | ||
{ | ||
label: "Nominations submitted", | ||
method: :submitted_count | ||
}, | ||
{ | ||
label: "Eligiblity - Admin eligible", | ||
method: :admin_eligible_count | ||
}, | ||
{ | ||
label: "Eligiblity - Not eligible nominator", | ||
method: :admin_not_eligible_nominator_count | ||
}, | ||
{ | ||
label: "Eligiblity - Not eligible group", | ||
method: :admin_not_eligible_group_count | ||
}, | ||
{ | ||
label: "Eligiblity - Withdrawn", | ||
method: :withdrawn_count | ||
}, | ||
{ | ||
label: "Local Assessment - Not recommended", | ||
method: :local_assessment_not_recommended_count | ||
}, | ||
{ | ||
label: "Local Assessment - Recommended", | ||
method: :local_assessment_recommended_count | ||
}, | ||
{ | ||
label: "National Assessment - Not recommended", | ||
method: :not_recommended_count | ||
}, | ||
{ | ||
label: "National Assessment - Recommended", | ||
method: :shortlisted_count | ||
}, | ||
{ | ||
label: "Royal Approval - Awarded", | ||
method: :awarded_count | ||
}, | ||
{ | ||
label: "Total", | ||
method: :total_count | ||
} | ||
] | ||
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module ProtectedFileMixin | ||
extend ActiveSupport::Concern | ||
|
||
def self.included(base) | ||
base.skip_after_action :verify_authorized | ||
end | ||
|
||
def show | ||
file = current_subject.protected_files.find(params[:id]) | ||
file.mark_as_downloaded! | ||
redirect_to file.file.url, allow_other_host: true | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
app/controllers/form/support_letter_attachments_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,29 @@ | ||
class Form::SupportLetterAttachmentsController < Form::BaseController | ||
include FormAnswerSubmissionMixin | ||
before_action :set_support_letter | ||
|
||
def show; end | ||
|
||
def destroy | ||
attachment = SupportLetterAttachment.find(params[:id]) | ||
form_answer = attachment.form_answer | ||
|
||
if attachment.destroy | ||
updated_list = form_answer.document['supporter_letters_list'].reject { |letter| letter['letter_of_support'] == attachment.id } | ||
form_answer.update(document: form_answer.document.merge(supporter_letters_list: updated_list)) | ||
|
||
flash[:notice] = 'Attachment successfully deleted.' | ||
else | ||
flash[:alert] = 'Failed to delete attachment.' | ||
end | ||
|
||
redirect_to form_form_answer_supporters_path(form_answer) | ||
end | ||
|
||
private | ||
|
||
def set_support_letter | ||
@support_letter = SupportLetter.find(params[:support_letter_id]) | ||
@form_answer = @support_letter.form_answer | ||
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
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,12 @@ | ||
class Admin::Statistics::NominationMailer < ApplicationMailer | ||
layout "mailer" | ||
|
||
def notify(identifier, file_identifier) | ||
@admin = Admin.find(identifier) | ||
@file = @admin.protected_files.find(file_identifier) | ||
|
||
subject = "Nomination statistics export - King's Award for Voluntary Service" | ||
|
||
view_mail ENV["GOV_UK_NOTIFY_API_TEMPLATE_ID"], to: @admin.email, subject: subject_with_env_prefix(subject) | ||
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
Oops, something went wrong.