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 1 of the last contact
Guido Boyke9b48d45af056
diff --git a/app/controllers/organisations/people_controller.rb b/app/controllers/organisations/people_controller.rbindex 4e1fbb8..9be3041 100644--- a/app/controllers/organisations/people_controller.rb+++ b/app/controllers/organisations/people_controller.rb@@ -266,6 +266,7 @@ module Organisationsdef list_stategiven = request.query_parameters.merge(request.request_parameters)state = given.slice(*LIST_PARAMS).select { |_key, value| value.is_a?(String) && value.present? }+ state.delete('sort') unless People::Directory::SORTS.include?(state['sort'])state['viewport'] = 'mobile' if given['viewport'] == 'mobile'stateenddiff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rbindex 86a76b1..e450bea 100644--- a/app/helpers/people_helper.rb+++ b/app/helpers/people_helper.rb@@ -204,11 +204,14 @@ module PeopleHelperend# The words of a last contact (People::Contacts::LastContact): the last- # meeting with its date, or the ticket work with its age.+ # meeting with its date (with the year when it is not this year), or the+ # ticket work with its age.def last_contact_text(last)scope = 'views.organisations.people.last_contact'if last.kind == :meeting- t("#{scope}.meeting", title: last.meeting_title, date: l(last.at.to_date, format: :short))+ date = last.at.to_date+ t("#{scope}.meeting", title: last.meeting_title,+ date: l(date, format: date.year == Time.zone.today.year ? :short : :default))elset("#{scope}.ticket.#{last.action}", number: last.ticket_number, age: last_contact_age(last.at))end@@ -219,9 +222,8 @@ module PeopleHelper# of a former member only its meetings.def person_contacts(person: nil, member: nil)contacts = People::Contacts.new(viewer: current_user, organisation: current_organisation)- subject = People::Contacts::Subject.new(person_id: person&.id, user_id: member&.id || person&.user_id,- member: member.present?)meetings = contacts.meetings_for(person: person, user: member).includes(:project)- { last: contacts.last_contacts([subject]).first, meetings: meetings }+ { last: contacts.last_contacts([People::Contacts::Subject.for(person: person, member: member)]).first,+ meetings: meetings }endenddiff --git a/app/services/people/contacts.rb b/app/services/people/contacts.rbindex ce944c1..d1d2301 100644--- a/app/services/people/contacts.rb+++ b/app/services/people/contacts.rb@@ -10,7 +10,8 @@ module People# A member without a row of their own has meetings through user_id alone.# * Readable means MeetingPolicy::Scope and TicketPolicy::Scope, the rules of# "Alle Meetings" and the ticket list; no rule of its own next to them.- # * The last contact (E3) is the newest readable meeting; for an active+ # * The last contact (E3) is the newest readable meeting that took place;+ # for an active# member also their own work on a readable ticket (created, changed,# commented), whichever is newer. A comment the viewer may not read# (Post.readable_by) does not count, nor does a bulk run (Activity.feed).@@ -37,7 +38,14 @@ module People# One entry of the directory: its person row, its account, and whether the# account is an active member (only then does ticket work count).- Subject = Struct.new(:person_id, :user_id, :member, keyword_init: true)+ Subject = Struct.new(:person_id, :user_id, :member, keyword_init: true) do+ # The one rule for the list and the lane: pass the active member's+ # account as member:, never for a row of a former member, whose account+ # still finds its meetings through the row's user_id.+ def self.for(person:, member:)+ new(person_id: person&.id, user_id: member&.id || person&.user_id, member: member.present?)+ end+ end# The participant column a meeting lookup reads, by name; never interpolated# from a caller.@@ -84,14 +92,15 @@ module People@readable_tickets ||= TicketPolicy::Scope.new(@viewer, Ticket).resolveend- # The newest readable meeting per person row or per account.+ # The newest readable meeting per person row or per account. A meeting+ # still to come is listed in the lane but is no contact yet.def latest_meetings(key, ids)return {} if ids.empty?column = PARTICIPANT_COLUMNS.fetch(key)rows = MeetingParticipant.where(meeting_id: readable_meetings.select(:id)).where(key == :person ? { person_id: ids } : { user_id: ids })- .joins(:meeting)+ .joins(:meeting).where(meetings: { occurred_at: ..Time.current }).select(Arel.sql("DISTINCT ON (#{column}) #{column} AS subject_id, " \'meetings.title AS meeting_title, meetings.occurred_at AS met_at')).order(Arel.sql("#{column}, meetings.occurred_at DESC, meetings.id DESC"))diff --git a/app/services/people/directory.rb b/app/services/people/directory.rbindex 4be504d..120457d 100644--- a/app/services/people/directory.rb+++ b/app/services/people/directory.rb@@ -57,9 +57,7 @@ module People# The one subject People::Contacts asks about for an entry: a member counts# their own ticket work, a contact (also a former member) only meetings.def self.contact_subject(entry)- People::Contacts::Subject.new(person_id: entry.person&.id,- user_id: entry.member? ? entry.user.id : entry.person&.user_id,- member: entry.member?)+ People::Contacts::Subject.for(person: entry.person, member: (entry.user if entry.member?))end# How many people the page holds, before search and filter: the head linediff --git a/app/views/organisations/people/_results.html.erb b/app/views/organisations/people/_results.html.erbindex fff9d16..950ded7 100644--- a/app/views/organisations/people/_results.html.erb+++ b/app/views/organisations/people/_results.html.erb@@ -5,19 +5,22 @@without a row through member_id. The two column heads sort the list(?sort=last, E5), a full visit that keeps search, filter and the openperson. %>-<% open_lane = params.permit(:person_id, :member_id).to_h %>+<% open_lane = request.query_parameters.slice('person_id', 'member_id').select { |_key, value| value.is_a?(String) } %><turbo-frame id="<%= Organisations::PeopleController::LIST_FRAME_ID %>"><% if entries.any? %><% sort = list_state['sort'] == 'last' ? 'last' : 'name' %>- <div class="people-columns" role="row">+ <%# The list is a list, not a table: the heads are two links, the active+ one marked with aria-current and a word for screen readers. %>+ <div class="people-columns"><%# Class names written out: Tailwind keeps only component classes it finds whole in a template. %>- <% { 'name' => ['ascending', 'people-columns__head--name'], 'last' => ['descending', 'people-columns__head--last'] }.each do |key, (direction, head_class)| %>+ <% { 'name' => 'people-columns__head--name', 'last' => 'people-columns__head--last' }.each do |key, head_class| %><% active = sort == key %>- <%= tag.span role: 'columnheader', class: "people-columns__head #{head_class}", 'aria-sort': (active ? direction : 'none') do %>+ <%= tag.span class: "people-columns__head #{head_class}" do %><%= link_to organisation_people_path(@current_organisation, list_state.except('sort').merge(key == 'last' ? { 'sort' => 'last' } : {}).merge(open_lane)),- class: "people-columns__link #{'people-columns__link--active' if active}", data: { turbo_frame: '_top' } do %>+ class: "people-columns__link #{'people-columns__link--active' if active}", 'aria-current': (active ? 'true' : nil),+ data: { turbo_frame: '_top' } do %><%= t("views.organisations.people.index.columns.#{key}") %>- <% if active %><i class="bi bi-arrow-down" aria-hidden="true"></i><% end %>+ <% if active %><i class="bi bi-arrow-down" aria-hidden="true"></i><span class="sr-only"><%= t('views.organisations.people.index.columns.sorted') %></span><% end %><% end %><% end %><% end %>diff --git a/config/locales/views/personen.de.yml b/config/locales/views/personen.de.ymlindex 7d09e73..a60a007 100644--- a/config/locales/views/personen.de.yml+++ b/config/locales/views/personen.de.yml@@ -51,6 +51,7 @@ de:columns:name: "Name"last: "Zuletzt"+ sorted: "(sortiert)"age:today: "heute"yesterday: "gestern"diff --git a/config/locales/views/personen.en.yml b/config/locales/views/personen.en.ymlindex 13b70aa..e22e639 100644--- a/config/locales/views/personen.en.yml+++ b/config/locales/views/personen.en.yml@@ -51,6 +51,7 @@ en:columns:name: "Name"last: "Last"+ sorted: "(sorted)"age:today: "today"yesterday: "yesterday"diff --git a/spec/helpers/people_helper_spec.rb b/spec/helpers/people_helper_spec.rbindex ac9ca8e..2965e0b 100644--- a/spec/helpers/people_helper_spec.rb+++ b/spec/helpers/people_helper_spec.rb@@ -33,6 +33,24 @@ RSpec.describe PeopleHelper, type: :helper doendend+ # Review round 1: the date of the last meeting names its year when it is+ # not this year.+ describe '#last_contact_text' do+ def meeting_contact(at)+ People::Contacts::LastContact.new(at: at, kind: :meeting, meeting_title: 'Kick-off')+ end++ it 'leaves the year out for this year' do+ expect(I18n.with_locale(:de) { helper.last_contact_text(meeting_contact(Time.zone.local(2026, 10, 3, 10))) })+ .to eq('Letztes Meeting: Kick-off, 03.10.')+ end++ it 'names the year of an older meeting' do+ expect(I18n.with_locale(:de) { helper.last_contact_text(meeting_contact(Time.zone.local(2024, 10, 3, 10))) })+ .to eq('Letztes Meeting: Kick-off, 03.10.2024')+ end+ end+it 'counts late yesterday evening as yesterday, not as hours ago' doexpect(I18n.with_locale(:de) { helper.last_contact_age(Time.zone.local(2026, 10, 25, 23, 50)) }).to eq('gestern')enddiff --git a/spec/requests/organisations/people_last_contact_spec.rb b/spec/requests/organisations/people_last_contact_spec.rbindex 14591cb..3a30396 100644--- a/spec/requests/organisations/people_last_contact_spec.rb+++ b/spec/requests/organisations/people_last_contact_spec.rb@@ -61,8 +61,10 @@ RSpec.describe 'Organisations::People last contact', :ci_guard, type: :request dhead = response.body[%r{<div class="people-columns"[\s\S]*?</div>}]expect(head).to include(I18n.t('views.organisations.people.index.columns.name'),I18n.t('views.organisations.people.index.columns.last'))- active = head[%r{<span[^>]*aria-sort="ascending"[^>]*>[\s\S]*?</span>}]- expect(active).to include(I18n.t('views.organisations.people.index.columns.name'), 'bi-arrow-down')+ expect(head).not_to include('role=', 'aria-sort')+ active = head[%r{<a[^>]*aria-current="true"[^>]*>[\s\S]*?</a>}]+ expect(active).to include(I18n.t('views.organisations.people.index.columns.name'), 'bi-arrow-down',+ I18n.t('views.organisations.people.index.columns.sorted'))expect(response.body.index('Carl Beispiel')).to be < response.body.index('Doris Dienstleister')end@@ -88,6 +90,16 @@ RSpec.describe 'Organisations::People last contact', :ci_guard, type: :request dexpect(response.body).to include(CGI.escapeHTML('"sort"'))end+ it 'drops an unknown sort from every link' do+ sign_in viewer++ get organisation_people_path(organisation, sort: 'evil')++ expect(response).to have_http_status(:ok)+ expect(response.body).to include('Doris Dienstleister')+ expect(response.body).not_to include('sort=evil')+ end+it 'is not moved by, and does not show, a meeting the viewer may not read' domeeting(readable, at: 5.days.ago, title: 'Status', person: contact)meeting(hidden, at: 1.hour.ago, title: 'Geheimrunde', user: colleague)@@ -197,6 +209,37 @@ RSpec.describe 'Organisations::People last contact', :ci_guard, type: :request dendend+ # Review round 1: a row of a former member (a contact with the account's+ # user_id) counts meetings through the account, never ticket work, in the+ # row, in the sort and in the lane alike.+ describe 'a row of a former member' do+ let(:ticket) { create(:ticket, organisation: organisation, project: readable) }+ let!(:former_row) { create(:person, organisation: organisation, user: colleague, name: 'Carl Frueher') }++ before do+ meeting(readable, at: 6.days.ago, title: 'Altrunde', user: colleague)+ Activity.create!(actor: colleague, trackable: ticket, organisation: organisation, action: 'created',+ parameters: { 'skip_notifications' => true }, created_at: 1.day.ago)+ Membership.find_by(user: colleague, organisation: organisation).update!(active: false)+ sign_in viewer+ end++ it 'shows the meeting through the account and not the ticket work in the row' do+ get organisation_people_path(organisation)++ row = row_of(response.body, 'Carl Frueher')+ expect(row).to include('vor 6 Tagen', 'Letztes Meeting: Altrunde')+ expect(row).not_to include('Ticket')+ end++ it 'shows the meeting and not the ticket work in the lane' do+ get organisation_person_path(organisation, former_row), headers: frame_headers++ expect(response.body).to include('Letztes Meeting: Altrunde', 'Altrunde')+ expect(response.body).not_to include("Hat Ticket ##{ticket.number}")+ end+ end+it 'shows the last contact and the meetings on a phone' domeeting(readable, at: 1.day.ago, title: 'Status', person: contact)sign_in viewerdiff --git a/spec/services/people/contacts_spec.rb b/spec/services/people/contacts_spec.rbindex 168e1e4..440a8b3 100644--- a/spec/services/people/contacts_spec.rb+++ b/spec/services/people/contacts_spec.rb@@ -98,6 +98,30 @@ RSpec.describe People::Contacts, :ci_guard doexpect(last.at).to be_within(1.second).of(5.days.ago)end+ # Review round 1: a meeting still to come is no contact yet.+ it 'does not count a meeting in the future, but lists it' do+ past = meeting_with(readable, at: 3.days.ago, title: 'Status', person: contact)+ future = meeting_with(readable, at: 10.days.from_now, title: 'Planung', person: contact)++ last = contacts.last_contacts([subject_for(person: contact)]).first++ expect(last.meeting_title).to eq('Status')+ expect(contacts.meetings_for(person: contact).to_a).to eq([future, past])+ end++ describe 'Subject.for (one rule for the list and the lane)' do+ it 'counts ticket work only for an active member' do+ row = create(:person, organisation: organisation, user: colleague)++ expect(described_class::Subject.for(person: row, member: colleague).to_h)+ .to eq(person_id: row.id, user_id: colleague.id, member: true)+ expect(described_class::Subject.for(person: row, member: nil).to_h)+ .to eq(person_id: row.id, user_id: colleague.id, member: false)+ expect(described_class::Subject.for(person: nil, member: colleague).to_h)+ .to eq(person_id: nil, user_id: colleague.id, member: true)+ end+ end+it 'is nil without anything readable' domeeting_with(hidden, at: 1.day.ago, title: 'Geheim', person: contact)