Skip to content

Commit

Permalink
New wiki source page for names
Browse files Browse the repository at this point in the history
  • Loading branch information
lmrodriguezr committed Jul 28, 2024
1 parent e3466e1 commit 1e922df
Show file tree
Hide file tree
Showing 12 changed files with 334 additions and 105 deletions.
37 changes: 28 additions & 9 deletions app/controllers/names_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class NamesController < ApplicationController
before_action(
:set_name,
only: %i[
show edit update destroy network
show edit update destroy network wiki
proposed_in not_validly_proposed_in emended_in assigned_in
corrigendum_in corrigendum_orphan corrigendum
edit_description edit_rank edit_notes edit_etymology edit_links edit_type
Expand All @@ -15,10 +15,10 @@ class NamesController < ApplicationController
before_action(
:authenticate_can_edit!,
only: %i[
edit update destroy
edit destroy
proposed_in not_validly_proposed_in emended_in assigned_in
corrigendum_in corrigendum_orphan corrigendum
edit_description edit_rank edit_notes edit_etymology edit_links edit_type
edit_description edit_rank edit_notes edit_etymology edit_type
autofill_etymology edit_parent
]
)
Expand All @@ -35,6 +35,7 @@ class NamesController < ApplicationController
]
)
before_action(:authenticate_user!, only: %i[observe unobserve observing])
before_action(:authenticate_can_edit_validated!, only: %i[update edit_links])

# GET /names/autocomplete.json?q=Maco
# GET /names/autocomplete.json?q=Allo&rank=genus
Expand Down Expand Up @@ -223,6 +224,11 @@ def network
end
end

# GET /names/1/wiki
def wiki
@crumbs = [['Names', names_path], [@name.name_html, @name], 'Wiki source']
end

# GET /names/new
def new
@name = Name.new
Expand Down Expand Up @@ -505,29 +511,42 @@ def set_tutorial
def authenticate_owner_or_curator!
unless current_user.try(:curator?) || @name.user?(current_user)
flash[:alert] = 'User is not the owner of the name'
redirect_to(root_path)
redirect_to(@name)
end
end

def authenticate_can_edit_validated!
unless @name.can_edit_validated?(current_user)
flash[:alert] = 'User cannot edit this aspect of the name'
redirect_to(@name)
end
end

def authenticate_can_edit!
unless @name.can_edit?(current_user)
flash[:alert] = 'User cannot edit name'
redirect_to(root_path)
redirect_to(@name)
end
end

