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
Keep the link of a deactivated member's row
Guido Boyke0377f9b62f5c
diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rbindex e450bea..15c2633 100644--- a/app/helpers/people_helper.rb+++ b/app/helpers/people_helper.rb@@ -92,11 +92,14 @@ module PeopleHelperreturn 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+ membership = person.stored_membership+ membership.user if membership&.active?+ end- active = Membership.where(organisation: current_organisation, user_id: stored_id, active: true).exists?- User.find_by(id: stored_id) if active+ # Whether the form offers the member select: not while a membership stands+ # behind the stored link, active or deactivated (SavePerson keeps it).+ def person_link_choosable?(person)+ !person.persisted? || person.stored_membership.nil?end# A member row with none of the details the directory is for yet.@@ -171,21 +174,14 @@ module PeopleHelper# 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).+ # through the viewer's name display setting. A row whose stored link has a+ # membership behind it gets no select (person_link_choosable?), so no stored+ # member needs an option of its own here (review of PR #64).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- 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]] + options+ members.map { |user| [viewer_display_name(user), user.id] }.sort_by { |label, _id| label.downcase }end# How long ago a last contact was, in calendar days (S2a): heute, gestern,diff --git a/app/models/CLAUDE.md b/app/models/CLAUDE.mdindex b5f2309..3fddb4f 100644--- a/app/models/CLAUDE.md+++ b/app/models/CLAUDE.md@@ -57,7 +57,9 @@ Verzeichnis-Layout nicht ablesbar — diese Karte gruppiert sie:Mitgliederseite nicht sieht, bleibt versteckt, auch wenn die Mitgliedschaft nur deaktiviert ist(`PersonPolicy::Scope`). Erst nach dem Entfernen ist sie ein Kontakt für alle mit dem Recht.Name, E-Mail und Verknüpfung der Zeile eines aktiven Mitglieds gehören dem Konto: `SavePerson`- nimmt sie aus keiner Anfrage (`ACCOUNT_FIELDS`). „Bearbeiten schließt Ansehen ein“ steht einmal+ nimmt sie aus keiner Anfrage (`ACCOUNT_FIELDS`). Bei einem deaktivierten Mitglied bleibt nur+ die Verknüpfung fest (`LINK_FIELDS`, kein Mitglieder-Select im Formular), Name und E-Mail+ der Zeile bleiben ihre eigenen. Beide fragen `Person#stored_membership`. „Bearbeiten schließt Ansehen ein“ steht einmalin `Permission::IMPLIED_BY` (gelesen von `PersonPolicy` und `RolePolicy#change_permission?`).⚠️ `concerns/person_trackable.rb`: Aktivitäten tragen KEINE Personendaten (leere Parameter,bei Änderungen nur Feldnamen), `skip_notifications` immer; ein Löschen hinterlässt genau einediff --git a/app/models/person.rb b/app/models/person.rbindex edb921c..f2c3c85 100644--- a/app/models/person.rb+++ b/app/models/person.rb@@ -46,6 +46,15 @@ class Person < ApplicationRecorduser_id.present?end+ # The membership behind the STORED link (not an unsaved change). While there+ # is one, the link stays (Actors::SavePerson, the form): deactivating can be+ # undone. An active one also owns name and email. Nil for a contact and for a+ # removed member (PersonLinkRelease).+ def stored_membership+ stored_id = user_id_in_database if persisted?+ Membership.find_by(organisation_id: organisation_id, user_id: stored_id) if stored_id+ end+privatedef normalize_name_fieldsdiff --git a/app/services/actors/save_person.rb b/app/services/actors/save_person.rbindex 600aa66..244c791 100644--- a/app/services/actors/save_person.rb+++ b/app/services/actors/save_person.rb@@ -12,7 +12,9 @@# * the fields the account owns: a row linked to an ACTIVE member takes name,# email and its link from the account, as the form shows them (locked, not# sent). A hand-made request does not write them either (ACCOUNT_FIELDS),-# and a row created for a member takes no email of its own.+# and a row created for a member takes no email of its own. A DEACTIVATED+# member's row keeps only its link (LINK_FIELDS): no other member, no+# contact, until the member is removed.# * creator on create, updater on every save;# * a stale save (lock_version, both sides edit the same row) raises# StaleObjectError, which BaseActor maps to code :stale_object; the@@ -24,6 +26,9 @@ module ActorsATTRIBUTES = %i[name function department company email phone notes lock_version].freeze# What the account of an active member owns on its row.ACCOUNT_FIELDS = %i[name email user_id].freeze+ # What stays while the member is only deactivated: the row's own name and+ # email are the ones shown then, so they stay editable.+ LINK_FIELDS = %i[user_id].freeze# lock_version is an integer column (4 bytes).LOCK_VERSION_RANGE = (0..((2**31) - 1))@@ -43,7 +48,7 @@ module Actorsraise ActorError.new(I18n.t('controllers.people.not_found'), code: :not_found) if @person.nil?check_lock_version- @params = @params.except(*ACCOUNT_FIELDS) if active_member_row?+ drop_account_fields@params = @params.except(:email) if @person.new_record? && @params[:user_id].present?attributes = @params.slice(*ATTRIBUTES)attributes.delete(:lock_version) if @person.new_record?@@ -77,10 +82,13 @@ module Actorsraise ActorError.new(I18n.t('controllers.people.link_not_allowed'), code: :validation_failed)end- # A saved row whose link points to an active member of this organisation.- def active_member_row?- stored = @person.persisted? && @person.user_id_in_database- stored && Membership.where(organisation: @organisation, user_id: stored, active: true).exists?+ # A saved row with a membership behind its link keeps that link; an active+ # member's account also owns name and email (Person#stored_membership).+ def drop_account_fields+ membership = @person.stored_membership+ return unless membership++ @params = @params.except(*(membership.active? ? ACCOUNT_FIELDS : LINK_FIELDS))end# Tenant-bound lookup: an id of another organisation is no person at all.diff --git a/app/views/organisations/people/_form.html.erb b/app/views/organisations/people/_form.html.erbindex 4ab287b..9ccab7c 100644--- a/app/views/organisations/people/_form.html.erb+++ b/app/views/organisations/people/_form.html.erb@@ -7,8 +7,9 @@A row of an active member takes name and email from the account: both areshown, 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. %>+ left out (no user_id sent: SavePerson keeps the link). A deactivated+ member's row keeps its link too, but its own name and email stay editable.+ A new row and a contact may be linked. %><% 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') %>@@ -81,7 +82,7 @@placeholder: t('views.organisations.people.form.placeholders.notes') %></div>- <% unless member %>+ <% if member.nil? && person_link_choosable?(person) %><div class="people-form__field"><%= f.label :user_id, t('views.organisations.people.form.link_label') %><%= f.select :user_id, member_options_for(person), { include_blank: t('views.organisations.people.form.no_member') },diff --git a/config/locales/views/personen.de.yml b/config/locales/views/personen.de.ymlindex a60a007..42d37f0 100644--- a/config/locales/views/personen.de.yml+++ b/config/locales/views/personen.de.yml@@ -108,7 +108,6 @@ de:edit_title: "%{name} bearbeiten"link_label: "Mit Mitglied verknüpfen (optional)"no_member: "kein Mitglied"- former_member_option: "%{name} (früheres Mitglied)"placeholders:name: "Vor- und Nachname"function: "z. B. Technischer Ansprechpartner"diff --git a/config/locales/views/personen.en.yml b/config/locales/views/personen.en.ymlindex e22e639..b46dfc6 100644--- a/config/locales/views/personen.en.yml+++ b/config/locales/views/personen.en.yml@@ -108,7 +108,6 @@ en:edit_title: "Edit %{name}"link_label: "Link to a member (optional)"no_member: "no member"- former_member_option: "%{name} (former member)"placeholders:name: "First and last name"function: "e.g. technical contact"diff --git a/spec/requests/organisations/people_spec.rb b/spec/requests/organisations/people_spec.rbindex 7ff0138..a2142f3 100644--- a/spec/requests/organisations/people_spec.rb+++ b/spec/requests/organisations/people_spec.rb@@ -311,10 +311,14 @@ RSpec.describe 'Organisations::People', :ci_guard, type: :request dosign_in adminend- it 'keeps the member selected in the edit form' do+ # Review of PR #64: the link of a deactivated member is fixed (SavePerson),+ # so the form offers no select to change it.+ it 'leaves the member select out of the edit form' doget edit_organisation_person_path(organisation, linked), headers: frame_headers- expect(response.body).to match(/<option selected="selected" value="#{former.id}">/)+ expect(response).to have_http_status(:ok)+ expect(response.body).to include('Frieda Former')+ expect(response.body).not_to include('name="person[user_id]"')endit 'keeps the link when the form is saved with its own values' do@@ -480,9 +484,10 @@ RSpec.describe 'Organisations::People', :ci_guard, type: :request do# 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. Since- # the review of S1 (decision A) such a reader does not get the row at all;- # this pins the label for a reader who may see the deactivated member.- it 'labels the stored former member with the row name, not the account' do+ # the review of S1 (decision A) such a reader does not get the row at all,+ # and since the review of PR #64 the form has no select for this row. What+ # stays: the form names the row, never the account.+ it 'names the row of a deactivated member by its own name, not the account' doproject = create(:project, organisation: organisation)create(:project_permission, user: manager, project: project, tickets_access: :read_only)hidden = member_with(role_with, first_name: 'Kopie')@@ -494,8 +499,9 @@ RSpec.describe 'Organisations::People', :ci_guard, type: :request doget edit_organisation_person_path(organisation, row), headers: frame_headers+ expect(response).to have_http_status(:ok)+ expect(response.body).to include('Kopie Name')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 onlydiff --git a/spec/services/actors/save_person_spec.rb b/spec/services/actors/save_person_spec.rbindex 570a7c3..65d7cff 100644--- a/spec/services/actors/save_person_spec.rb+++ b/spec/services/actors/save_person_spec.rb@@ -56,11 +56,13 @@ RSpec.describe Actors::SavePerson doexpect(result.resource.name).to eq(user.display_name)end- # The form shows the member select again once the member is no longer active.- it 'drops the link of a former member when user_id is blank' do+ # Only a link without any membership behind it can be dropped. Removing a+ # member releases the link by itself (PersonLinkRelease); delete_all skips+ # that callback and leaves such a link behind.+ it 'drops a link without a membership behind it when user_id is blank' douser = memberperson = save(name: 'x', user_id: user.id).resource- Membership.where(user: user, organisation: organisation).update_all(active: false)+ Membership.where(user: user, organisation: organisation).delete_allsave(user_id: '', lock_version: person.lock_version, id: person.id)@@ -68,6 +70,37 @@ RSpec.describe Actors::SavePerson doexpect(person.name).to eq(user.display_name)end+ # Review of PR #64: deactivating can be undone, so the row is still that+ # member's. A new link would carry their phone and notes over to another+ # member, and an empty one would make the row a contact for every reader.+ # The name and email stay the row's own (round 3: the row's name is the one+ # shown).+ describe 'the row of a deactivated member' do+ let(:first_member) { member }+ let!(:row) { save(name: 'egal', user_id: first_member.id, phone: '1', notes: 'n').resource }++ before { Membership.where(user: first_member, organisation: organisation).update_all(active: false) }++ it 'keeps the link against another member' do+ result = save(user_id: member.id, lock_version: row.lock_version, id: row.id)++ expect(result).to be_success+ expect(row.reload.user_id).to eq(first_member.id)+ end++ it 'keeps the link against a blank user_id' do+ save(user_id: '', lock_version: row.lock_version, id: row.id)++ expect(row.reload.user_id).to eq(first_member.id)+ end++ it 'takes name and email from the request' do+ save(name: 'Eigener Name', email: '[email protected]', lock_version: row.lock_version, id: row.id)++ expect([row.reload.name, row.email]).to eq(['Eigener Name', '[email protected]'])+ end+ end+# Review of S1 (28.10.2026): the form locks name, email and the link of an# active member's row and does not send them. A hand-made request must not# write them either: the name would surface once the member leaves, and a new