Skip to content

Commit

Permalink
Begin adding import all user's obs
Browse files Browse the repository at this point in the history
- Add checkbox to form
- Add appropriate translation strings
- Require user to (a) check import all, and/or (b) provide a list of obss
  • Loading branch information
JoeCohen committed Jul 25, 2024
1 parent 311af40 commit 34f6891
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 13 deletions.
12 changes: 11 additions & 1 deletion app/controllers/observations/inat_imports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]
Expand Down
14 changes: 11 additions & 3 deletions app/views/controllers/observations/inat_imports/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down
17 changes: 11 additions & 6 deletions config/locales/en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
8 changes: 5 additions & 3 deletions test/controllers/observations/inat_imports_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 }
Expand All @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions test/integration/capybara/inat_imports_integration_test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 34f6891

Please sign in to comment.