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

DDD links #2429

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions app/helpers/object_link_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def ascomycete_org_name_url(name)
"https://ascomycete.org/Search-Results?search=#{name.sensu_stricto}"
end

def ddd_url
"https://www.alpental.com/psms/ddd/index.htm"
end

def gbif_name_search_url(name)
# omit `group`, else there are no hits
# omit quotes around the name in order to get synonyms and cf's
Expand Down
5 changes: 5 additions & 0 deletions app/helpers/tabs/names_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ def google_images_for_name_tab(name)
{ class: tab_id(__method__.to_s), target: :_blank, rel: :noopener }]
end

def ddd_link_tab
[:show_observation_ddd.l, ddd_url,
{ class: tab_id(__method__.to_s), target: :_blank, rel: :noopener }]
end

def ascomycete_org_name_tab(name)
["Ascomycete.org", ascomycete_org_name_url(name),
{ class: tab_id(__method__.to_s), target: :_blank, rel: :noopener }]
Expand Down
18 changes: 12 additions & 6 deletions app/helpers/tabs/observations_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,22 @@ def observation_map_tab(mappable)
{ class: tab_id(__method__.to_s) }]
end

def name_links_web(name:)
tabs = create_links_to(observation_web_name_tabs(name),
def name_links_web(observation:)
tabs = create_links_to(observation_web_name_tabs(observation),
{ class: "d-block" })
tabs.reject(&:empty?)
end

def observation_web_name_tabs(name)
[mycoportal_name_tab(name),
mycobank_name_search_tab(name),
google_images_for_name_tab(name)]
def observation_web_name_tabs(observation)
tabs = [mycoportal_name_tab(observation.name),
mycobank_name_search_tab(observation.name),
google_images_for_name_tab(observation.name)]
tabs << ddd_link_tab if namings_pnw_provisional?(observation)
tabs
end

def namings_pnw_provisional?(observation)
observation.namings.any? { |naming| naming.name.pnw_provisional? }
end

def observation_hide_thumbnail_map_tab(obs)
Expand Down
4 changes: 4 additions & 0 deletions app/models/name/taxonomy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ def unsearchable_in_registry?
/\bcrypt temp\b/i =~ author&.delete(".")
end

def pnw_provisional?
text_name.match?(/".*pnw/i) || author.match(/pnw/i)
end

################

private
Expand Down
2 changes: 2 additions & 0 deletions app/views/controllers/names/show/_nomenclature.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ synonym_links = [approve, deprecate].reject(&:nil?).safe_join(" | ")
tag.p(link_to(*index_fungorum_name_search_tab(name))),
tag.p(link_to(*mycobank_basic_search_tab))
].safe_join
elsif name.pnw_provisional?
tag.p(link_to(:show_observation_ddd.l, ddd_url))
end
end)

