-
Notifications
You must be signed in to change notification settings - Fork 8
Asap 215 document audit export #284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
3a4f3be
Stashing initial work on background job.
lkacenja e7dc0e6
Merge branch 'dev' into asap-215-document-audit-export
lkacenja a93849a
Merge branch 'dev' into asap-215-document-audit-export
lkacenja 73c5979
Stash progress on exporting.
lkacenja c911b5b
Mostly function audit export page.
lkacenja 7d0c808
Clean up and make localstack erros more obvious. Move secret names to…
lkacenja fdd69bb
Remove secret name constants.
lkacenja 4623062
Use actual bucket name.
lkacenja e25fc76
Move S3 permissions to the correct role.
lkacenja 2d9e0d4
Allow backend to handle errors.
lkacenja 07faab6
Refactor and simplify API.
lkacenja 3aad551
Add swagger UI to the app.
lkacenja 58974a9
Fix API paths and example.
lkacenja 9dabed3
Handle errors more gracefully.
lkacenja f92d1ed
Use staging bucket name (default).
lkacenja d548be5
Improve access and responses as revealed by testing.
lkacenja 6d446d4
Refactor tests for new endpoints.
lkacenja 2ae72bc
Merge branch 'dev' into asap-215-document-audit-export
lkacenja 3e0e59d
Fix up linting issues.
lkacenja 4d15e99
Remove future fields from factory.
lkacenja 10af338
Fix tests by matching new routes and using required fields.
lkacenja 8ee3313
Add a light test for exports.
lkacenja b19f830
Merge branch 'dev' into asap-215-document-audit-export
lkacenja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -4,10 +4,10 @@ class DocumentsController < AuthenticatedController | |
|
|
||
| protect_from_forgery with: :exception | ||
| skip_before_action :verify_authenticity_token, only: [:update_document_category, :update_accessibility_recommendation, :update_notes, :update_summary_inference, :update_recommendation_inference] | ||
| before_action :set_site, only: [:index, :modal_content, :batch_update] | ||
| before_action :set_document, except: [:index, :batch_update] | ||
| before_action :ensure_user_site_access, only: [:index, :modal_content, :batch_update] | ||
| before_action :ensure_user_document_access, except: [:index, :modal_content, :batch_update] | ||
| before_action :set_site, only: [:index, :insights, :audit_exports, :modal_content, :batch_update] | ||
| before_action :set_document, except: [:index, :insights, :audit_exports, :batch_update] | ||
| before_action :ensure_user_site_access, only: [:index, :insights, :audit_exports, :modal_content, :batch_update] | ||
| before_action :ensure_user_document_access, except: [:index, :insights, :audit_exports, :modal_content, :batch_update] | ||
|
|
||
| def modal_content | ||
| render partial: "modal_content", locals: {document: @document} | ||
|
|
@@ -29,6 +29,110 @@ def index | |
| @filters_for_sorts = query_params [:sort, :direction, :page] | ||
| end | ||
|
|
||
| def insights | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved the insights (dashboard) endpoint here to documents, because it nests under documents in the URL and views directory. I thought this would make more sense. |
||
| # Build document list. | ||
| @documents = @site.documents | ||
| .by_category(params[:category]) | ||
| .by_department(params[:department]) | ||
| # Create binned date data for visualization. | ||
| # First, gather all documents by year | ||
| year_groups = @documents.group_by(&:modification_year).map { |label, year_documents| [label, year_documents.size] } | ||
| # Extract and remove "Unknown" to handle separately | ||
| unknown_group = year_groups.find { |item| item[0] == "Unknown" } | ||
| year_groups = year_groups.reject { |item| item[0] == "Unknown" } | ||
| year_groups = year_groups.select do |item| | ||
| Integer(item[0]) | ||
| true | ||
| rescue | ||
| if unknown_group.nil? | ||
| unknown_group = ["Unknown", 0] | ||
| end | ||
| unknown_group[1] += 1 | ||
| false | ||
| end | ||
| # Convert to integers for sorting and calculations | ||
| year_groups = year_groups.map { |year, count| [Integer(year), count] } | ||
| # Create bins based on specific year ranges | ||
| binned_data = [] | ||
| bins = [ | ||
| ["< 2000", -Float::INFINITY..1999], | ||
| ["2000-2005", 2000..2005], | ||
| ["2006-2011", 2006..2011], | ||
| ["2012-2017", 2012..2017], | ||
| ["2018-2023", 2018..2023], | ||
| ["> 2023", 2024..Float::INFINITY] | ||
| ] | ||
| bins.each do |label, range| | ||
| count = year_groups.filter_map { |year, count| count if range.cover?(year) }.sum | ||
| binned_data << [label, count] | ||
| end | ||
| # Add the "Unknown" group if it exists (placing it at the end) | ||
| binned_data << unknown_group if unknown_group | ||
| @document_years = binned_data | ||
| # Create table data. | ||
| default_group = Document::DECISION_TYPES.keys.map { |status| [status, 0] }.to_h | ||
| @category_groups = {} | ||
| @documents.group([:document_category, :accessibility_recommendation]).count.each do |groups, group_count| | ||
| @category_groups[groups[0]] = default_group.clone if @category_groups[groups[0]].nil? | ||
| if Document::DECISION_TYPES.keys.exclude? groups[1] | ||
| parent = Document::DECISION_TYPES.keys.find do |key| | ||
| if Document::DECISION_TYPES[key]["children"].present? && Document::DECISION_TYPES[key]["children"].key?(groups[1]) | ||
| key | ||
| end | ||
| end | ||
| if parent.present? | ||
| groups[1] = parent | ||
| end | ||
| end | ||
| @category_groups[groups[0]][groups[1]] += group_count | ||
| end | ||
| @category_groups.each do |key, child_hash| | ||
| sum = child_hash.values.sum | ||
| child_hash["Total"] = sum | ||
| end | ||
| @category_groups = @category_groups.sort.to_h | ||
| # Work on document links. | ||
| @document_links = { | ||
| complexity: [ | ||
| {title: Document::SIMPLE_STATUS, params: query_params.merge({complexity: Document::SIMPLE_STATUS})}, | ||
| {title: Document::COMPLEX_STATUS, params: query_params.merge({complexity: Document::COMPLEX_STATUS})} | ||
| ], | ||
| years: bins.map do |label, range| | ||
| document_count = @document_years.find { |item| item[0] == label } | ||
| if document_count[1] == 0 | ||
| next | ||
| end | ||
| start_date = (range.begin == -Float::INFINITY) ? nil : "#{range.begin}-01-01" | ||
| end_date = (range.end == Float::INFINITY) ? nil : "#{range.end}-12-31" | ||
| { | ||
| title: label, | ||
| params: query_params.merge( | ||
| start_date: start_date, | ||
| end_date: end_date | ||
| ).compact | ||
| } | ||
| end.compact, | ||
| decision: @documents.pluck(:accessibility_recommendation).uniq.map do |decision| | ||
| { | ||
| title: decision, | ||
| params: query_params.merge( | ||
| accessibility_recommendation: decision | ||
| ) | ||
| } | ||
| end | ||
| } | ||
| end | ||
|
|
||
| def audit_exports | ||
| @export_links = [] | ||
| @error_message = nil | ||
| begin | ||
| @export_links = @site.get_document_audit_link_hashes! | ||
| rescue => e | ||
| @error_message = e.message | ||
| end | ||
| end | ||
|
|
||
| def serve_document_url | ||
| response = HTTParty.get(@document.normalized_url) | ||
| if response.success? | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR introduces a move to storing more items in Rails config. These secret names are now in config/environments/development.