-
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.
Handle when ExcelAnalyzer detects issues
Hide spreadsheets and automatically send a report.
- Loading branch information
Showing
3 changed files
with
56 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
ExcelAnalyzer.on_hidden_metadata = ->(attachment_blob, metadata) do | ||
foi_attachment = FoiAttachment.joins(:file_blob). | ||
find_by(active_storage_blobs: { id: attachment_blob }) | ||
|
||
incoming_message = foi_attachment.incoming_message | ||
next if incoming_message.sent_at < 1.day.ago | ||
|
||
foi_attachment.update_and_log_event( | ||
prominence: 'hidden', | ||
event: { | ||
editor: User.internal_admin_user, | ||
reason: 'ExcelAnalyzer: hidden data dectected' | ||
} | ||
) | ||
|
||
ExcelAnalyzerNotifier.report(foi_attachment, metadata).deliver_now | ||
end | ||
|
||
Rails.configuration.to_prepare do | ||
class ExcelAnalyzerNotifier < ApplicationMailer | ||
include Rails.application.routes.url_helpers | ||
default_url_options[:host] = AlaveteliConfiguration.domain | ||
|
||
def report(foi_attachment, metadata) | ||
@foi_attachment = foi_attachment | ||
@metadata = metadata | ||
|
||
from = email_address_with_name( | ||
blackhole_email, 'WhatDoTheyKnow.com Execl Analyzer report' | ||
) | ||
|
||
headers['X-WDTK-Contact'] = 'wdtk-excel-anaylzer-report' | ||
headers['X-WDTK-CaseRef'] = @foi_attachment.id | ||
|
||
mail( | ||
from: from, | ||
to: pro_contact_from_name_and_email, | ||
subject: _('ExcelAnalyzer: hidden data dectected [{{reference}}]', | ||
reference: @foi_attachment.id) | ||
) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
ExcelAnalyzer has flagged and automatically set hidden prominence of a received | ||
spreadsheet due to the detection of potentially suspect hidden data. | ||
|
||
Admin URL: <%= edit_admin_foi_attachment_url(@foi_attachment) %> | ||
|
||
The following was detected: | ||
<% @metadata.each do |key, value| %> | ||
<%= key %>: <%= value %> | ||
<% end %> | ||
|
||
Please review the file carefully. |