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

AO3-6529 Prevent work imports from AO3 #4981

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,19 @@
render(:new_import) && return
end

@urls.each do |url|
uri = UrlFormatter.new(url).standardized
next unless ArchiveConfig.PERMITTED_HOSTS.include?(uri.host)

work_id = uri.path[%r{/works/(\d+)}, 1]
flash.now[:error] = if work_id
t(".on_archive", bookmark_it_link: view_context.link_to(t(".bookmark_it"), new_work_bookmark_path(work_id)))
else
t(".on_archive", bookmark_it_link: t(".bookmark_it"))
end
render(:new_import) and return

Check warning on line 489 in app/controllers/works_controller.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Non-local exit from iterator, without return value. `next`, `break`, `Array#find`, `Array#any?`, etc. is preferred. Raw Output: app/controllers/works_controller.rb:489:31: W: Lint/NonLocalExitFromIterator: Non-local exit from iterator, without return value. `next`, `break`, `Array#find`, `Array#any?`, etc. is preferred.
Bilka2 marked this conversation as resolved.
Show resolved Hide resolved
end

@language_id = params[:language_id]
if @language_id.empty?
flash.now[:error] = ts("Language cannot be blank.")
Expand Down
3 changes: 2 additions & 1 deletion config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,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
3 changes: 3 additions & 0 deletions config/locales/controllers/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ en:
works:
drafts:
page_title: "%{username} - Drafts"
import:
bookmark_it: bookmark it directly
on_archive: 'We couldn''t successfully import that work, sorry: URL is for a work on the Archive. Please %{bookmark_it_link} instead.'
wrangling_guidelines:
create: Wrangling Guideline was successfully created.
delete: Wrangling Guideline was successfully deleted.
Expand Down
15 changes: 15 additions & 0 deletions spec/controllers/works/importing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@
expect(flash[:error]).to eq "Did you want to enter a URL?"
end

context "when url is from this archive" do
it "is a work url" do
work_id = "1234"
params = { urls: "http://archiveofourown.org/works/#{work_id}" }
get :import, params: params
expect(flash[:error]).to eq "We couldn't successfully import that work, sorry: URL is for a work on the Archive. Please <a href=\"/works/#{work_id}/bookmarks/new\">bookmark it directly</a> instead."
end

it "is a different url" do
params = { urls: "http://archiveofourown.org/tags/search" }
get :import, params: params
expect(flash[:error]).to eq "We couldn't successfully import that work, sorry: URL is for a work on the Archive. Please bookmark it directly instead."
end
end

it "there is an external author name but importing_for_others is NOT turned on" do
params = {
urls: "url1, url2",
Expand Down
Loading