Skip to content
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

Accessibility Checker #1627

Merged
merged 36 commits into from
Oct 29, 2024
Merged

Accessibility Checker #1627

merged 36 commits into from
Oct 29, 2024

Conversation

ajkiessl
Copy link
Collaborator

@ajkiessl ajkiessl commented Oct 18, 2024

closes #1602

Module for pulling a file from S3, sending it up to Adobe through the AdobePdf API, accessibility checking, storing the accessibility report, and deleting the file in Adobe. There's some over lap with #1613 with storing the report, but it looks like the conflicts are minimal. I also threw a small accessibility fix in here to make the three required fields for culminating experiences required in the view.

I added an issue (#1638) to decouple the AdobePdf module from ScholarSphere. It's not a priority, but it might be helpful architecturally, and if we want to use this elsewhere. I also added an issue (#1637) to use setters for storing the report from Adobe. Again, not a priority, but it could help us keep track of changes Adobe makes to the report's structure.

resource.file_data['metadata']['size'] < FILE_SIZE_LIMIT
end

def fetch_accessibility_report
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method fetch_accessibility_report has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.

file_resource.file_data['metadata']['size'] < FILE_SIZE_LIMIT
end

def fetch_accessibility_report
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method fetch_accessibility_report has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

… model scope. Tests for this. Also, using .create! when storeing acccessibility check results so an error is raised if one already exists. The associated model should be deleted entirely if we want to try again.
@ajkiessl ajkiessl marked this pull request as ready for review October 25, 2024 18:41
@ajkiessl ajkiessl changed the title WIP: Accessibility Checker Accessibility Checker Oct 25, 2024
@ajkiessl ajkiessl changed the base branch from main to 1613-store-check-results October 25, 2024 19:36
@ajkiessl ajkiessl changed the base branch from 1613-store-check-results to main October 28, 2024 14:33
jlandiseigsti
jlandiseigsti previously approved these changes Oct 28, 2024
Copy link
Contributor

@jlandiseigsti jlandiseigsti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I have few potential refactors but didn't see anything that looked broken or hard to maintain. I would cast my notes as: optional.


def client_secret
if Rails.env.test?
'adobe_client_secret'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something to consider (probably down the line) – we could consider having distinct env files for different environments, so that this sort of logic wouldn't be in the code itself.
For example, direnv/direnv#320 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay. I didn't know you could do that with direnv. I wonder if there's a way to switch contexts depending on an ENV variable? From what I understand in that issue, you still need to manually switch contexts.

# my_asset = MyAsset.new(resource)
# my_asset.perform_operations
#
# @yield The block to run additional operations on the asset.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really helpful to include an example like this, thanks!


def asset_id
@asset_id ||= asset_upload_uri_and_asset_id['assetID']
end
Copy link
Contributor

@jlandiseigsti jlandiseigsti Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this and upload_uri potentially get set during initialize as well?

Copy link
Collaborator Author

@ajkiessl ajkiessl Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I wasn't sure what would be better. They both require similar amounts of code, and result in similar memoization. I think with the way I have it, the value won't be stored until it's needed, which probably makes the code infinitesimally more efficient.

AccessibilityCheckResult.create!(file_resource: resource,
detailed_report: {
error: 'Accessibility check failed: Polling time limit exceeded'
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed code climate's Complexity warning, but I'm not seeing a lot of obvious places to trim this method down. One very minor thing could be to pull lines 48-51 into some kind of createTimeoutResult method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this one might be hard to clean up.

'Passed manually' => 0,
'Skipped' => 0
}
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels brittle to me, as even slight changes to how Adobe formats their responses would require test rewirites. I'm not sure what the best alternative, but I'd be content know we got a result containing 'Detailed Report'.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The request is mocked with VCR/Webmock here spec/fixtures/vcr_cassettes/AdobePdf_AccessibilityChecker/_call/happy_path/fetches_the_accessibility_report.yml, so it won't break unless that is turned off. If we do turn that off and run a live test, it would be good to have it break so we can make changes. I added an issue to further handle the format and storing of the report here #1637 .

# frozen_string_literal: true

module AdobePdf
# TODO: This whole module can potentially be decoupled from scholarsphere.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm glad we have this on our todo list. Crossing fingers for reusability!

Smullz622
Smullz622 previously approved these changes Oct 29, 2024
Copy link
Contributor

@Smullz622 Smullz622 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Jesse's suggestions & think it looks great otherwise! Once this is merged, I'll make the adjustments needed for #1628

Copy link
Contributor

@jlandiseigsti jlandiseigsti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ajkiessl ajkiessl merged commit 9823811 into main Oct 29, 2024
1 check passed
@ajkiessl ajkiessl deleted the 1602-acc-check branch October 29, 2024 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automated Accessibility Checking
3 participants