Skip to content

Commit

Permalink
AO3-6529 Prevent work imports from AO3 (#4981)
Browse files Browse the repository at this point in the history
* AO3-6529 Prevent work imports from AO3

* AO3-6529 Shut up rubocop

* AO3-6529 Moved code to StoryParser
  • Loading branch information
Bilka2 authored Jan 22, 2025
1 parent 29fe145 commit c5aa49b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/models/story_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,8 @@ def download_with_timeout(location, limit = 10)
# we do a little cleanup here in case the user hasn't included the 'http://'
# or if they've used capital letters or an underscore in the hostname
uri = UrlFormatter.new(location).standardized
raise Error, I18n.t("story_parser.on_archive") if ArchiveConfig.PERMITTED_HOSTS.include?(uri.host)

response = Net::HTTP.get_response(uri)
case response
when Net::HTTPSuccess
Expand Down
3 changes: 2 additions & 1 deletion config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,8 @@ HIT_COUNT_ROLLOVER_HOUR: 3
# The batch size for calculating a work's filters from its tags:
FILTER_UPDATE_BATCH_SIZE: 100

# URLs for which we should not display the proxy notice. Alphabetical by
# URLs for which we should not display the proxy notice. URLs from these hosts
# are allowed in Abuse reports and disallowed in Work imports. Alphabetical by
# environment.
PERMITTED_HOSTS: [
# Production
Expand Down
2 changes: 2 additions & 0 deletions config/locales/models/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,7 @@ en:
closed_ticket: must not be closed.
invalid_department: must be in your department.
required: must exist and not be spam.
story_parser:
on_archive: URL is for a work on the Archive. Please bookmark it directly instead.
subscriptions:
deleted: Deleted item
9 changes: 9 additions & 0 deletions features/importing/work_import_errors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ Feature: Import Works
Then I should see "We couldn't successfully import that work, sorry: We couldn't download anything from http://no-content. Please make sure that the URL is correct and complete, and try again."
When I go to my works page
Then I should see "Drafts (0)"

Scenario: Cannot import works from the current archive
Given I set up importing
And I fill in "urls" with "https://archiveofourown.org/works/54711364"
And I select "English" from "Choose a language"
And I press "Import"
Then I should see "We couldn't successfully import that work, sorry: URL is for a work on the Archive. Please bookmark it directly instead."
When I go to my works page
Then I should see "Drafts (0)"

0 comments on commit c5aa49b

Please sign in to comment.