Skip to content

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.

Add a free text salutation to people in the directory

Guido Boykeff2167c0d804
diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rb
index e450bea..4e46479 100644
--- a/app/helpers/people_helper.rb
+++ b/app/helpers/people_helper.rb
@@ -101,7 +101,7 @@ module PeopleHelper
# A member row with none of the details the directory is for yet.
def person_bare?(person)
- person.nil? || %i[function department phone notes].all? { |field| person.public_send(field).blank? }
+ person.nil? || %i[salutation function department phone notes].all? { |field| person.public_send(field).blank? }
end
# The lines of the lane: label, value, and for email and phone the link. An
@@ -110,6 +110,7 @@ module PeopleHelper
email = member ? member.email : person&.email
phone = person&.phone
[
+ ({ label: Person.human_attribute_name(:salutation), value: person.salutation } if person&.salutation.present?),
({ label: Person.human_attribute_name(:function), value: person.function } if person&.function.present?),
({ label: Person.human_attribute_name(:department), value: person.department } if person&.department.present?),
({ label: Person.human_attribute_name(:company), value: person.company } if person&.company.present?),
diff --git a/app/models/person.rb b/app/models/person.rb
index edb921c..5c1473e 100644
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -9,6 +9,8 @@
# name is always filled, also for a linked row (copied at link time by
# Actors::SavePerson), so removing the membership loses nothing
# (PersonLinkRelease). Tracking keeps no personal data (PersonTrackable).
+# salutation is free text ("Herr", "Frau Dr."): often only "Frau Müller" is
+# known, without a first name. Blank means none given and is stored as nil.
# lock_version: both sides edit the same row; a stale save raises
# ActiveRecord::StaleObjectError.
class Person < ApplicationRecord
@@ -26,7 +28,7 @@ class Person < ApplicationRecord
MAX_NOTES_LENGTH = 10_000
MAX_FIELD_LENGTH = 255
- TEXT_FIELDS = %i[name function department company email phone].freeze
+ TEXT_FIELDS = %i[name salutation function department company email phone].freeze
before_validation :normalize_name_fields
@@ -51,6 +53,7 @@ class Person < ApplicationRecord
def normalize_name_fields
self.name = name.to_s.strip.gsub(/\s+/, ' ') if name
self.normalized_name = PersonName.normalize(name)
+ self.salutation = salutation.to_s.squish.presence
end
# Same rule as Actors::SaveMeeting for participants: only an active member of
diff --git a/app/services/actors/save_person.rb b/app/services/actors/save_person.rb
index f89464c..2975e49 100644
--- a/app/services/actors/save_person.rb
+++ b/app/services/actors/save_person.rb
@@ -17,7 +17,7 @@
# Tracking is PersonTrackable's: no personal data, no fanout.
module Actors
class SavePerson < BaseActor
- ATTRIBUTES = %i[name function department company email phone notes lock_version].freeze
+ ATTRIBUTES = %i[name salutation function department company email phone notes lock_version].freeze
# lock_version is an integer column (4 bytes).
LOCK_VERSION_RANGE = (0..((2**31) - 1))
diff --git a/app/services/user_data_exports/registry.rb b/app/services/user_data_exports/registry.rb
index 52aec8a..9a435ad 100644
--- a/app/services/user_data_exports/registry.rb
+++ b/app/services/user_data_exports/registry.rb
@@ -221,7 +221,7 @@ module UserDataExports
# content (as analysis_prompts); unlinked rows are data about third
# parties, whose requests go through the organisation as controller.
source(key: :people, model: 'Person', tenant_scoped: true,
- attributes: %w[name function department company email phone notes created_at updated_at],
+ attributes: %w[name salutation function department company email phone notes created_at updated_at],
scope: ->(user) { Person.where(user_id: user.id) }),
source(key: :notification_subscriptions, model: 'NotificationSubscription', tenant_scoped: true,
attributes: %w[subscribable_type source created_at],
diff --git a/app/views/organisations/people/_form.html.erb b/app/views/organisations/people/_form.html.erb
index 4ab287b..29e39a4 100644
--- a/app/views/organisations/people/_form.html.erb
+++ b/app/views/organisations/people/_form.html.erb
@@ -37,6 +37,12 @@
<%= f.hidden_field :user_id %>
<% end %>
+ <div class="people-form__field">
+ <%= f.label :salutation %>
+ <%= f.text_field :salutation, class: 'people-input', maxlength: Person::MAX_FIELD_LENGTH,
+ placeholder: t('views.organisations.people.form.placeholders.salutation') %>
+ </div>
+
<div class="people-form__field">
<%= f.label :name do %>
<%= Person.human_attribute_name(:name) %><span class="people-form__required" aria-hidden="true"> *</span>
diff --git a/config/locales/models.de.yml b/config/locales/models.de.yml
index 7e3e0c0..8cc1f4a 100644
--- a/config/locales/models.de.yml
+++ b/config/locales/models.de.yml
@@ -5,6 +5,7 @@ de:
person:
user: "Mitglied"
name: "Name"
+ salutation: "Anrede"
function: "Funktion"
department: "Abteilung"
company: "Firma"
diff --git a/config/locales/models.en.yml b/config/locales/models.en.yml
index f6f7fed..4ed5f4f 100644
--- a/config/locales/models.en.yml
+++ b/config/locales/models.en.yml
@@ -5,6 +5,7 @@ en:
person:
user: "Member"
name: "Name"
+ salutation: "Salutation"
function: "Function"
department: "Department"
company: "Company"
diff --git a/config/locales/views/personen.de.yml b/config/locales/views/personen.de.yml
index a60a007..9ff4138 100644
--- a/config/locales/views/personen.de.yml
+++ b/config/locales/views/personen.de.yml
@@ -110,6 +110,7 @@ de:
no_member: "kein Mitglied"
former_member_option: "%{name} (früheres Mitglied)"
placeholders:
+ salutation: "z. B. Herr, Frau, Frau Dr. (leer = keine Angabe)"
name: "Vor- und Nachname"
function: "z. B. Technischer Ansprechpartner"
department: "z. B. IT"
diff --git a/config/locales/views/personen.en.yml b/config/locales/views/personen.en.yml
index e22e639..0a05882 100644
--- a/config/locales/views/personen.en.yml
+++ b/config/locales/views/personen.en.yml
@@ -110,6 +110,7 @@ en:
no_member: "no member"
former_member_option: "%{name} (former member)"
placeholders:
+ salutation: "e.g. Mr, Ms, Dr (empty = none given)"
name: "First and last name"
function: "e.g. technical contact"
department: "e.g. IT"
diff --git a/db/migrate/20261028100000_add_salutation_to_people.rb b/db/migrate/20261028100000_add_salutation_to_people.rb
new file mode 100644
index 0000000..78f311a
--- /dev/null
+++ b/db/migrate/20261028100000_add_salutation_to_people.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+# The salutation of a person in the people directory ("Herr", "Frau Dr."), free
+# text. Often only "Frau Müller" is known, without a first name; the salutation
+# says how to address her. Empty means none given. No default, so no rewrite.
+class AddSalutationToPeople < ActiveRecord::Migration[8.1]
+ def change
+ add_column :people, :salutation, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index e9d8ac7..cd4e872 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[8.1].define(version: 2026_10_27_130000) do
+ActiveRecord::Schema[8.1].define(version: 2026_10_28_100000) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
enable_extension "pgcrypto"
@@ -1074,6 +1074,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_10_27_130000) do
t.integer "lock_version", default: 0, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
+ t.string "salutation"
t.index ["organisation_id", "normalized_name"], name: "index_people_on_organisation_id_and_normalized_name"
t.index ["organisation_id", "user_id"], name: "index_people_on_organisation_id_and_user_id", unique: true, where: "(user_id IS NOT NULL)"
t.index ["user_id"], name: "index_people_on_user_id"
diff --git a/spec/helpers/people_helper_spec.rb b/spec/helpers/people_helper_spec.rb
index 2965e0b..7934d34 100644
--- a/spec/helpers/people_helper_spec.rb
+++ b/spec/helpers/people_helper_spec.rb
@@ -33,6 +33,16 @@ RSpec.describe PeopleHelper, type: :helper do
end
end
+ # A member row with only a salutation has details: no "add details" hint.
+ describe '#person_bare?' do
+ it 'counts a salutation as a detail' do
+ ActsAsTenant.with_tenant(create(:organisation)) do
+ expect(helper.person_bare?(Person.new(name: 'Müller'))).to be(true)
+ expect(helper.person_bare?(Person.new(name: 'Müller', salutation: 'Frau'))).to be(false)
+ end
+ end
+ end
+
# Review round 1: the date of the last meeting names its year when it is
# not this year.
describe '#last_contact_text' do
diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb
index 76ab281..7e7112c 100644
--- a/spec/models/person_spec.rb
+++ b/spec/models/person_spec.rb
@@ -42,6 +42,25 @@ RSpec.describe Person, type: :model do
expect(build(:person, organisation: organisation, email: '')).to be_valid
end
+ describe 'the salutation' do
+ it 'keeps free text as written, squeezed' do
+ person = create(:person, organisation: organisation, salutation: ' Frau Dr. ')
+
+ expect(person.salutation).to eq('Frau Dr.')
+ end
+
+ it 'stores a blank salutation as none' do
+ expect(create(:person, organisation: organisation, salutation: ' ').salutation).to be_nil
+ end
+
+ it 'refuses a salutation longer than a field' do
+ person = build(:person, organisation: organisation, salutation: 'x' * (Person::MAX_FIELD_LENGTH + 1))
+
+ expect(person).not_to be_valid
+ expect(person.errors[:salutation]).to be_present
+ end
+ end
+
describe 'the member link' do
it 'accepts an active member of the same organisation' do
expect(build(:person, organisation: organisation, user: member_of(organisation))).to be_valid
diff --git a/spec/requests/organisations/people_spec.rb b/spec/requests/organisations/people_spec.rb
index 3f92ac7..993c5c8 100644
--- a/spec/requests/organisations/people_spec.rb
+++ b/spec/requests/organisations/people_spec.rb
@@ -299,6 +299,38 @@ RSpec.describe 'Organisations::People', :ci_guard, type: :request do
end
end
+ # Often only "Herr Müller" or "Frau Müller" is known. The salutation is free
+ # text; the form suggests the usual ones as a grey example only.
+ describe 'the salutation' do
+ before { sign_in manager }
+
+ it 'saves it from the form and shows it in the lane' do
+ patch organisation_person_path(organisation, person),
+ params: { person: { salutation: 'Frau Dr.', lock_version: person.lock_version } }
+ expect(person.reload.salutation).to eq('Frau Dr.')
+
+ get organisation_person_path(organisation, person), headers: frame_headers
+
+ expect(response.body).to include(Person.human_attribute_name(:salutation), 'Frau Dr.')
+ end
+
+ it 'offers a free text field with the suggestions as placeholder' do
+ get edit_organisation_person_path(organisation, person), headers: frame_headers
+
+ field = Nokogiri::HTML(response.body).at_css('input#person_salutation')
+ expect(field).to be_present
+ expect(field['type']).to eq('text')
+ expect(field['placeholder']).to eq(I18n.t('views.organisations.people.form.placeholders.salutation'))
+ end
+
+ it 'shows no salutation line for a person without one' do
+ get organisation_person_path(organisation, person), headers: frame_headers
+
+ expect(response.body).to include('Doris Dienstleister')
+ expect(response.body).not_to include(">#{Person.human_attribute_name(:salutation)}<")
+ end
+ end
+
# Review round 1, finding 1: the form only offered ACTIVE members, so the row
# of a deactivated member showed "Kein Mitglied" selected, and any save (only
# the phone changed) dropped the link without anybody noticing.
diff --git a/spec/services/actors/save_person_spec.rb b/spec/services/actors/save_person_spec.rb
index 5228f8a..c6cc0c8 100644
--- a/spec/services/actors/save_person_spec.rb
+++ b/spec/services/actors/save_person_spec.rb
@@ -30,6 +30,15 @@ RSpec.describe Actors::SavePerson do
expect([person.creator_id, person.updater_id]).to eq([writer.id, writer.id])
end
+ it 'saves and clears the salutation' do
+ person = save(name: 'Müller', salutation: 'Frau Dr.').resource
+ expect(person.salutation).to eq('Frau Dr.')
+
+ save(salutation: '', lock_version: person.lock_version, id: person.id)
+
+ expect(person.reload.salutation).to be_nil
+ end
+
it 'records the actor of the activity (Current.user from the actor)' do
result = save(name: 'Erika Beispiel')