Expand Down
2 changes: 1 addition & 1 deletion app/views/controllers/observations/show/_name_info.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ panel_block(
end %>
<%= tag.div(class: "col-xs-6") do
concat(tag.div("#{:on_the_web.l}:", class: "font-weight-bold"))
concat(name_links_web(name: obs.name).safe_join)
concat(name_links_web(observation: @observation).safe_join)
end %>
<% end %>

Expand Down
1 change: 1 addition & 0 deletions config/locales/en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2316,6 +2316,7 @@
show_observation_more_like_this: More like this
show_observation_look_alikes: Look-alikes
show_observation_related_taxa: Related taxa
show_observation_ddd: "DDD (PNW DNA-based taxa)"
map_observation_title: "Map of Observation #[ID]"

# observations/suggestions
Expand Down
25 changes: 25 additions & 0 deletions test/controllers/names_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,31 @@
assert_external_link("Ascomycete.org", ascomycete_org_name_url(name))
end

def test_show_name_pnw_cryptonym
name = Name.create(
user_id: rolf.id,
rank: "Species",
text_name: 'Hygrocybe "parvula-PNW01"',
search_name: "Hygrocybe \"parvula-PNW01\" S.D. Russell crypt. temp.",
display_name: '**__Hygrocybe "parvula-PNW01"__** S.D. Russell crypt. temp.',
sort_name: 'Hygrocybe "parvula-PNW01" S.D. Russell crypt. temp.',
citation: "",
deprecated: false,
synonym_id: nil,
correct_spelling_id: nil,
classification:
"Domain: _Eukarya_\r\nKingdom: _Fungi_\r\nPhylum: _Basidiomycota_\r\nClass: _Agaricomycetes_\r\nOrder: _Agaricales_\r\nFamily: _Hygrophoraceae_", # rubocop:disable Layout/LineLength
author: "S.D. Russell crypt. temp."
)

login
get(:show, params: { id: name.id })

assert_select("div#nomenclature a:match('href',?)",
%r{https://www.alpental.com/psms/ddd/index.htm}, true,

Check failure

Code scanning / CodeQL

Incomplete regular expression for hostnames High test

This regular expression has an unescaped '.' before 'alpental.com/psms/ddd/index', so it might match more hosts than expected.

Copilot Autofix AI 3 months ago

To fix the problem, we need to escape the . characters in the regular expression to ensure that they match literal dots rather than any character. This will make the regex more precise and prevent it from matching unintended URLs.

  • Locate the regular expression on line 648 in the file test/controllers/names_controller_test.rb.
  • Modify the regex to escape the . characters by replacing each . with \..
Suggested changeset 1
test/controllers/names_controller_test.rb

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/test/controllers/names_controller_test.rb b/test/controllers/names_controller_test.rb
--- a/test/controllers/names_controller_test.rb
+++ b/test/controllers/names_controller_test.rb
@@ -647,3 +647,3 @@
     assert_select("div#nomenclature a:match('href',?)",
-                  %r{https://www.alpental.com/psms/ddd/index.htm}, true,
+                  %r{https://www\.alpental\.com/psms/ddd/index\.htm}, true,
                   "Page is missing a link to PNW cryptonym page")
EOF
@@ -647,3 +647,3 @@
assert_select("div#nomenclature a:match('href',?)",
%r{https://www.alpental.com/psms/ddd/index.htm}, true,
%r{https://www\.alpental\.com/psms/ddd/index\.htm}, true,
"Page is missing a link to PNW cryptonym page")
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
"Page is missing a link to PNW cryptonym page")
end

def test_show_name_genus_with_icn_id
# Name's icn_id is filled in
name = names(:tubaria)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,33 @@
end
end

def test_observation_pnw_link_exists
obs = observations(:minimal_unknown_obs)
name = Name.create(
user_id: rolf.id,
rank: "Species",
text_name: 'Hygrocybe "parvula-PNW01"',
search_name: "Hygrocybe \"parvula-PNW01\" S.D. Russell crypt. temp.",
display_name: '**__Hygrocybe "parvula-PNW01"__** S.D. Russell crypt. temp.',
sort_name: 'Hygrocybe "parvula-PNW01" S.D. Russell crypt. temp.',
citation: "",
deprecated: false,
synonym_id: nil,
correct_spelling_id: nil,
classification:
"Domain: _Eukarya_\r\nKingdom: _Fungi_\r\nPhylum: _Basidiomycota_\r\nClass: _Agaricomycetes_\r\nOrder: _Agaricales_\r\nFamily: _Hygrophoraceae_", # rubocop:disable Layout/LineLength
author: "S.D. Russell crypt. temp."
)
Naming.create(observation: obs, name: name, vote_cache: 0, user: rolf)

login
get(:show, params: { id: obs.id })

assert_select("a:match('href',?)",
%r{https://www.alpental.com/psms/ddd/index.htm}, true,

Check failure

Code scanning / CodeQL

Incomplete regular expression for hostnames High test

This regular expression has an unescaped '.' before 'alpental.com/psms/ddd/index', so it might match more hosts than expected.

Copilot Autofix AI 3 months ago

To fix the problem, we need to escape the . characters in the regular expression to ensure they match literal dots rather than any character. This will make the regex more precise and prevent it from matching unintended URLs.

  • Update the regular expression on line 314 to escape the . characters.
  • No additional methods, imports, or definitions are needed.
Suggested changeset 1
test/controllers/observations_controller/observations_controller_show_test.rb

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/test/controllers/observations_controller/observations_controller_show_test.rb b/test/controllers/observations_controller/observations_controller_show_test.rb
--- a/test/controllers/observations_controller/observations_controller_show_test.rb
+++ b/test/controllers/observations_controller/observations_controller_show_test.rb
@@ -313,3 +313,3 @@
     assert_select("a:match('href',?)",
-                  %r{https://www.alpental.com/psms/ddd/index.htm}, true,
+                  %r{https://www\.alpental\.com/psms/ddd/index\.htm}, true,
                   "Page is missing a link to PNW cryptonym page")
EOF
@@ -313,3 +313,3 @@
assert_select("a:match('href',?)",
%r{https://www.alpental.com/psms/ddd/index.htm}, true,
%r{https://www\.alpental\.com/psms/ddd/index\.htm}, true,
"Page is missing a link to PNW cryptonym page")
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
"Page is missing a link to PNW cryptonym page")
end

def test_show_observation_edit_links
obs = observations(:detailed_unknown_obs)
proj = projects(:bolete_project)
Expand Down