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.

Address review round 4 of linking a meeting participant

Guido Boykeb70980585d60
diff --git a/app/controllers/organisations/meeting_participant_links_controller.rb b/app/controllers/organisations/meeting_participant_links_controller.rb
index b030b2d..99039dd 100644
--- a/app/controllers/organisations/meeting_participant_links_controller.rb
+++ b/app/controllers/organisations/meeting_participant_links_controller.rb
@@ -106,20 +106,28 @@ module Organisations
end
end
- # The dialog again with the reason, in place of the instance that sent it.
- # Gone meanwhile (a move, a deleted participant) is a 404, our own failure a 500.
+ # The dialog again with the reason, in place of the instance that sent it;
+ # our own failure is a 500. Not found (a person or member out of reach, or the
+ # meeting moved meanwhile, which the lock reloaded into its new project) closes
+ # the dialog with the reason and draws nothing of the meeting again.
def refused(result)
@errors = result.errors
- status = if INTERNAL_CODES.include?(result.code) then :internal_server_error
- elsif NOT_FOUND_CODES.include?(result.code) then :not_found
- else :unprocessable_content
- end
+ return gone if NOT_FOUND_CODES.include?(result.code)
+
+ status = INTERNAL_CODES.include?(result.code) ? :internal_server_error : :unprocessable_content
respond_to do |format|
format.turbo_stream { render 'organisations/meeting_participant_links/refused', status: status }
format.html { redirect_to meeting_path, alert: @errors.to_sentence, status: :see_other }
end
end
+ def gone
+ respond_to do |format|
+ format.turbo_stream { render 'organisations/meeting_participant_links/gone', status: :not_found }
+ format.html { redirect_to meeting_path, alert: @errors.to_sentence, status: :see_other }
+ end
+ end
+
def meeting_path
organisation_project_meetings_path(current_organisation, @project, meeting_id: @meeting.id)
end
diff --git a/app/views/organisations/meeting_participant_links/gone.turbo_stream.erb b/app/views/organisations/meeting_participant_links/gone.turbo_stream.erb
new file mode 100644
index 0000000..fd21283
--- /dev/null
+++ b/app/views/organisations/meeting_participant_links/gone.turbo_stream.erb
@@ -0,0 +1,8 @@
+<%# Not found: a person or member out of the writer's reach, or a meeting moved meanwhile (the
+ lock reloaded it into its new project). The dialog instance goes and the reason comes as a
+ flash; nothing of the meeting is drawn again, so a moved meeting shows nothing of the
+ project it is in now. %>
+<% if @modal_token %>
+ <%= turbo_stream.remove participant_link_modal_instance_id(@meeting, @modal_token) %>
+<% end %>
+<%= turbo_stream.prepend 'flash', partial: 'layouts/flash', locals: { flash: { alert: @errors.to_sentence } } %>
diff --git a/app/views/organisations/meeting_participant_links/refused.turbo_stream.erb b/app/views/organisations/meeting_participant_links/refused.turbo_stream.erb
index db5359e..5732769 100644
--- a/app/views/organisations/meeting_participant_links/refused.turbo_stream.erb
+++ b/app/views/organisations/meeting_participant_links/refused.turbo_stream.erb
@@ -1,5 +1,5 @@
<%# The link was refused (nothing picked, a member already in the meeting, no right to create
- a person, gone meanwhile): the dialog again with the reason and what was picked, in place
+ a person; not found answers with gone instead): the dialog again with the reason and what was picked, in place
of the instance that sent it. A dialog closed meanwhile has no such element and stays
closed. Without a usable token there is no instance to fill: the reason goes out as a
flash, and the row shows the state as it is now. %>
diff --git a/app/views/organisations/meetings/_participant_chips.html.erb b/app/views/organisations/meetings/_participant_chips.html.erb
index ac97a9f..72305ac 100644
--- a/app/views/organisations/meetings/_participant_chips.html.erb
+++ b/app/views/organisations/meetings/_participant_chips.html.erb
@@ -8,6 +8,7 @@
<% participants.each do |participant| %>
<% chip_style = meeting_participant_chip_style(meeting_participant_type(participant, permitted_user_ids)) %>
<% path = people.path_for(participant) %>
+ <% linkable = people.linkable?(participant) %>
<span class="meeting-participant inline-flex min-w-0 max-w-full items-center gap-0.5">
<% chip = render NeoTagComponent.new(
text: participant.display_name,
@@ -18,13 +19,16 @@
class: 'max-w-full [&_.tag-text]:break-words [&_.tag-text]:[overflow-wrap:anywhere]'
) %>
<% if path %>
+ <%# Without a link action (a name just linked to a member), the person link carries the
+ action's id: the dialog gives the focus back to it. %>
<%= link_to chip, path, class: 'meeting-participant__person min-w-0 max-w-full rounded-full',
+ id: (participant_link_trigger_id(participant) unless linkable),
data: { turbo_frame: '_top' },
aria: { label: t("#{pl}.open_person", name: participant.display_name) } %>
<% else %>
<%= chip %>
<% end %>
- <% if people.linkable?(participant) %>
+ <% if linkable %>
<% action_label = participant.person_id ? t("#{pl}.change", name: participant.display_name) : t("#{pl}.link", name: participant.display_name) %>
<%= link_to new_organisation_project_meeting_participant_link_path(current_organisation, meeting.project, meeting, participant),
id: participant_link_trigger_id(participant),
diff --git a/spec/requests/organisations/meeting_participant_links_spec.rb b/spec/requests/organisations/meeting_participant_links_spec.rb
index b82b269..505fddb 100644
--- a/spec/requests/organisations/meeting_participant_links_spec.rb
+++ b/spec/requests/organisations/meeting_participant_links_spec.rb
@@ -127,6 +127,11 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :reque
gone = member_with(create(:role, organisation: organisation), first_name: 'Gerd')
row = create(:person, organisation: organisation, name: 'Gerd Beispiel', user: gone)
gone_participant = create(:meeting_participant, meeting: meeting, display_name: 'Gerd Beispiel', user: gone)
+ # Still a member elsewhere: only the membership HERE counts.
+ elsewhere = create(:organisation)
+ ActsAsTenant.with_tenant(elsewhere) do
+ create(:membership, user: gone, organisation: elsewhere, role: create(:role, organisation: elsewhere), active: true)
+ end
RemoveMembershipService.new(membership: gone.memberships.find_by!(organisation: organisation), admin: admin).call
expect(row.reload.user_id).to be_nil
sign_in admin
@@ -142,6 +147,17 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :reque
expect(response.body).to include('Hosting-Abstimmung')
end
+ it 'offers no link for the participant of a deactivated member' do
+ dora = member_with(create(:role, organisation: organisation), first_name: 'Dora')
+ dora_participant = create(:meeting_participant, meeting: meeting, display_name: 'Dora Beispiel', user: dora)
+ Membership.where(user: dora, organisation: organisation).update_all(active: false)
+ sign_in admin
+ show_meeting
+
+ expect(response.body).to include('Dora Beispiel', CGI.escapeHTML(new_link_path))
+ expect(response.body).not_to include(new_link_path(dora_participant))
+ end
+
it 'keeps a chip as text when its person is a row the viewer may not see' do
hidden_member = member_with(create(:role, organisation: organisation), first_name: 'Hanna')
create(:project_permission, user: hidden_member, project: create(:project, organisation: organisation),
@@ -408,7 +424,7 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :reque
post_link("person:#{hidden_row.id}")
expect(response).to have_http_status(:not_found)
- expect(response.body).to include('Jonas Weber')
+ expect(response.body).to include(I18n.t('services.actors.link_meeting_participant.not_found'))
expect(response.body).not_to include('Hanna Weber')
post_link("member:#{hidden_member.id}")
expect(response).to have_http_status(:not_found)
@@ -427,6 +443,23 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :reque
expect(other.reload.person_id).to be_nil
end
+ # A move that commits between the lookup and the lock (lock_in_project! reloads the
+ # meeting): the answer closes the dialog and draws nothing of the new project.
+ it 'answers a meeting moved during the request without drawing it again' do
+ target = create(:project, organisation: organisation)
+ allow_any_instance_of(Meeting).to receive(:lock_in_project!) do |moved, _project_id|
+ moved.update_columns(project_id: target.id)
+ false
+ end
+ sign_in admin
+
+ post_link("person:#{contact.id}")
+
+ expect(response).to have_http_status(:not_found)
+ expect(response.body).to include("action=\"remove\" target=\"meeting-participant-link-modal-#{meeting.id}-#{modal_token}\"")
+ expect(response.body).not_to include(target.id, 'action="replace"')
+ end
+
it 'does not find a meeting moved into another project' do
target = create(:project, organisation: organisation)
Actors::MoveMeeting.call(meeting: meeting, target_project: target, current_user: admin)
diff --git a/spec/services/actors/link_meeting_participant_spec.rb b/spec/services/actors/link_meeting_participant_spec.rb
index 8f1db9b..6577494 100644
--- a/spec/services/actors/link_meeting_participant_spec.rb
+++ b/spec/services/actors/link_meeting_participant_spec.rb
@@ -131,6 +131,17 @@ RSpec.describe Actors::LinkMeetingParticipant, :ci_guard do
end
end
+ describe 'a participant of a deactivated member' do
+ it 'is still a member participant (the account comes back with the membership)' do
+ colleague = member(first_name: 'Dora')
+ participant.update!(user: colleague)
+ Membership.where(user: colleague, organisation: organisation).update_all(active: false)
+
+ expect(link(person_id: contact.id).code).to eq(:member_participant)
+ expect(participant.reload.slice(:user_id, :person_id)).to eq('user_id' => colleague.id, 'person_id' => nil)
+ end
+ end
+
describe 'unlinking' do
it 'sets person_id to nil and keeps the row and its name' do
link(person_id: contact.id)
@@ -255,5 +266,14 @@ RSpec.describe Actors::LinkMeetingParticipant, :ci_guard do
link(person_id: contact.id)
end
+
+ # The claim writes participants without the meeting lock: the row is locked too.
+ it 'locks the participant row' do
+ statements = []
+ collect = ->(*, payload) { statements << payload[:sql] }
+ ActiveSupport::Notifications.subscribed(collect, 'sql.active_record') { link(person_id: contact.id) }
+
+ expect(statements).to include(a_string_matching(/FROM "meeting_participants".*FOR UPDATE/m))
+ end
end
end
diff --git a/spec/system/meeting_participant_link_spec.rb b/spec/system/meeting_participant_link_spec.rb
index 2464bb5..2b7b753 100644
--- a/spec/system/meeting_participant_link_spec.rb
+++ b/spec/system/meeting_participant_link_spec.rb
@@ -61,6 +61,24 @@ RSpec.describe 'Linking a meeting participant to a person', type: :system do
expect(page).to have_css("##{trigger_id}:focus")
end
+ # After a link to a member the name has no link action any more: the focus goes to the
+ # chip's link to the person instead of falling to the page.
+ it 'gives the focus to the person link after linking a member' do
+ colleague = create(:user, first_name: 'Jonas', last_name: 'Kollege')
+ create(:membership, user: colleague, organisation: organisation, role: create(:role, organisation: organisation), active: true)
+ visit organisation_project_meetings_path(organisation, project, meeting_id: meeting.id)
+ open_dialog
+
+ within('[role="dialog"]') do
+ find('label', text: 'Jonas Kollege').click
+ click_button I18n.t("#{pl}.submit")
+ end
+
+ expect(page).to have_no_css('[role="dialog"]')
+ expect(page).to have_css("a##{trigger_id}:focus", text: 'J. Weber (Hoster)')
+ expect(participant.reload.user_id).to eq(colleague.id)
+ end
+
# A refusal swaps the dialog for a new instance: the focus must still go back to the
# button that opened it, and a search in the refused dialog must still work.
it 'gives the focus back after a refusal, a search and Escape' do