diff --git a/app/controllers/observations/inat_imports_controller.rb b/app/controllers/observations/inat_imports_controller.rb index bee33e6e00..da09ce961f 100644 --- a/app/controllers/observations/inat_imports_controller.rb +++ b/app/controllers/observations/inat_imports_controller.rb @@ -29,9 +29,9 @@ class InatImportsController < ApplicationController def new; end def create - return redirect_to(new_observation_path) if params[:inat_ids].blank? return username_required if params[:inat_username].blank? return reload_form if bad_inat_ids_param? + return designation_required unless imports_designated? return consent_required if params[:consent] == "0" inat_import = InatImport.find_or_create_by(user: User.current) @@ -52,6 +52,16 @@ def reload_form render(:new) end + def designation_required + flash_warning(:inat_no_imports_designated.t) + @inat_username = params[:inat_username] + render(:new) + end + + def imports_designated? + params[:all] == 1 || params[:inat_ids].present? + end + def consent_required flash_warning(:inat_consent_required.t) @inat_ids = params[:inat_ids] diff --git a/app/views/controllers/observations/inat_imports/new.html.erb b/app/views/controllers/observations/inat_imports/new.html.erb index e858de1e8a..511ec3fdf0 100644 --- a/app/views/controllers/observations/inat_imports/new.html.erb +++ b/app/views/controllers/observations/inat_imports/new.html.erb @@ -7,9 +7,17 @@ <%= f.label :inat_username, "#{:inat_username.l}: " %> <%= f.text_field(:inat_username, size: 10, value: @inat_username, class: "form-control") %> - <%= f.label :inat_id, "#{:inat_id_list.l}: " %> - <%= f.text_field(:inat_ids, size: 10, value: @inat_ids, - class: "form-control") %> + + <%= panel_block(id: "choose_observation", + heading: :inat_choose_observations.l, + class: "name-section") do %> + <%= f.label :inat_id, "#{:inat_import_list.l}: " %> + <%= f.text_field(:inat_ids, size: 10, value: @inat_ids, + class: "form-control") %> + <%= check_box_with_label(form: f, field: :all, + class: "mt-3", label: :inat_import_all.t) %> + <% end %> + <%= check_box_with_label(form: f, field: :consent, class: "mt-3", label: :inat_import_consent.t) %> <%= panel_block do %> diff --git a/config/locales/en.txt b/config/locales/en.txt index 4829751833..52f57df0bc 100644 --- a/config/locales/en.txt +++ b/config/locales/en.txt @@ -2983,18 +2983,23 @@ # observation/inat_imports create_inat_import_title: Import from iNat import_observation_from_inat: Import from iNat + inat_choose_observations: "Inat Observations to Import:" + inat_import_list: "Comma separated list of observation #s" + inat_import_all: Import all my iNat observations inat_import_consent: (Required) I consent to creating MushroomObserver Observation(s) based on my iNaturalist observations, including their photos. inat_consent_required: Your consent is required to import Inat observations. Please check the checkbox to give your consent. - inat_data_comment: iNat Data - inat_dqa_casual: Casual - inat_dqa_needs_id: Needs ID - inat_dqa_research: Research Grade - inat_id_list: "Comma separated list of iNat observation #s" - runtime_illegal_inat_id: iNat observation number can contain only numbers, commas, and spaces inat_username: Your iNat Username (mandatory) + runtime_illegal_inat_id: iNat observation number can contain only numbers, commas, and spaces inat_missing_username: Missing your iNat Username + inat_no_imports_designated: Imports missing. Complete [:inat_import_list], or select [:inat_import_all] + inat_no_authorization: iNat import aborted; MO did not received authorization to access iNat user data inat_taxon_not_importable: Cannot import iNat id `[id]`. (Can import only Fungi.) + + inat_data_comment: iNat Data + inat_dqa_casual: Casual + inat_dqa_needs_id: Needs ID + inat_dqa_research: Research Grade inat_details_heading: "Details/Caveats" inat_details_list: "- MO will list most iNat data and/or map it to analogous MO fields. \n - The MO Observation links to the iNat observation and vice versa. \n - MO Consensus ID is an analog of the iNat Community ID. \n - Coordinates are hidden from the public if iNat hid/obscured them. \n - Location is a rectangle with an MO-style name, rather than the iNat Place name. \n - iNat Projects are not included (iNat's API does not provide that data). \n" diff --git a/test/controllers/observations/inat_imports_controller_test.rb b/test/controllers/observations/inat_imports_controller_test.rb index c2957338b3..70c8af7229 100644 --- a/test/controllers/observations/inat_imports_controller_test.rb +++ b/test/controllers/observations/inat_imports_controller_test.rb @@ -32,11 +32,13 @@ def test_new_inat_import "Form needs a field for inputting iNat ids") assert_select("input#inat_username", true, "Form needs a field for inputting iNat username") + assert_select("input[type=checkbox][id=all]", true, + "Form needs checkbox for importing all a user's iNat obss") assert_select("input[type=checkbox][id=consent]", true, "Form needs checkbox requiring consent") end - def test_import_authorization_request + def test_create_authorization_request user = users(:rolf) inat_username = "rolf" inat_import = inat_imports(:rolf_inat_import) @@ -62,7 +64,7 @@ def test_import_authorization_request "Failed to save InatImport.inat_username") end - def test_import_missing_username + def test_create_missing_username user = users(:rolf) id = "123" params = { inat_ids: id } @@ -74,7 +76,7 @@ def test_import_missing_username assert_form_action(action: :create) end - def test_import_no_consent + def test_create_no_consent mock_search = File.read("test/inat/evernia.txt") inat_obs = InatObs.new( JSON.generate(JSON.parse(mock_search)["results"].first) diff --git a/test/integration/capybara/inat_imports_integration_test.rb b/test/integration/capybara/inat_imports_integration_test.rb new file mode 100644 index 0000000000..8e9560e1bf --- /dev/null +++ b/test/integration/capybara/inat_imports_integration_test.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require("test_helper") + +# Test things that are untestable in integration tests +class InatImportsTest < CapybaraIntegrationTestCase + def test_link_to_licenses + login(mary) + visit(new_observations_inat_import_path) + + fill_in("inat_username", with: "anything") + page.check("consent") + click_on("Submit") + + assert_flash_text(:inat_no_imports_designated.t) + assert_text(:create_inat_import_title.l) + end +end