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.

fix(people): address the external review of the people page

Guido Boykedb1b0288abb9
diff --git a/app/controllers/organisations/people_controller.rb b/app/controllers/organisations/people_controller.rb
index 0060724..af9ba83 100644
--- a/app/controllers/organisations/people_controller.rb
+++ b/app/controllers/organisations/people_controller.rb
@@ -236,10 +236,15 @@ module Organisations
end
# The list state of this request (the address, or the hidden fields of a
- # lane form). Kept to strings: a list state is a word and a search.
+ # lane form). Kept to strings: a list state is a word and a search. The
+ # phone view rides along (viewport=mobile): without it a refused save or a
+ # redirect renders the desktop page, and viewport_controller reloads the
+ # original address, losing the reason and the values typed.
def list_state
- state = request.query_parameters.merge(request.request_parameters).slice(*LIST_PARAMS)
- state.select { |_key, value| value.is_a?(String) && value.present? }
+ given = request.query_parameters.merge(request.request_parameters)
+ state = given.slice(*LIST_PARAMS).select { |_key, value| value.is_a?(String) && value.present? }
+ state['viewport'] = 'mobile' if given['viewport'] == 'mobile'
+ state
end
helper_method :list_state
end
diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rb
index 81973eb..05fa411 100644
--- a/app/helpers/people_helper.rb
+++ b/app/helpers/people_helper.rb
@@ -84,6 +84,21 @@ module PeopleHelper
end
end
+ # The member whose account fills (and locks) name and email in the form: the
+ # STORED link of a saved row, or the member chosen for a new one. A link the
+ # save just refused (taken, not a member) is no member: the form shows the
+ # select again so the writer can correct it.
+ def person_form_member(person)
+ return if person.errors.include?(:user_id) || person.errors.include?(:user)
+ return person_member_user(person) unless person.persisted?
+
+ stored_id = person.user_id_in_database
+ return unless stored_id
+
+ active = Membership.where(organisation: current_organisation, user_id: stored_id, active: true).exists?
+ User.find_by(id: stored_id) if active
+ end
+
# 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? }
diff --git a/app/javascript/controllers/neo_button_controller.js b/app/javascript/controllers/neo_button_controller.js
index 0972622..efcf276 100644
--- a/app/javascript/controllers/neo_button_controller.js
+++ b/app/javascript/controllers/neo_button_controller.js
@@ -13,13 +13,21 @@ export default class extends Controller {
this.showLoading()
}
- // Reset loading state after Turbo form submission completes
+ // Reset loading state after Turbo form submission completes. Turbo fires
+ // the submit events on the FORM, so a button inside one listens there.
this.boundReset = this.hideLoading.bind(this)
+ this.boundShow = this.showLoading.bind(this)
+ this.form = this.element.tagName === "BUTTON" ? this.element.closest("form") : null
this.element.addEventListener("turbo:submit-end", this.boundReset)
+ if (this.form) this.form.addEventListener("turbo:submit-end", this.boundReset)
}
disconnect() {
this.element.removeEventListener("turbo:submit-end", this.boundReset)
+ if (this.form) {
+ this.form.removeEventListener("turbo:submit-end", this.boundReset)
+ this.form.removeEventListener("turbo:submit-start", this.boundShow)
+ }
}
async handleClick(event) {
@@ -38,6 +46,15 @@ export default class extends Controller {
return
}
+ // A form that asks first (data-turbo-confirm, the form: + confirm: button):
+ // Turbo asks after this click. Loading starts only when it really submits;
+ // a "no" leaves the button as it was, nothing to restore.
+ if (this.form && this.form.dataset.turboConfirm) {
+ this.form.removeEventListener("turbo:submit-start", this.boundShow)
+ this.form.addEventListener("turbo:submit-start", this.boundShow)
+ return
+ }
+
// For forms and turbo-method links, show loading state
this.showLoading()
}
diff --git a/app/services/actors/save_person.rb b/app/services/actors/save_person.rb
index 8de2753..f89464c 100644
--- a/app/services/actors/save_person.rb
+++ b/app/services/actors/save_person.rb
@@ -65,6 +65,7 @@ module Actors
def save_link_safely
@person.save!
rescue ActiveRecord::RecordNotUnique
+ @person.errors.add(:user_id, :taken)
raise ActorError.new(I18n.t('controllers.people.link_not_allowed'), code: :validation_failed)
end
diff --git a/app/services/people/directory.rb b/app/services/people/directory.rb
index 0369ffd..3fb7a1e 100644
--- a/app/services/people/directory.rb
+++ b/app/services/people/directory.rb
@@ -61,8 +61,10 @@ module People
# The other entries with the same normalized name as this person: rows and
# members that may be the same person (the duplicate hint, read only).
def duplicates_of(person)
+ own = everyone.find { |entry| entry.person&.id == person.id }
+ name = own ? own.sort_name : person.normalized_name
everyone.select do |entry|
- entry.sort_name == person.normalized_name && entry.person&.id != person.id &&
+ entry.sort_name == name && entry.person&.id != person.id &&
!(entry.user && entry.user.id == person.user_id)
end
end
diff --git a/app/views/organisations/people/_detail.html.erb b/app/views/organisations/people/_detail.html.erb
index 51cddc7..da2a5f3 100644
--- a/app/views/organisations/people/_detail.html.erb
+++ b/app/views/organisations/people/_detail.html.erb
@@ -10,7 +10,7 @@
<div class="people-detail">
<%= render 'organisations/people/lane_head',
kind_label: t("views.organisations.people.show.kind.#{kind}"),
- edit_url: (edit_organisation_person_path(@current_organisation, person) if can_write) %>
+ edit_url: (edit_organisation_person_path(@current_organisation, person, list_state) if can_write) %>
<% status_icon, status = person_link_state(person, member) %>
<%= render 'organisations/people/identity', name: name, user: member, status_icon: status_icon, status: status %>
@@ -30,7 +30,7 @@
</p>
<% end %>
<% if can_write && member.nil? && duplicates.any?(&:member?) %>
- <%= link_to t('views.organisations.people.show.duplicate_link'), edit_organisation_person_path(@current_organisation, person),
+ <%= link_to t('views.organisations.people.show.duplicate_link'), edit_organisation_person_path(@current_organisation, person, list_state),
class: 'people-text-action' %>
<% end %>
</div>
@@ -38,7 +38,7 @@
<% end %>
<% if member && person_bare?(person) %>
- <%= render 'organisations/people/bare_hint', member: member, url: (edit_organisation_person_path(@current_organisation, person) if can_write) %>
+ <%= render 'organisations/people/bare_hint', member: member, url: (edit_organisation_person_path(@current_organisation, person, list_state) if can_write) %>
<% end %>
<%= render 'organisations/people/fields', fields: person_fields(person, member) %>
diff --git a/app/views/organisations/people/_form.html.erb b/app/views/organisations/people/_form.html.erb
index 4fb7dad..4ab287b 100644
--- a/app/views/organisations/people/_form.html.erb
+++ b/app/views/organisations/people/_form.html.erb
@@ -9,10 +9,10 @@
shown, locked, and not sent. Its link is fixed, so the member select is
left out (no user_id sent: SavePerson keeps the link). A new row and a
contact may be linked. %>
-<% member = person_member_user(person) %>
+<% member = person_form_member(person) %>
<% url = person.persisted? ? organisation_person_path(@current_organisation, person) : organisation_people_path(@current_organisation) %>
<% title = person.persisted? || member ? t('views.organisations.people.form.edit_title', name: person_display_name(person: person, user: member)) : t('views.organisations.people.form.new_title') %>
-<% cancel_url = person.persisted? ? organisation_person_path(@current_organisation, person) : organisation_people_path(@current_organisation, list_state) %>
+<% cancel_url = person.persisted? ? organisation_person_path(@current_organisation, person, list_state) : organisation_people_path(@current_organisation, list_state) %>
<div class="people-form-wrap">
<div class="people-lane__head" data-lane-head data-lane-index-url="<%= organisation_people_path(@current_organisation) %>">
<h2 class="people-form__title"><%= title %></h2>
diff --git a/app/views/organisations/people/_row.html.erb b/app/views/organisations/people/_row.html.erb
index f5e0bd2..8b9a684 100644
--- a/app/views/organisations/people/_row.html.erb
+++ b/app/views/organisations/people/_row.html.erb
@@ -10,7 +10,9 @@
<% param, id = 'member_id', entry.user.id %>
<% open = member&.id == entry.user.id %>
<% end %>
-<% row_data = { controller: 'list-row', action: 'click->list-row#click', people_row: true,
+<%# Enter and Space open the row like a click: the row is the only control. %>
+<% row_data = { controller: 'list-row', action: 'click->list-row#click keydown.enter->list-row#click keydown.space->list-row#click',
+ people_row: true,
list_row_url_value: url, list_row_id_value: id, list_row_param_value: param,
list_row_params_value: PeopleHelper::SELECTION_PARAMS.to_json,
list_row_frame_value: Organisations::PeopleController::DETAIL_FRAME_ID } %>
diff --git a/spec/javascript/controllers/neo_button_controller.test.js b/spec/javascript/controllers/neo_button_controller.test.js
new file mode 100644
index 0000000..050f6c0
--- /dev/null
+++ b/spec/javascript/controllers/neo_button_controller.test.js
@@ -0,0 +1,61 @@
+import { test } from "node:test"
+import assert from "node:assert/strict"
+import { readFileSync } from "node:fs"
+import { runInNewContext } from "node:vm"
+
+const source = readFileSync(new URL("../../../app/javascript/controllers/neo_button_controller.js", import.meta.url), "utf8")
+ .replace(/^import .*\n/gm, "")
+ .replace("export default class", "class NeoButtonController")
+
+// A tiny element with classes and listeners, enough for the controller.
+function element(tagName, dataset = {}) {
+ const listeners = {}
+ const classes = new Set()
+ return {
+ tagName,
+ dataset,
+ form: null,
+ classList: { add: (...c) => c.forEach(x => classes.add(x)), remove: (...c) => c.forEach(x => classes.delete(x)), contains: c => classes.has(c) },
+ addEventListener: (type, fn) => { (listeners[type] ||= []).push(fn) },
+ removeEventListener: (type, fn) => { listeners[type] = (listeners[type] || []).filter(f => f !== fn) },
+ dispatch: type => (listeners[type] || []).slice().forEach(fn => fn({ type })),
+ closest: () => null
+ }
+}
+
+function fixture({ confirmOnForm }) {
+ const Controller = runInNewContext(`${source}\nNeoButtonController`, { Controller: class {}, confirm: () => true })
+ const form = element("FORM", confirmOnForm ? { turboConfirm: "Sicher?" } : {})
+ const button = element("BUTTON")
+ button.form = form
+ button.closest = selector => (selector === "form" ? form : null)
+ const controller = new Controller()
+ controller.element = button
+ controller.loadingValue = false
+ controller.confirmValue = ""
+ controller.hasSpinnerTarget = false
+ controller.hasContentTarget = false
+ controller.connect()
+ return { controller, form, button }
+}
+
+test("a form that asks first: no loading state before the answer", () => {
+ const { controller, button } = fixture({ confirmOnForm: true })
+ controller.handleClick({ preventDefault() {}, stopPropagation() {} })
+ assert.equal(button.classList.contains("pointer-events-none"), false)
+})
+
+test("a form that asks first: loading once Turbo submits, and back after the answer", () => {
+ const { controller, form, button } = fixture({ confirmOnForm: true })
+ controller.handleClick({ preventDefault() {}, stopPropagation() {} })
+ form.dispatch("turbo:submit-start")
+ assert.equal(button.classList.contains("pointer-events-none"), true)
+ form.dispatch("turbo:submit-end")
+ assert.equal(button.classList.contains("pointer-events-none"), false)
+})
+
+test("a form without a question: loading at once, as before", () => {
+ const { controller, button } = fixture({ confirmOnForm: false })
+ controller.handleClick({ preventDefault() {}, stopPropagation() {} })
+ assert.equal(button.classList.contains("pointer-events-none"), true)
+})
diff --git a/spec/requests/organisations/people_spec.rb b/spec/requests/organisations/people_spec.rb
index f66f3fa..4b07266 100644
--- a/spec/requests/organisations/people_spec.rb
+++ b/spec/requests/organisations/people_spec.rb
@@ -684,6 +684,53 @@ RSpec.describe 'Organisations::People', :ci_guard, type: :request do
end
end
+ # External review of 26.10.2026.
+ describe 'on a phone' do
+ before { sign_in admin }
+
+ it 'keeps the phone view when a save is refused' do
+ post organisation_people_path(organisation), params: { person: { name: '' }, viewport: 'mobile' }
+
+ expect(response).to have_http_status(:unprocessable_content)
+ expect(response.body).to include('people-mobile-grid', 'name="viewport"')
+ end
+
+ it 'carries the phone view into the edit form of the lane' do
+ get organisation_people_path(organisation, person_id: person.id, viewport: 'mobile')
+
+ expect(response.body).to include(edit_organisation_person_path(organisation, person, viewport: 'mobile'))
+ end
+
+ it 'lands on the phone view after a save' do
+ patch organisation_person_path(organisation, person),
+ params: { person: { phone: '0', lock_version: person.lock_version }, viewport: 'mobile' }
+
+ expect(response).to redirect_to(organisation_people_path(organisation, person_id: person.id, viewport: 'mobile'))
+ end
+ end
+
+ it 'keeps the member select when a link is refused (the member has a row already)' do
+ taken = member_with(role_with, first_name: 'Vergeben')
+ create(:person, organisation: organisation, user: taken)
+ sign_in admin
+
+ patch organisation_person_path(organisation, person),
+ params: { person: { user_id: taken.id, lock_version: person.lock_version } }
+
+ expect(response).to have_http_status(:unprocessable_content)
+ expect(response.body).to include('name="person[user_id]"')
+ expect(response.body[/<input[^>]*id="person_name"[^>]*>/]).not_to include('readonly')
+ end
+
+ it 'opens a row from the keyboard (Enter and Space)' do
+ sign_in admin
+
+ get organisation_people_path(organisation)
+
+ row = response.body[/<li[^>]*data-list-row-id-value="#{person.id}"[^>]*>/]
+ expect(row).to include(CGI.escapeHTML('keydown.enter->list-row#click'), CGI.escapeHTML('keydown.space->list-row#click'))
+ end
+
it 'has no missing translation on the page' do
sign_in admin
get organisation_people_path(organisation, person_id: person.id)
diff --git a/spec/services/people/directory_spec.rb b/spec/services/people/directory_spec.rb
index c93ff68..e60d667 100644
--- a/spec/services/people/directory_spec.rb
+++ b/spec/services/people/directory_spec.rb
@@ -96,6 +96,20 @@ RSpec.describe People::Directory, :ci_guard do
end
end
+ # External review of 26.10.2026: a linked member is compared by the name
+ # the directory shows, not by the copy taken when the row was linked.
+ it 'finds duplicates of a member by the current account name' do
+ row = create(:person, organisation: organisation, user: colleague, name: 'Carl Kollege')
+ colleague.update!(first_name: 'Carlo', last_name: 'Neu')
+ namesake = create(:person, organisation: organisation, name: 'Carlo Neu')
+ old_namesake = create(:person, organisation: organisation, name: 'Carl Kollege')
+
+ duplicates = described_class.new(viewer: admin, organisation: organisation).duplicates_of(row.reload)
+
+ expect(duplicates.map(&:person)).to include(namesake)
+ expect(duplicates.map(&:person)).not_to include(old_namesake)
+ end
+
it 'returns nothing without the right' do
expect(entries(colleague)).to be_empty
end