# Never trust parameters from the scary internet, only allow the white list
# through
def name_params
@name_params ||=
params.require(:name)
.permit(
:name, :rank, :description, :notes, :ncbi_taxonomy, :lpsn_url,
:gtdb_accession, :algaebase_species, :algaebase_taxonomy,
@name.can_edit?(current_user) ?
params.require(:name).permit(
:name, :rank, :description, :notes,
:ncbi_taxonomy, :lpsn_url, :gtdb_accession,
:algaebase_species, :algaebase_taxonomy,
:syllabication, :syllabication_reviewed,
:type_material, :type_accession, :etymology_text, :register,
:genome_strain,
*etymology_pars
) :
params.require(:name).permit(
:notes,
:ncbi_taxonomy, :lpsn_url, :gtdb_accession,
:algaebase_species, :algaebase_taxonomy
)
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/placements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def set_name
end

def authenticate_can_edit!
unless @name.can_edit_placements?(current_user)
unless @name.can_edit_validated?(current_user)
flash[:alert] = 'User cannot edit name placements'
redirect_to(@name)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/pseudonyms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def set_name
end

def authenticate_can_edit!
unless @name&.can_edit_placements?(current_user)
unless @name&.can_edit_validated?(current_user)
flash[:alert] = 'User cannot edit pseudonyms'
redirect_to(root_path)
end
Expand Down
90 changes: 88 additions & 2 deletions app/models/name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,48 @@ def rank_suffixes
{ phylum: 'ota', class: 'ia', order: 'ales', family: 'aceae' }
end

def rank_variant(rank, opts = {})
list =
if opts[:abbr]
{
domain: 'dom.', kingdom: 'regn.', phylum: 'phy.',
class: 'classis', order: 'ord.', family: 'fam.',
genus: 'gen.', species: 'sp.', subspecies: 'subsp.'
}
elsif opts[:latin]
if opts[:plural]
{
domain: 'dominia', kingdom: 'regna', phylum: 'phyla',
class: 'classis', order: 'ordines', family: 'familiae',
genus: 'genera', species: 'species', subspecies: 'subspecies'
}
else
{
domain: 'dominium', kingdom: 'regnum', phylum: 'phylum',
class: 'classes', order: 'ordo', family: 'familia',
genus: 'genus', species: 'species', subspecies: 'subspecies'
}
end
else
if opts[:plural]
{
domain: 'domains', kingdom: 'kingdoms', phylum: 'phyla',
class: 'classes', order: 'orders', family: 'family',
genus: 'genera', species: 'species', subspecies: 'subspecies'
}
else
{
domain: 'domain', kingdom: 'kingdom', phylum: 'phylum',
class: 'class', order: 'order', family: 'families',
genus: 'genus', species: 'species', subspecies: 'subspecies'
}
end
end
return list unless rank.present?
var = list[rank.to_s.downcase.to_sym]
opts[:title] ? var.titleize : var
end

def rank_regexps
Hash[rank_suffixes.map { |k, v| [k, /#{v}$/] }]
end
Expand Down Expand Up @@ -454,6 +496,13 @@ def name_html(name = nil, assume_valid = false)
end
end

def name_wiki(opts = {})
y = base_name
y = "[[#{y}]]" if opts[:link]
y = "''Candidatus'' #{y}" if !opts[:no_candidatus] && candidatus?
validated? ? "''#{y}''" : "\"#{y}\""
end

def abbr_corr_name
abbr_name(corrigendum_from)
end
Expand All @@ -469,7 +518,7 @@ def formal_html
if not_validly_proposed_in.any?
y += ' (ex'
y += not_validly_proposed_in
.map { |i| " #{sanitize(i.short_citation)}" }.join(';')
.map { |i| " #{sanitize(i.short_citation)}" }.join('; ')
y += ')'
end
if authority || proposed_in
Expand All @@ -489,6 +538,26 @@ def formal_txt
sanitize(formal_html.gsub(/&#822[01];/, "'"))
end

def formal_wiki
y = name_wiki
y += ' corrig.' if corrigendum_from?
if not_validly_proposed_in.any?
y += ' (ex'
y += not_validly_proposed_in
.map { |i| " #{sanitize(i.short_citation(:wikispecies))}" }
.join('; ')
y += ')'
end
if authority || proposed_in
y += " #{sanitize(authority || proposed_in.short_citation(:wikispecies))}"
end
if emended_in.any?
cit = emended_in.map { |p| p.short_citation(:wikispecies) }.join('; ')
y += " emend. #{cit}"
end
sanitize(y)
end

def display(html = true)
html ? name_html : name
end
Expand Down Expand Up @@ -586,6 +655,15 @@ def algaebase_url
nil
end

def edit_wikispecies_page_link
'https://species.wikimedia.org/w/index.php?title=%s&action=edit' % base_name
end

def edit_wikispecies_template_link
'https://species.wikimedia.org/w/index.php?title=Template:%s&action=edit'
% base_name
end

def ncbi_taxonomy_url
return unless ncbi_taxonomy?

Expand Down Expand Up @@ -663,7 +741,7 @@ def can_edit?(user)
false
end

def can_edit_placements?(user)
def can_edit_validated?(user)
can_edit?(user) || user.try(:curator?)
end

Expand Down Expand Up @@ -967,6 +1045,14 @@ def lineage_find(rank)
lineage.find { |par| par.rank == rank.to_s }
end

def rank_above
self.class.ranks[self.class.ranks.index(inferred_rank) - 1]
end

def rank_below
self.class.ranks[self.class.ranks.index(inferred_rank) + 1]
end

def propose_lineage_name(rank)
return name if rank.to_s == inferred_rank
return if above_rank?(rank)
Expand Down
25 changes: 14 additions & 11 deletions app/models/publication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,22 @@ def query_crossref(query)

end

def authors_et_al
def authors_et_al(format = :text)
family = authors.pluck(:family) # To reduce SQL requests
if family.empty?
'Anonymous'
elsif family.count < 3
family.join(', ')
else
family.first + ' et al.'
end
family.map! { |a| "{{a|#{a}}}" } if format == :wikispecies
y =
if family.empty?
'Anonymous'
elsif family.count < 3
family.join(', ')
else
family.first + ' et al.'
end
format == :html ? ERB::Util.h(y) : y
end

def authors_et_al_html
ERB::Util.h(authors_et_al)
authors_et_al(:html)
end

def clean_abstract
Expand All @@ -195,8 +198,8 @@ def clean_abstract
end
end

def short_citation
"#{authors_et_al}, #{journal_date.year}"
def short_citation(format = :text)
"#{authors_et_al(format)}, #{journal_date.year}"
end

def citation
Expand Down
Loading

0 comments on commit 1e922df

Please sign in to comment.