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
fix(people): address review round 3 of the people directory
Guido Boyke655d0f5a94f6
diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rbindex cf57719..1283b67 100644--- a/app/helpers/people_helper.rb+++ b/app/helpers/people_helper.rb@@ -84,16 +84,22 @@ module PeopleHelperendend- # The active members the reader may link a row to: visible on the members- # page and without a row of their own yet. The row's current member always- # stays an option, also once deactivated: without it the select shows "no- # member", and every save of the form would drop the link (review round 1).- def linkable_members_for(person)+ # The options of the member select: the active members the reader may link+ # (visible on the members page, without a row of their own yet), labelled+ # through the viewer's name display setting. The member a stored row is+ # linked to always stays an option, also once deactivated: without it the+ # select shows "no member" and every save drops the link (review round 1).+ # A stored member the reader cannot link now (deactivated, out of sight) is+ # labelled with the row's own name, never with the account (review round 3).+ def member_options_for(person)taken = Person.where(organisation: current_organisation).linked.where.not(id: person.id).select(:user_id)member_ids = policy_scope(Membership).where(organisation: current_organisation, active: true).select(:user_id)members = User.where(id: member_ids).where.not(id: taken).to_a- stored = User.find_by(id: person.user_id_in_database) if person.persisted? && person.user_id_in_database- members |= [stored] if stored- members.sort_by { |user| viewer_display_name(user).downcase }+ options = members.map { |user| [viewer_display_name(user), user.id] }.sort_by { |label, _id| label.downcase }+ stored_id = person.user_id_in_database if person.persisted?+ return options if stored_id.nil? || members.any? { |user| user.id == stored_id }++ label = t('views.organisations.people.form.former_member_option', name: person.name_in_database)+ [[label, stored_id]] + optionsendenddiff --git a/app/services/actors/save_person.rb b/app/services/actors/save_person.rbindex 04cbe76..8de2753 100644--- a/app/services/actors/save_person.rb+++ b/app/services/actors/save_person.rb@@ -18,6 +18,8 @@module Actorsclass SavePerson < BaseActorATTRIBUTES = %i[name function department company email phone notes lock_version].freeze+ # lock_version is an integer column (4 bytes).+ LOCK_VERSION_RANGE = (0..((2**31) - 1))def initialize(organisation:, params:, current_user:, id: nil)super()@@ -35,7 +37,9 @@ module Actorsraise ActorError.new(I18n.t('controllers.people.not_found'), code: :not_found) if @person.nil?check_lock_version- @person.assign_attributes(@params.slice(*ATTRIBUTES))+ attributes = @params.slice(*ATTRIBUTES)+ attributes.delete(:lock_version) if @person.new_record?+ @person.assign_attributes(attributes)assign_link if @params.key?(:user_id)@person.creator ||= @current_user if @person.new_record?@person.updater = @current_user@@ -46,11 +50,12 @@ module Actorsattr_reader :current_user- # A lock_version that is not a number (a hand-made request) cannot say what- # the writer saw; Rails would raise on a nil one. Treated as stale.+ # On an update, a lock_version that is not a number the column can hold (a+ # hand-made request) cannot say what the writer saw; Rails would raise on+ # it. Treated as stale. A new row has none to compare.def check_lock_version- return unless @params.key?(:lock_version)- return if Integer(@params[:lock_version].to_s, exception: false)+ return if @person.nil? || @person.new_record? || [email protected]?(:lock_version)+ return if LOCK_VERSION_RANGE.cover?(Integer(@params[:lock_version].to_s, exception: false))raise ActorError.new(I18n.t('controllers.people.update.stale'), code: :stale_object)enddiff --git a/app/views/organisations/people/_detail.html.erb b/app/views/organisations/people/_detail.html.erbindex dad56b9..76e10d1 100644--- a/app/views/organisations/people/_detail.html.erb+++ b/app/views/organisations/people/_detail.html.erb@@ -74,7 +74,10 @@<% duplicates.each do |entry| %><li><% if entry.person %>- <%= link_to person_display_name(person: entry.person, user: entry.user), organisation_person_path(@current_organisation, entry.person) %>+ <%# A full visit, like a row: the address names the person shown. %>+ <%= link_to person_display_name(person: entry.person, user: entry.user),+ organisation_people_path(@current_organisation, list_state.merge('person_id' => entry.person.id)),+ data: { turbo_frame: '_top' } %><% else %><%= viewer_display_name(entry.user) %><% end %>diff --git a/app/views/organisations/people/_form.html.erb b/app/views/organisations/people/_form.html.erbindex d0cc902..cccb409 100644--- a/app/views/organisations/people/_form.html.erb+++ b/app/views/organisations/people/_form.html.erb@@ -24,16 +24,17 @@<div><%= f.label :user_id, Person.human_attribute_name(:user), class: 'block text-sm font-medium text-cream-700 mb-1' %>- <%= f.select :user_id, linkable_members_for(person).map { |user| [viewer_display_name(user), user.id] },+ <%= f.select :user_id, member_options_for(person),{ include_blank: t('views.organisations.people.form.no_member') }, class: input_class %><p class="mt-1 text-xs text-muted"><%= t('views.organisations.people.form.member_hint') %></p></div><div><%= f.label :name, class: 'block text-sm font-medium text-cream-700 mb-1' %>- <%# A linked row shows the member's own name; the copy here only shows once- the link is gone, so it is not edited while linked. %>- <%= f.text_field :name, class: input_class, maxlength: Person::MAX_FIELD_LENGTH, readonly: person.user_id.present? %>+ <%# A row of an active member shows the member's own name; the copy here+ only shows once the link is gone or the member left, so it is not+ edited while the member is active. %>+ <%= f.text_field :name, class: input_class, maxlength: Person::MAX_FIELD_LENGTH, readonly: person_member_user(person).present? %></div><% %i[function department company].each do |field| %>diff --git a/config/locales/views/personen.de.yml b/config/locales/views/personen.de.ymlindex 9c3b805..885ac75 100644--- a/config/locales/views/personen.de.yml+++ b/config/locales/views/personen.de.yml@@ -49,6 +49,7 @@ de:new_title: "Person anlegen"edit_title: "Person bearbeiten"no_member: "Kein Mitglied"+ former_member_option: "%{name} (früheres Mitglied)"member_hint: "Mit einem Mitglied verknüpft, zeigt die Liste den Namen aus seinem Konto."shared_hint: "Alle mit Zugriff auf Personen sehen diese Angaben, auch die Kundenseite."save: "Speichern"diff --git a/config/locales/views/personen.en.yml b/config/locales/views/personen.en.ymlindex f7a15f1..3115eda 100644--- a/config/locales/views/personen.en.yml+++ b/config/locales/views/personen.en.yml@@ -49,6 +49,7 @@ en:new_title: "Add person"edit_title: "Edit person"no_member: "No member"+ former_member_option: "%{name} (former member)"member_hint: "When linked to a member, the list shows the name from their account."shared_hint: "Everyone with access to people sees these details, the customer's side too."save: "Save"diff --git a/spec/requests/organisations/people_spec.rb b/spec/requests/organisations/people_spec.rbindex 342a45a..44142fa 100644--- a/spec/requests/organisations/people_spec.rb+++ b/spec/requests/organisations/people_spec.rb@@ -280,7 +280,7 @@ RSpec.describe 'Organisations::People', :ci_guard, type: :request doget organisation_person_path(organisation, person), headers: frame_headersexpect(response.body).to include(I18n.t('views.organisations.people.show.duplicates_title'),- organisation_person_path(organisation, twin))+ "person_id=#{twin.id}")endit 'lists the history without values' do@@ -477,6 +477,106 @@ RSpec.describe 'Organisations::People', :ci_guard, type: :request doexpect(response.body).to match(/<input[^>]*readonly="readonly"[^>]*id="person_name"|<input[^>]*id="person_name"[^>]*readonly="readonly"/)end+ # Review round 3, finding 1: the member select named the CURRENT account of+ # a deactivated member, also to a reader who may not see that member.+ it 'labels the stored former member with the row name, not the account' do+ project = create(:project, organisation: organisation)+ create(:project_permission, user: manager, project: project, tickets_access: :read_only)+ hidden = member_with(role_with, first_name: 'Kopie')+ create(:project_permission, user: hidden, project: create(:project, organisation: organisation),+ tickets_access: :read_only)+ row = create(:person, organisation: organisation, user: hidden, name: 'Kopie Name')+ Membership.find_by(user: hidden, organisation: organisation).update!(active: false)+ hidden.update!(first_name: 'Geheim', last_name: 'Neuname')+ sign_in manager++ get edit_organisation_person_path(organisation, row), headers: frame_headers++ expect(response.body).not_to include('Neuname')+ expect(response.body).to match(/<option selected="selected" value="#{hidden.id}">Kopie Name/)+ end++ # Review round 3, finding 2: the name of a former member's row is the only+ # name shown, so it stays editable.+ it 'keeps the name field editable for the row of a former member' do+ former = member_with(role_with, first_name: 'Alt')+ row = create(:person, organisation: organisation, user: former, name: 'Alt Name')+ Membership.find_by(user: former, organisation: organisation).update!(active: false)+ sign_in admin++ get edit_organisation_person_path(organisation, row), headers: frame_headers++ expect(response.body[/<input[^>]*id="person_name"[^>]*>/]).not_to include('readonly')+ end++ # Review round 3, finding 3: ?user_id= only preselects a member without a row+ # who is active.+ describe 'preselecting a member through the address' do+ before { sign_in admin }++ it 'does not preselect a member who already has a row' do+ taken = member_with(role_with, first_name: 'Vergeben')+ create(:person, organisation: organisation, user: taken)++ get new_organisation_person_path(organisation, user_id: taken.id), headers: frame_headers++ expect(response.body).not_to include('selected="selected"')+ expect(response.body[/<input[^>]*id="person_name"[^>]*>/]).not_to include('readonly')+ end++ it 'does not preselect a deactivated member' do+ former = member_with(role_with, first_name: 'Inaktiv')+ Membership.find_by(user: former, organisation: organisation).update!(active: false)++ get new_organisation_person_path(organisation, user_id: former.id), headers: frame_headers++ expect(response.body).not_to include('selected="selected"')+ end+ end++ # Review round 3, finding 4: the address rules of user_id (form group, the+ # "+" takes it away, an unopened one is dropped).+ it 'wires user_id as part of the lane form state' do+ sign_in admin++ get organisation_people_path(organisation, user_id: 'x')++ expect(response.body).to include(CGI.escapeHTML('"form":["new","user_id"]'),+ CGI.escapeHTML('["person_id","user_id"]'),+ CGI.escapeHTML('{"user_id":"x"}'))+ end++ # Review round 3, findings 5 and 6: hand-made lock versions.+ it 'creates a person even when the request carries an unusable lock_version' do+ sign_in admin++ expect do+ post organisation_people_path(organisation), params: { person: { name: 'Neu Person', lock_version: '' } }+ end.to change(Person, :count).by(1)+ end++ it 'answers a lock_version beyond the column as a stale save' do+ sign_in admin++ patch organisation_person_path(organisation, person),+ params: { person: { phone: '0', lock_version: '99999999999999999999' } }++ expect(response).to have_http_status(:unprocessable_content)+ expect(person.reload.phone).to eq('+49 30 1234567')+ end++ # Review round 3, finding 7: a duplicate opens like a row, with its own+ # address, not inside the frame alone.+ it 'links a duplicate to the page address of that person' do+ twin = create(:person, organisation: organisation, name: 'Doris Dienstleister')+ sign_in admin++ get organisation_person_path(organisation, person), headers: frame_headers++ link = response.body[/<a[^>]*href="[^"]*person_id=#{twin.id}[^"]*"[^>]*>/]+ expect(link).to include('data-turbo-frame="_top"')+ end+it 'has no missing translation on the page' dosign_in adminget organisation_people_path(organisation, person_id: person.id)