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 review round 4 of the people page

Guido Boyke9bd2986a234a
diff --git a/app/assets/stylesheets/application.tailwind.css b/app/assets/stylesheets/application.tailwind.css
index 9602c1a..f1b0e1d 100644
--- a/app/assets/stylesheets/application.tailwind.css
+++ b/app/assets/stylesheets/application.tailwind.css
@@ -474,6 +474,7 @@
.people-form__field { @apply flex flex-col gap-1; }
.people-form__field label { @apply text-xs text-muted; }
.people-form__required { color: #A03227; }
+ .dark .people-form__required { color: var(--wash-danger-text); }
.people-input { @apply box-border w-full rounded-lg border border-cream-400 bg-surface-raised px-2.5 py-2 text-sm text-heading focus:border-ink focus:outline-none focus:ring-1 focus:ring-ink; }
.people-input--area { @apply resize-y leading-normal; }
.people-input--locked { @apply bg-cream-100 text-cream-700; }
diff --git a/app/controllers/organisations/people_controller.rb b/app/controllers/organisations/people_controller.rb
index af9ba83..a59c799 100644
--- a/app/controllers/organisations/people_controller.rb
+++ b/app/controllers/organisations/people_controller.rb
@@ -33,7 +33,9 @@ module Organisations
rescue_from Pundit::NotAuthorizedError, with: :render_forbidden
- before_action :set_viewport_mode, only: :index
+ # Every action: the lane frames (show, member, new, edit) render the phone
+ # layout too, and only the address knows which one.
+ before_action :set_viewport_mode
before_action :set_person, only: %i[show edit update destroy]
def index
@@ -41,6 +43,9 @@ module Organisations
@people = policy_scope(Person)
return render_lane_frame if lane_frame_request?
+ member_row = member_with_row
+ return redirect_to(index_path(person_id: member_row.id)) if member_row
+
load_list
@lane_person = selected_person
@lane_member = selected_member if @lane_person.nil?
@@ -157,6 +162,14 @@ 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.
+ def member_with_row
+ id = params[:member_id]
+ return unless id.is_a?(String) && id.present? && params[:person_id].blank?
+
+ directory.member_entry(id)&.person
+ end
+
# ?member_id=: the account of a visible member without a row. A member who
# has a row is opened through that row (person_id), never twice.
def selected_member
@@ -235,6 +248,14 @@ module Organisations
organisation_people_path(current_organisation, list_state.merge(lane.stringify_keys).compact_blank)
end
+ # The accounts the reader may see on the members page (MembershipPolicy::
+ # Scope), once per request: who created or changed a row is named only
+ # when the reader may see them (PeopleHelper#person_actor_name).
+ def people_visible_member_ids
+ @people_visible_member_ids ||= policy_scope(Membership).where(organisation: current_organisation).pluck(:user_id).to_set
+ end
+ helper_method :people_visible_member_ids
+
# 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. The
# phone view rides along (viewport=mobile): without it a refused save or a
diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rb
index 05fa411..5307429 100644
--- a/app/helpers/people_helper.rb
+++ b/app/helpers/people_helper.rb
@@ -145,10 +145,21 @@ module PeopleHelper
name.to_s.split.first(2).map { |part| part[0] }.join.upcase
end
+ # The name of whoever created or changed a row, only when the reader may see
+ # that person on the members page (MembershipPolicy::Scope, the rule the
+ # whole directory follows); otherwise "Jemand". The reader always sees
+ # themselves.
+ def person_actor_name(user)
+ return t('views.organisations.people.show.someone') unless user
+
+ visible = user.id == current_user.id || people_visible_member_ids.include?(user.id)
+ visible ? viewer_display_name(user) : t('views.organisations.people.show.someone')
+ end
+
# One line of the history: who did what. An update names the changed fields
# (never their values, PersonTrackable).
def person_history_line(activity)
- actor = viewer_display_name(activity.actor)
+ actor = person_actor_name(activity.actor)
case activity.action
when 'created' then t('views.organisations.people.history.created', actor: actor)
when 'updated'
diff --git a/app/views/organisations/people/_bare_hint.html.erb b/app/views/organisations/people/_bare_hint.html.erb
index a215c89..7abb20c 100644
--- a/app/views/organisations/people/_bare_hint.html.erb
+++ b/app/views/organisations/people/_bare_hint.html.erb
@@ -3,7 +3,7 @@
add it to those who may write. %>
<div class="people-callout people-callout--quiet">
<div class="people-callout__body">
- <p><%= t('views.organisations.people.show.bare_text', first_name: member.first_name.presence || viewer_display_name(member)) %></p>
+ <p><%= t('views.organisations.people.show.bare_text', first_name: viewer_display_name(member)) %></p>
<% if url || link %>
<%= link_to(link ? link[:href] : url, class: 'people-secondary-action', data: link&.dig(:data)) do %>
<i class="bi bi-pencil" aria-hidden="true"></i><%= t('views.organisations.people.show.add_details') %>
diff --git a/app/views/organisations/people/_detail.html.erb b/app/views/organisations/people/_detail.html.erb
index da2a5f3..b44f25b 100644
--- a/app/views/organisations/people/_detail.html.erb
+++ b/app/views/organisations/people/_detail.html.erb
@@ -53,7 +53,7 @@
<div class="people-footer">
<p class="people-footer__created">
<% if person.creator %>
- <%= t('views.organisations.people.show.created_by', name: viewer_display_name(person.creator), date: l(person.created_at.to_date, format: :default)) %>
+ <%= t('views.organisations.people.show.created_by', name: person_actor_name(person.creator), date: l(person.created_at.to_date, format: :default)) %>
<% else %>
<%= t('views.organisations.people.show.created_at', date: l(person.created_at.to_date, format: :default)) %>
<% end %>
diff --git a/app/views/organisations/people/_list_head.html.erb b/app/views/organisations/people/_list_head.html.erb
index 0fc0d8c..501de97 100644
--- a/app/views/organisations/people/_list_head.html.erb
+++ b/app/views/organisations/people/_list_head.html.erb
@@ -24,7 +24,10 @@
<h1 class="people-head__h1"><%= t('views.organisations.people.index.title') %></h1>
<% end %>
<p class="people-head__count">
- <%= t('views.organisations.people.index.count_line', count: counts['all'], members: counts['members'], contacts: counts['contacts']) %>
+ <%= t('views.organisations.people.index.count_line',
+ people: t('views.organisations.people.index.count_people', count: counts['all']),
+ members: t('views.organisations.people.index.count_members', count: counts['members']),
+ contacts: t('views.organisations.people.index.count_contacts', count: counts['contacts'])) %>
</p>
</div>
<% if policy(Person).create? && mobile %>
diff --git a/config/locales/views/personen.de.yml b/config/locales/views/personen.de.yml
index 9420768..83b726a 100644
--- a/config/locales/views/personen.de.yml
+++ b/config/locales/views/personen.de.yml
@@ -16,9 +16,16 @@ de:
people:
index:
title: "Personen"
- count_line:
- one: "%{count} Person · %{members} Mitglieder, %{contacts} Kontakte"
- other: "%{count} Personen · %{members} Mitglieder, %{contacts} Kontakte"
+ count_line: "%{people} · %{members}, %{contacts}"
+ count_people:
+ one: "%{count} Person"
+ other: "%{count} Personen"
+ count_members:
+ one: "%{count} Mitglied"
+ other: "%{count} Mitglieder"
+ count_contacts:
+ one: "%{count} Kontakt"
+ other: "%{count} Kontakte"
new_person: "Person anlegen"
search_label: "Personen durchsuchen"
search_placeholder: "Name, Funktion oder Firma"
@@ -56,6 +63,7 @@ de:
add_details: "Angaben ergänzen"
call: "anrufen"
created_by: "Angelegt von %{name} am %{date}"
+ someone: "Jemand"
created_at: "Angelegt am %{date}"
from_account: "Aus dem Konto übernommen am %{date}"
read_only: "Du kannst Personen ansehen, aber nicht bearbeiten."
diff --git a/config/locales/views/personen.en.yml b/config/locales/views/personen.en.yml
index af14cdd..df5e74f 100644
--- a/config/locales/views/personen.en.yml
+++ b/config/locales/views/personen.en.yml
@@ -16,9 +16,16 @@ en:
people:
index:
title: "People"
- count_line:
- one: "%{count} person · %{members} members, %{contacts} contacts"
- other: "%{count} people · %{members} members, %{contacts} contacts"
+ count_line: "%{people} · %{members}, %{contacts}"
+ count_people:
+ one: "%{count} person"
+ other: "%{count} people"
+ count_members:
+ one: "%{count} member"
+ other: "%{count} members"
+ count_contacts:
+ one: "%{count} contact"
+ other: "%{count} contacts"
new_person: "Add person"
search_label: "Search people"
search_placeholder: "Name, function or company"
@@ -56,6 +63,7 @@ en:
add_details: "Add details"
call: "call"
created_by: "Added by %{name} on %{date}"
+ someone: "Someone"
created_at: "Added on %{date}"
from_account: "Taken from the account on %{date}"
read_only: "You can view people, but not edit them."
diff --git a/spec/requests/organisations/people_spec.rb b/spec/requests/organisations/people_spec.rb
index 7670e2d..3f92ac7 100644
--- a/spec/requests/organisations/people_spec.rb
+++ b/spec/requests/organisations/people_spec.rb
@@ -633,7 +633,7 @@ RSpec.describe 'Organisations::People', :ci_guard, type: :request do
get organisation_people_path(organisation, member_id: colleague.id)
- expect(response.body).to include('show-content', I18n.t('views.organisations.people.show.bare_text', first_name: 'Kolja'))
+ expect(response.body).to include('show-content', CGI.escapeHTML(I18n.t('views.organisations.people.show.bare_text', first_name: colleague.display_name)))
expect(response.body).to match(/class="people-row selected-row"[^>]*>|data-list-row-id-value="#{colleague.id}"[^>]*class="people-row selected-row"/)
end
@@ -654,7 +654,11 @@ RSpec.describe 'Organisations::People', :ci_guard, type: :request do
get organisation_people_path(organisation, kind: 'contacts')
members = Membership.where(organisation: organisation, active: true).count
- expect(response.body).to include(I18n.t('views.organisations.people.index.count_line', count: members + 1, members: members, contacts: 1))
+ scope = 'views.organisations.people.index'
+ line = I18n.t("#{scope}.count_line", people: I18n.t("#{scope}.count_people", count: members + 1),
+ members: I18n.t("#{scope}.count_members", count: members),
+ contacts: I18n.t("#{scope}.count_contacts", count: 1))
+ expect(response.body).to include(line)
end
describe 'the row of an active member' do
@@ -744,6 +748,106 @@ RSpec.describe 'Organisations::People', :ci_guard, type: :request do
expect(response.body).to match(/class="person-content/)
end
+ # Review round 4.
+ describe 'names of members the reader cannot see' do
+ let(:project) { create(:project, organisation: organisation) }
+ let(:hidden_writer) { member_with(role_with('manage_people'), first_name: 'Geheim') }
+
+ before do
+ create(:project_permission, user: manager, project: project, tickets_access: :read_only)
+ create(:project_permission, user: hidden_writer, project: create(:project, organisation: organisation),
+ tickets_access: :read_only)
+ end
+
+ it 'shows neither the creator nor the editor by name' do
+ row = Current.set(user: hidden_writer) { create(:person, organisation: organisation, creator: hidden_writer) }
+ Current.set(user: hidden_writer) { row.update!(phone: '1') }
+ sign_in manager
+
+ get organisation_person_path(organisation, row), headers: frame_headers
+
+ expect(response).to have_http_status(:ok)
+ expect(response.body).not_to include('Geheim')
+ expect(response.body).to include(I18n.t('views.organisations.people.history.updated', actor: I18n.t('views.organisations.people.show.someone'),
+ fields: Person.human_attribute_name(:phone)))
+ end
+ end
+
+ it 'keeps the phone view in a lane frame (show after "Abbrechen")' do
+ sign_in admin
+
+ get organisation_person_path(organisation, person, viewport: 'mobile'), headers: frame_headers
+
+ expect(response.body).not_to include('data-lane-close')
+ end
+
+ it 'counts with the right singular and plural forms' do
+ sign_in admin
+ get organisation_people_path(organisation)
+
+ expect(response.body).to match(/1 Kontakt(?!e)/)
+ expect(response.body).not_to include('1 Kontakte')
+ end
+
+ it 'names the member of the hint through the name display setting' do
+ reader = admin
+ reader.preference_store.set!('name_display', 'initial_last')
+ member = member_with(role_with, first_name: 'Carla')
+ sign_in reader
+
+ get member_organisation_people_path(organisation, member.id), headers: frame_headers
+
+ expect(response.body).not_to include('wofür Carla')
+ end
+
+ it 'shows the member select again when a new row asks for a member who has one' do
+ taken = member_with(role_with, first_name: 'Vergeben')
+ create(:person, organisation: organisation, user: taken)
+ sign_in admin
+
+ post organisation_people_path(organisation), params: { person: { name: 'X', user_id: taken.id } }
+
+ expect(response).to have_http_status(:unprocessable_content)
+ expect(response.body).to include('name="person[user_id]"')
+ expect(response.body).not_to include(%(type="hidden" value="#{taken.id}"))
+ end
+
+ it 'opens no form for ?new=person without the right to write' do
+ sign_in viewer
+
+ get organisation_people_path(organisation, new: 'person')
+
+ expect(response.body).not_to include('id="person_name"')
+ end
+
+ it 'sends ?member_id= of a member with a row to that row' do
+ row = create(:person, organisation: organisation, user: viewer)
+ sign_in admin
+
+ get organisation_people_path(organisation, member_id: viewer.id)
+
+ expect(response).to redirect_to(organisation_people_path(organisation, person_id: row.id))
+ end
+
+ it 'answers a lane request of the index with the member lane' do
+ member = member_with(role_with, first_name: 'Lena')
+ sign_in admin
+
+ get organisation_people_path(organisation, member_id: member.id), headers: frame_headers
+
+ expect(response.body).to include(I18n.t('views.organisations.people.show.add_details'), member.email)
+ end
+
+ it 'shows the account email of an active member in the lane, not an old row email' do
+ row = create(:person, organisation: organisation, user: viewer, email: '[email protected]')
+ sign_in admin
+
+ get organisation_person_path(organisation, row), headers: frame_headers
+
+ expect(response.body).to include(viewer.email)
+ expect(response.body).not_to include('[email protected]')
+ end
+
it 'has no missing translation on the page' do
sign_in admin
get organisation_people_path(organisation, person_id: person.id)