Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.
Ruby agplai-assistantdockerdsgvogdprhotwireissue-trackerjira-alternativeknowledge-basellmmcp-servermeeting-notesopen-sourceproject-managementredmine-alternativeruby-on-railsself-hostedticketingtime-tracking
Close the gaps found in the first review of the additional details
Guido Boyked9fdfbc2c026
diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rbindex 8c7aac5..c6db6ee 100644--- a/app/helpers/people_helper.rb+++ b/app/helpers/people_helper.rb@@ -186,7 +186,7 @@ module PeopleHelper({ label: Person.human_attribute_name(:company), value: person.company } if person&.company.present?),({ label: Person.human_attribute_name(:email), value: email, href: "mailto:#{email}", icon: 'bi-envelope' } if email.present?),if phone.present?- { label: Person.human_attribute_name(:phone), value: phone, href: "tel:#{phone.gsub(/[^\d+]/, '')}",+ { label: Person.human_attribute_name(:phone), value: phone, href: PersonDetail.new('kind' => 'phone', 'value' => phone).href,icon: 'bi-telephone', mono: true, action: t('views.organisations.people.show.call') }end].compactdiff --git a/app/models/person_detail.rb b/app/models/person_detail.rbindex 34a2571..6b95063 100644--- a/app/models/person_detail.rb+++ b/app/models/person_detail.rb@@ -34,6 +34,7 @@ class PersonDetailINDEX_KEY = /\A\d{1,9}\z/ISO_DATE = /\A\d{4}-\d{2}-\d{2}\z/LINE_BREAK = /\r\n|\r|\n/+ NON_ASCII = /[^\x00-\x7F]/attr_reader :kind, :label, :value@@ -108,6 +109,10 @@ class PersonDetail# A stored entry, read without trusting it: written around the validation# (a console, update_column) it still renders, and nothing here raises.+ # The form cannot show such an entry faithfully (an unknown kind falls back+ # to the first option, a malformed date to an empty date field), so the next+ # save through the form may refuse or drop it. Only writes around the+ # validation can store one.def initialize(entry)entry = {} unless entry.is_a?(Hash)@kind = self.class.string_in(entry, 'kind')@@ -166,8 +171,12 @@ class PersonDetailendend+ # A web address may carry umlauts ("https://example.com/wiki/Köln", an+ # umlaut domain), which a browser accepts and URI.parse does not: they are+ # escaped for the check only, the stored value stays as written. Control+ # characters and spaces are ASCII and still refused.def http_url?- uri = URI.parse(value)+ uri = URI.parse(value.gsub(NON_ASCII) { |char| CGI.escape(char) })URL_SCHEMES.include?(uri.scheme.to_s.downcase) && uri.host.present?rescue URI::Errorfalsediff --git a/config/locales/views/personen.de.yml b/config/locales/views/personen.de.ymlindex 8becd39..f8fd9b6 100644--- a/config/locales/views/personen.de.yml+++ b/config/locales/views/personen.de.yml@@ -102,7 +102,7 @@ de:delete: "Löschen"delete_confirm: "%{name} wird aus der Liste gelöscht. Das lässt sich nicht rückgängig machen."remove_details: "Ergänzte Angaben entfernen"- remove_details_confirm: "Funktion, Abteilung, Telefon und Notiz von %{name} werden entfernt, das Konto bleibt. Das lässt sich nicht rückgängig machen."+ remove_details_confirm: "Alle ergänzten Angaben von %{name} werden entfernt (Anrede, Funktion, Abteilung, Telefon, Notiz und weitere Angaben), das Konto bleibt. Das lässt sich nicht rückgängig machen."details:kinds:phone: "Telefon"diff --git a/config/locales/views/personen.en.yml b/config/locales/views/personen.en.ymlindex 6778dfd..67c8a60 100644--- a/config/locales/views/personen.en.yml+++ b/config/locales/views/personen.en.yml@@ -102,7 +102,7 @@ en:delete: "Delete"delete_confirm: "%{name} will be deleted from the list. This cannot be undone."remove_details: "Remove added details"- remove_details_confirm: "Function, department, phone and note of %{name} will be removed, the account stays. This cannot be undone."+ remove_details_confirm: "All added details of %{name} will be removed (salutation, function, department, phone, note and additional details), the account stays. This cannot be undone."details:kinds:phone: "Phone"diff --git a/spec/helpers/people_helper_spec.rb b/spec/helpers/people_helper_spec.rbindex 6e51c4f..8c23717 100644--- a/spec/helpers/people_helper_spec.rb+++ b/spec/helpers/people_helper_spec.rb@@ -110,6 +110,21 @@ RSpec.describe PeopleHelper, type: :helper doexpect(field[:value]).to eq('javascript:alert(1)')end+ # Review round 1, finding 4: an entry written around the validation.+ it 'names an unknown kind as stored and gives it a plain text field in the form' do+ field = fields_for(detail('fax', '+49 30 1'), phone: nil).first++ expect(field).to eq(label: 'fax', value: '+49 30 1')+ expect(helper.person_detail_field('fax')).to eq(helper.person_detail_field('text'))+ expect(helper.person_detail_field('fax')[:input]).to eq('text')+ end++ # Review round 1, finding 8: the fixed phone links through the same rule.+ it 'links the fixed phone through PersonDetail, and not at all without digits' do+ expect(fields_for(phone: '+49 (30) 123-4567').first[:href]).to eq('tel:+49301234567')+ expect(fields_for(phone: 'nur Zentrale').first[:href]).to be_nil+ end+it 'shows no line for a person without details' doexpect(fields_for(phone: nil)).to eq([])enddiff --git a/spec/models/person_detail_spec.rb b/spec/models/person_detail_spec.rbindex aad533b..5552301 100644--- a/spec/models/person_detail_spec.rb+++ b/spec/models/person_detail_spec.rb@@ -124,6 +124,21 @@ RSpec.describe PersonDetail doendend+ # Review round 1, finding 6: a browser accepts umlauts in a web address,+ # URI.parse does not; they must not read as "no http(s)".+ it 'accepts umlauts in the path and in the host' do+ %w[https://example.com/wiki/Köln http://ä.example.com https://example.com/straße?q=ü].each do |value|+ expect(problems(detail(kind: 'url', value: value))).to eq([]), value+ expect(described_class.new(detail(kind: 'url', value: value)).href).to eq(value)+ end+ end++ it 'still refuses spaces and control characters next to an umlaut' do+ ['https://exa mple.com/Köln', "https://example.com/Köln\u0000", "java\tscript:alert('ö')"].each do |value|+ expect(problems(detail(kind: 'url', value: value))).to eq([[:invalid_url, { position: 1 }]]), value.inspect+ end+ end+it 'refuses every scheme but http and https, and a url without a host' do['javascript:alert(1)', 'JavaScript:alert(1)', 'data:text/html,<b>x</b>', 'ftp://example.com','mailto:[email protected]', 'https://', '//example.com', 'https://exa mple.com',diff --git a/spec/requests/organisations/people_spec.rb b/spec/requests/organisations/people_spec.rbindex 20d3fc5..0b14209 100644--- a/spec/requests/organisations/people_spec.rb+++ b/spec/requests/organisations/people_spec.rb@@ -393,6 +393,15 @@ RSpec.describe 'Organisations::People', :ci_guard, type: :request doexpect(tap.text).to include('+49 170 1234567', 'Mobil')end+ it 'opens a web address on a phone in a new tab without the opener' do+ person.update!(additional_details: [row('url', 'https://example.com', label: 'Website')])++ get organisation_people_path(organisation, person_id: person.id, viewport: 'mobile')++ tap = Nokogiri::HTML(response.body).at_css('a.people-tap[href="https://example.com"]')+ expect([tap['target'], tap['rel']]).to eq(['_blank', 'noopener noreferrer'])+ end+it 'shows no detail line for a person without details' dofields = lane_html.css('.people-fields__row dt').map { |dt| dt.text.strip }diff --git a/spec/services/actors/save_person_spec.rb b/spec/services/actors/save_person_spec.rbindex eb7df6e..3095f58 100644--- a/spec/services/actors/save_person_spec.rb+++ b/spec/services/actors/save_person_spec.rb@@ -268,6 +268,22 @@ RSpec.describe Actors::SavePerson doexpect(person.reload.additional_details.size).to eq(2)end+ # Review round 1, finding 1: the account owns name, email and link of a+ # member's row (ACCOUNT_FIELDS, LINK_FIELDS), never its details.+ [true, false].each do |active|+ it "changes the details of a saved row of a member (active: #{active})" do+ user = member+ stored = save(name: 'egal', user_id: user.id, additional_details: form(row)).resource+ expect(stored.additional_details).to eq([row])+ Membership.find_by(user: user, organisation: organisation).update!(active: active)++ result = save(additional_details: form(row(label: 'Mobil')), lock_version: stored.lock_version, id: stored.id)++ expect(result).to be_success+ expect(stored.reload.additional_details).to eq([row(label: 'Mobil')])+ end+ end+it 'takes details for the row of an active member' douser = memberresult = save(name: 'egal', user_id: user.id, additional_details: form(row))diff --git a/spec/system/people_additional_details_spec.rb b/spec/system/people_additional_details_spec.rbindex d8a8ea6..4c430b0 100644--- a/spec/system/people_additional_details_spec.rb+++ b/spec/system/people_additional_details_spec.rb@@ -39,7 +39,9 @@ RSpec.describe 'People additional details in the form', type: :system do# browser keeps painting the old page until its animations end).def screenshot(name)page.execute_script('document.getAnimations().forEach((animation) => animation.finish())')- page.driver.browser.save_screenshot(Rails.root.join("tmp/screenshots/#{name}.png").to_s)+ directory = Rails.root.join('tmp/screenshots')+ FileUtils.mkdir_p(directory)+ page.driver.browser.save_screenshot(directory.join("#{name}.png").to_s)enddef rows@@ -72,7 +74,7 @@ RSpec.describe 'People additional details in the form', type: :system doadd_button.clickwithin(rows[1]) dofind('select').select(kind_name('address'))- expect(page).to have_css('textarea[data-person-details-value]')+ expect(page).to have_css("textarea[data-person-details-value][maxlength='#{PersonDetail::MAX_ADDRESS_LENGTH}']")expect(page).to have_css('input[data-person-details-label][list="person-detail-suggestions-address"]')find('input[data-person-details-label]').fill_in(with: 'Büro')find('textarea[data-person-details-value]').fill_in(with: "Musterstraße 1\n12345 Berlin")@@ -80,8 +82,9 @@ RSpec.describe 'People additional details in the form', type: :system doadd_button.clickwithin(rows[2]) do+ find('select').select(kind_name('address'))find('select').select(kind_name('url'))- expect(page).to have_css('input[data-person-details-value][type="url"]')+ expect(page).to have_css("input[data-person-details-value][type='url'][maxlength='#{PersonDetail::MAX_VALUE_LENGTH}']")find('input[data-person-details-value]').fill_in(with: 'https://example.com')click_button remove_labelend@@ -100,6 +103,22 @@ RSpec.describe 'People additional details in the form', type: :system doexpect(person.reload.additional_details.pluck('label')).to eq(%w[Fax Büro])end+ # Review round 1, finding 2: a row added after a removal in the middle+ # needs an index no other row has, or the server merges two rows into one.+ it 'keeps every row when one in the middle was removed before adding' do+ person.update!(additional_details: %w[eins zwei drei].map { |value| { 'kind' => 'text', 'label' => '', 'value' => value } })+ open_form++ within(rows[0]) { click_button remove_label }+ expect(rows.size).to eq(2)+ add_button.click+ within(rows.last) { find('input[data-person-details-value]').fill_in(with: '+49 30 4') }+ click_button I18n.t('views.organisations.people.form.save')++ expect(page).to have_text(I18n.t('controllers.people.update.success'))+ expect(person.reload.additional_details.pluck('value')).to eq(['zwei', 'drei', '+49 30 4'])+ end+it 'hides the add button at ten with a note, and shows it again after a remove' doopen_formhint = I18n.t('views.organisations.people.form.details_limit', count: PersonDetail::MAX)