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.

Keep a deactivated member's row hidden and the account fields locked

Guido Boyke3dc5305b2b91
diff --git a/app/controllers/organisations/people_controller.rb b/app/controllers/organisations/people_controller.rb
index 9be3041..fb2e3e9 100644
--- a/app/controllers/organisations/people_controller.rb
+++ b/app/controllers/organisations/people_controller.rb
@@ -164,10 +164,15 @@ module Organisations
entry.person ? { person_id: entry.person.id } : { member_id: entry.user.id }
end
- # ?member_id= of a member who has a row by now: the row is the address.
+ # A member who has a row by now, named by ?member_id= or by the form for a
+ # new row (?new=person&user_id=): the row is the address, in the lane and on
+ # a full visit alike (review of S1, 28.10.2026: Back after "Angaben
+ # ergänzen" asked the lane for the old address and got an empty form).
def member_with_row
- id = params[:member_id]
- return unless id.is_a?(String) && id.present? && params[:person_id].blank?
+ return if params[:person_id].present?
+
+ id = params[:member_id].presence || (params[:user_id] if params[:new] == NEW_STATE)
+ return unless id.is_a?(String) && id.present?
directory.member_entry(id)&.person
end
@@ -214,7 +219,7 @@ module Organisations
# The lane alone, as a full visit of the same address shows it.
def render_lane_frame
- person = selected_person
+ person = selected_person || member_with_row
member = selected_member unless person
if person
render_frame(:detail, person: person)
diff --git a/app/models/CLAUDE.md b/app/models/CLAUDE.md
index 5212bd1..b5f2309 100644
--- a/app/models/CLAUDE.md
+++ b/app/models/CLAUDE.md
@@ -1,4 +1,4 @@
-# Karte: app/models (Stand: 2026-10-27)
+# Karte: app/models (Stand: 2026-10-28)
~80 Modelle liegen flach in diesem Verzeichnis; Namespaces existieren nur für `admin/`,
`knowledge/`, `overview/`, `smart_folders/`, `time_sessions/`, `user/`. Die Domänen-Zugehörigkeit ist am
@@ -53,6 +53,12 @@ Verzeichnis-Layout nicht ablesbar — diese Karte gruppiert sie:
`view_people`/`manage_people`, gastrollen-tauglich), Kontoadmins ohne Zeile; die Policy
prüft die aktive Mitgliedschaft selbst. Lesen über `People::Directory`, Schreiben über
`Actors::SavePerson`/`DestroyPerson`.
+ Sichtbarkeit (Review von S1, 28.10.2026): Die Zeile eines Mitglieds, das der Leser auf der
+ 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
+ in `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 eine
anonyme `person.deleted`-Zeile. ⚠️ `concerns/person_link_release.rb` steht in `membership`
diff --git a/app/models/permission.rb b/app/models/permission.rb
index 8ffdfc8..40786e6 100644
--- a/app/models/permission.rb
+++ b/app/models/permission.rb
@@ -96,14 +96,28 @@ class Permission < ApplicationRecord
# The shared people directory of the organisation (Person). Its own category
# for the same reason as :assistant: customer roles are billable: false and
# must be able to keep the list, which an action under :projects would
- # forbid. manage_people (create, edit, delete, link) implies view_people in
- # PersonPolicy. No role gets either automatically; account admins need none.
+ # forbid. manage_people (create, edit, delete, link) implies view_people
+ # (IMPLIED_BY). No role gets either automatically; account admins need none.
people: %w[
view_people
manage_people
]
}.freeze
+ # A right that another right includes: [category, action] => the actions of
+ # the same category that grant it too. Asked by PersonPolicy (who may view)
+ # and RolePolicy#change_permission? (who may grant it), so the two cannot
+ # disagree.
+ IMPLIED_BY = {
+ %w[people view_people] => %w[manage_people]
+ }.freeze
+
+ # The actions of a category that grant [category, action]: itself and every
+ # action that includes it.
+ def self.granting_actions(category, action)
+ [action, *IMPLIED_BY.fetch([category.to_s, action.to_s], [])]
+ end
+
validates :category, inclusion: { in: CATEGORIES.keys.map(&:to_s) }
validate :validate_action_for_category
# Guest-Ceiling Verbotsliste (Plan doc/billing_agentur_konto_plan.md §4.3,
diff --git a/app/policies/person_policy.rb b/app/policies/person_policy.rb
index a732e41..2cd93ae 100644
--- a/app/policies/person_policy.rb
+++ b/app/policies/person_policy.rb
@@ -11,20 +11,22 @@
# membership.active (same reason as ChatPolicy.assistant_gate_open?).
class PersonPolicy < ApplicationPolicy
class Scope < ApplicationPolicy::Scope
- # The rows of this organisation, minus the rows linked to an active member
- # the viewer may not see on the members page (MembershipPolicy::Scope). A
- # row linked to a former or deactivated member is shown, as a contact: its
- # data is the row's own. Nothing without the right.
+ # The rows of this organisation, minus the rows linked to a member the
+ # viewer may not see on the members page (MembershipPolicy::Scope). That
+ # holds for a deactivated member too: deactivating can be undone, and until
+ # then the row stays as hidden as the member was (review of S1, 28.10.2026).
+ # A row whose member was removed lost its account (PersonLinkRelease) and is
+ # a contact of the organisation. Nothing without the right.
def resolve
return scope.none unless organisation && PersonPolicy.view_allowed?(user, organisation)
people = scope.where(organisation: organisation)
return people if user.account_admin_in?(organisation)
- active_member_ids = Membership.where(organisation: organisation, active: true).select(:user_id)
+ member_ids = Membership.where(organisation: organisation).select(:user_id)
visible_member_ids = MembershipPolicy::Scope.new(user, Membership).resolve.select(:user_id)
people.where(user_id: nil)
- .or(people.where.not(user_id: active_member_ids))
+ .or(people.where.not(user_id: member_ids))
.or(people.where(user_id: visible_member_ids))
end
end
@@ -33,8 +35,9 @@ class PersonPolicy < ApplicationPolicy
return false unless user.active_member_of_organisation?(organisation)
user.account_admin_in?(organisation) ||
- user.has_permission_in_organisation?(organisation, 'people', 'view_people') ||
- user.has_permission_in_organisation?(organisation, 'people', 'manage_people')
+ Permission.granting_actions('people', 'view_people').any? do |action|
+ user.has_permission_in_organisation?(organisation, 'people', action)
+ end
end
def self.manage_allowed?(user, organisation)
diff --git a/app/policies/role_policy.rb b/app/policies/role_policy.rb
index 63161fd..0848c26 100644
--- a/app/policies/role_policy.rb
+++ b/app/policies/role_policy.rb
@@ -40,7 +40,7 @@ class RolePolicy < ApplicationPolicy
# too: a manager must not strip other roles of rights beyond their own reach.
# Enforced by Actors::SaveRole for every right the form actually changes.
def change_permission?(category, action)
- account_admin? || has_permission?(category, action)
+ account_admin? || Permission.granting_actions(category, action).any? { |granting| has_permission?(category, granting) }
end
def destroy?
diff --git a/app/services/actors/save_person.rb b/app/services/actors/save_person.rb
index f89464c..600aa66 100644
--- a/app/services/actors/save_person.rb
+++ b/app/services/actors/save_person.rb
@@ -9,6 +9,10 @@
# members the writer may see (MembershipPolicy::Scope, active only), never
# assigned as given. Linking copies the member's name into the row, so the
# row keeps a name when the link goes (PersonLinkRelease).
+# * 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.
# * 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
@@ -18,6 +22,8 @@
module Actors
class SavePerson < BaseActor
ATTRIBUTES = %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
# lock_version is an integer column (4 bytes).
LOCK_VERSION_RANGE = (0..((2**31) - 1))
@@ -37,6 +43,8 @@ module Actors
raise 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?
+ @params = @params.except(:email) if @person.new_record? && @params[:user_id].present?
attributes = @params.slice(*ATTRIBUTES)
attributes.delete(:lock_version) if @person.new_record?
@person.assign_attributes(attributes)
@@ -69,6 +77,12 @@ module Actors
raise 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?
+ end
+
# Tenant-bound lookup: an id of another organisation is no person at all.
def find_person(id)
return @organisation.people.build if id.blank?
diff --git a/app/services/people/directory.rb b/app/services/people/directory.rb
index ba83ec2..65803e9 100644
--- a/app/services/people/directory.rb
+++ b/app/services/people/directory.rb
@@ -208,9 +208,11 @@ module People
@people ||= PersonPolicy::Scope.new(@viewer, Person).resolve
end
+ # A member's email is the account's; an email left on a member row is not
+ # shown, so it is not searched either.
def matches?(entry)
- haystack = [entry.plain_name, entry.person&.function, entry.person&.department, entry.person&.company,
- entry.person&.email, entry.user&.email]
+ email = entry.member? ? entry.user.email : entry.person&.email
+ haystack = [entry.plain_name, entry.person&.function, entry.person&.department, entry.person&.company, email]
haystack.any? { |value| value.present? && PersonName.normalize(value).include?(@query) }
end
end
diff --git a/spec/policies/person_policy_spec.rb b/spec/policies/person_policy_spec.rb
index ed8a543..1eb996b 100644
--- a/spec/policies/person_policy_spec.rb
+++ b/spec/policies/person_policy_spec.rb
@@ -114,11 +114,32 @@ RSpec.describe PersonPolicy, :ci_guard, type: :policy do
expect([policy.update?, policy.destroy?]).to eq([false, false])
end
- it 'shows a row linked to a former member as a contact' do
- former_row = create(:person, organisation: organisation, user: stranger)
+ # Deactivating can be undone: until then, the row stays as hidden as the
+ # member was (review of S1, decision A, 28.10.2026). It is the same person.
+ it 'keeps the row of a deactivated member hidden from a viewer who cannot see them' do
+ stranger_row = create(:person, organisation: organisation, user: stranger)
Membership.find_by(user: stranger, organisation: organisation).update!(active: false)
- expect(rows(viewer)).to include(former_row)
+ expect(rows(viewer)).not_to include(stranger_row)
+ expect(rows(admin)).to include(stranger_row)
+ expect(described_class.new(User.find(viewer.id), stranger_row).show?).to be(false)
+ end
+
+ it 'shows the row of a deactivated member to a viewer who can see them' do
+ colleague_row = create(:person, organisation: organisation, user: colleague)
+ Membership.find_by(user: colleague, organisation: organisation).update!(active: false)
+
+ expect(rows(viewer)).to include(colleague_row)
+ end
+
+ # Removed from the organisation, the row lost its account (PersonLinkRelease)
+ # and is a contact of the organisation like any other.
+ it 'shows the row of a removed member as a contact' do
+ stranger_row = create(:person, organisation: organisation, user: stranger)
+ Membership.find_by(user: stranger, organisation: organisation).destroy!
+
+ expect(stranger_row.reload.user_id).to be_nil
+ expect(rows(viewer)).to include(stranger_row)
end
it 'returns nothing without the right' do
diff --git a/spec/policies/role_policy_spec.rb b/spec/policies/role_policy_spec.rb
index cb5b8a1..4f6d77f 100644
--- a/spec/policies/role_policy_spec.rb
+++ b/spec/policies/role_policy_spec.rb
@@ -306,4 +306,35 @@ RSpec.describe RolePolicy, :ci_guard, type: :policy do
expect(described_class.new(user, target_role).update_billable?).to be false
end
end
+
+ # Review of S1 (28.10.2026): manage_people includes view_people
+ # (Permission::IMPLIED_BY), so a role editor holding it may grant both.
+ describe '#change_permission?' do
+ def editor_with(*rights)
+ role = create(:role, organisation: organisation)
+ create(:permission, role: role, category: 'accounts', action: 'add_edit_delete_roles', allowed: true)
+ rights.each { |category, action| create(:permission, role: role, category: category, action: action, allowed: true) }
+ user = create(:user)
+ create(:membership, user: user, organisation: organisation, role: role)
+ User.find(user.id)
+ end
+
+ def may_change?(user, category, action)
+ ActsAsTenant.with_tenant(organisation) { described_class.new(user, regular_role).change_permission?(category, action) }
+ end
+
+ it 'lets an editor with manage_people change view_people too' do
+ editor = editor_with(%w[people manage_people])
+
+ expect(may_change?(editor, 'people', 'view_people')).to be(true)
+ expect(may_change?(editor, 'people', 'manage_people')).to be(true)
+ end
+
+ it 'does not turn view_people into manage_people' do
+ editor = editor_with(%w[people view_people])
+
+ expect(may_change?(editor, 'people', 'view_people')).to be(true)
+ expect(may_change?(editor, 'people', 'manage_people')).to be(false)
+ end
+ end
end
diff --git a/spec/requests/organisations/people_spec.rb b/spec/requests/organisations/people_spec.rb
index 3f92ac7..7ff0138 100644
--- a/spec/requests/organisations/people_spec.rb
+++ b/spec/requests/organisations/people_spec.rb
@@ -479,13 +479,14 @@ RSpec.describe 'Organisations::People', :ci_guard, type: :request do
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.
+ # 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
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)
+ create(:project_permission, user: hidden, project: project, 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')
@@ -848,6 +849,65 @@ RSpec.describe 'Organisations::People', :ci_guard, type: :request do
expect(response.body).not_to include('[email protected]')
end
+ # Review of S1 (28.10.2026).
+ describe 'review of S1' do
+ let(:project) { create(:project, organisation: organisation) }
+
+ it 'names a visible creator and the reader themselves' do
+ create(:project_permission, user: manager, project: project, tickets_access: :read_only)
+ colleague = member_with(role_with('manage_people'), first_name: 'Sichtbar')
+ create(:project_permission, user: colleague, project: project, tickets_access: :read_only)
+ row = Current.set(user: colleague) { create(:person, organisation: organisation, creator: colleague) }
+ Current.set(user: manager) { row.update!(phone: '1') }
+ sign_in manager
+
+ get organisation_person_path(organisation, row), headers: frame_headers
+
+ expect(response.body).to include('Sichtbar')
+ expect(response.body).to include(I18n.t('views.organisations.people.history.updated',
+ actor: User.find(manager.id).display_name, fields: Person.human_attribute_name(:phone)))
+ end
+
+ # Decision A: deactivating keeps a row as hidden as the member was.
+ it 'keeps the row of a deactivated member the reader cannot see out of list and lane' do
+ create(:project_permission, user: viewer, project: project, tickets_access: :read_only)
+ hidden = member_with(role_with, first_name: 'Versteckt')
+ create(:project_permission, user: hidden, project: create(:project, organisation: organisation), tickets_access: :read_only)
+ row = create(:person, organisation: organisation, user: hidden, name: 'Versteckt Mitglied', notes: 'GEHEIMNOTIZ')
+ Membership.where(user: hidden, organisation: organisation).update_all(active: false)
+ sign_in viewer
+
+ get organisation_people_path(organisation)
+ expect(response.body).to include('Doris Dienstleister')
+ expect(response.body).not_to include('Versteckt Mitglied')
+
+ # Only the status: the test 404 page shows the spec source, which names the note.
+ get organisation_person_path(organisation, row), headers: frame_headers
+ expect(response).to have_http_status(:not_found)
+ end
+
+ it 'answers a lane request with ?member_id= of a member with a row by that row, as a full visit does' do
+ create(:person, organisation: organisation, user: viewer, phone: '+49 30 7654321')
+ sign_in admin
+
+ get organisation_people_path(organisation, member_id: viewer.id), headers: frame_headers
+
+ expect(response.body).to include('+49 30 7654321')
+ end
+
+ it 'opens the row of a member who has one for ?new=person&user_id=, in the lane and on a full visit' do
+ row = create(:person, organisation: organisation, user: viewer, phone: '+49 30 7654321')
+ sign_in admin
+
+ get organisation_people_path(organisation, new: 'person', user_id: viewer.id), headers: frame_headers
+ expect(response.body).to include('+49 30 7654321')
+ expect(response.body).not_to include('id="person_name"')
+
+ get organisation_people_path(organisation, new: 'person', user_id: viewer.id)
+ expect(response).to redirect_to(organisation_people_path(organisation, person_id: row.id))
+ end
+ 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/actors/save_person_spec.rb b/spec/services/actors/save_person_spec.rb
index 5228f8a..570a7c3 100644
--- a/spec/services/actors/save_person_spec.rb
+++ b/spec/services/actors/save_person_spec.rb
@@ -56,9 +56,11 @@ RSpec.describe Actors::SavePerson do
expect(result.resource.name).to eq(user.display_name)
end
- it 'drops a link when user_id is blank' do
+ # 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
user = member
person = save(name: 'x', user_id: user.id).resource
+ Membership.where(user: user, organisation: organisation).update_all(active: false)
save(user_id: '', lock_version: person.lock_version, id: person.id)
@@ -66,6 +68,38 @@ RSpec.describe Actors::SavePerson do
expect(person.name).to eq(user.display_name)
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
+ # user_id would carry the first member's phone and notes over to another.
+ describe 'the row of an active member' do
+ let(:first_member) { member }
+ let(:second_member) { member }
+ let!(:row) { save(name: 'egal', user_id: first_member.id, phone: '1').resource }
+
+ it 'keeps name, email and link against a hand-made request' do
+ result = save(name: 'Gefaelscht', email: '[email protected]', user_id: second_member.id, phone: '2',
+ lock_version: row.lock_version, id: row.id)
+
+ expect(result).to be_success
+ row.reload
+ expect([row.name, row.email, row.user_id, row.phone]).to eq([first_member.display_name, nil, first_member.id, '2'])
+ 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 no email when the row is created for the member' do
+ other = member
+ created = save(name: 'egal', email: '[email protected]', user_id: other.id).resource
+
+ expect(created.email).to be_nil
+ end
+ end
+
it 'refuses a raw user_id the writer may not link (another organisation)' do
foreign = member(org: other_organisation)
diff --git a/spec/services/people/directory_spec.rb b/spec/services/people/directory_spec.rb
index 1fe82c6..e873e60 100644
--- a/spec/services/people/directory_spec.rb
+++ b/spec/services/people/directory_spec.rb
@@ -70,6 +70,27 @@ RSpec.describe People::Directory, :ci_guard do
expect(list.count { |item| item.user == colleague }).to eq(0)
end
+ # Review of S1 (28.10.2026): a contact row keeps the name it was saved with.
+ # Search and order read that name, never the account's current one, so the
+ # search cannot tell which account a former member's row belonged to.
+ it 'searches and sorts the row of a deactivated member by the row name, not the account name' do
+ row = create(:person, organisation: organisation, user: colleague, name: 'Carl Kollege')
+ Membership.find_by(user: colleague, organisation: organisation).update!(active: false)
+ colleague.update!(first_name: 'Zacharias', last_name: 'Umbenannt')
+
+ expect(names(entries(query: 'zacharias'))).to eq([])
+ expect(entries(query: 'kollege').map(&:person)).to eq([row])
+ expect(names(entries)).to eq(['Carl Kollege', 'Doris Dienstleister', 'Vera Viewer'])
+ end
+
+ # The email of a member is the account's; a row email left on a member row is
+ # not shown, so it must not be searchable either.
+ it 'does not search the row email of a member row' do
+ create(:person, organisation: organisation, user: colleague, email: '[email protected]')
+
+ expect(names(entries(query: 'versteckt'))).to eq([])
+ end
+
# One directory per example: each call resolves the viewer's reach once, and
# Prosopite would read a second call as an N+1.
{