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.

Pin the unlink rights, the dialog token and the unique-index refusal

Guido Boyke8cb0c35dc447
diff --git a/spec/requests/organisations/meeting_participant_links_spec.rb b/spec/requests/organisations/meeting_participant_links_spec.rb
index 505fddb..5518ed2 100644
--- a/spec/requests/organisations/meeting_participant_links_spec.rb
+++ b/spec/requests/organisations/meeting_participant_links_spec.rb
@@ -226,6 +226,18 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :reque
expect(response.body).to include('Anton Anders')
expect(response.body).not_to include('Jonas Weber')
expect(response.body).not_to include(I18n.t("#{pl}.suggestion"))
+ # Only the list frame, not the whole dialog around it.
+ expect(response.body).to include("id=\"meeting-participant-link-results-#{participant.id}\"")
+ expect(response.body).not_to include(I18n.t("#{pl}.title"), "meeting-participant-link-modal-#{meeting.id}")
+ end
+
+ it 'shows the line under a name: function of a row, email of a member' do
+ colleague = member_with(create(:role, organisation: organisation), first_name: 'Carl')
+ sign_in admin
+
+ get new_link_path
+
+ expect(response.body).to include('Jonas Weber', 'Hosting', 'Carl Beispiel', CGI.escapeHTML(colleague.email))
end
it 'does not name a linked person the viewer may not see' do
@@ -321,6 +333,25 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :reque
expect(participant.reload.user_id).to be_nil
end
+ # The pick of a refused save is put back into the list; it must not stand twice,
+ # whether the dialog lists it as a suggestion or among the others.
+ it 'lists a refused pick once, as a suggestion or among the others' do
+ suggested = create(:user, first_name: 'Karl', last_name: 'Weber')
+ listed = member_with(create(:role, organisation: organisation), first_name: 'Carl')
+ create(:membership, user: suggested, organisation: organisation, role: create(:role, organisation: organisation), active: true)
+ create(:meeting_participant, meeting: meeting, display_name: 'Karl Weber', user: suggested)
+ create(:meeting_participant, meeting: meeting, display_name: 'Carl Beispiel', user: listed)
+ sign_in admin
+
+ [suggested, listed].each do |pick|
+ post_link("member:#{pick.id}")
+
+ expect(response).to have_http_status(:unprocessable_content)
+ expect(response.body.scan(%(value="member:#{pick.id}")).size).to eq(1)
+ end
+ expect(response.body).to include(I18n.t("#{pl}.suggestion"))
+ end
+
it 'refuses without a choice' do
sign_in admin
@@ -330,6 +361,44 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :reque
expect(response.body).to include(I18n.t('services.actors.link_meeting_participant.nothing_picked'))
end
+ it 'answers our own failure with a 500 and the dialog' do
+ failure = Actors::BaseActor::Result.new(success: false, errors: ['Interner Fehler'], code: :internal_error)
+ allow(Actors::LinkMeetingParticipant).to receive(:call).and_return(failure)
+ sign_in admin
+
+ post_link("person:#{contact.id}")
+
+ expect(response).to have_http_status(:internal_server_error)
+ expect(response.body).to include("action=\"replace\" target=\"meeting-participant-link-modal-#{meeting.id}-#{modal_token}\"",
+ 'Interner Fehler')
+ end
+
+ # The token names one opening of the dialog in a stream target: only 16 hex
+ # characters count, anything else answers as if there were no dialog.
+ { 'a leading character' => '-0123456789abcdef', 'a trailing character' => '0123456789abcdef-',
+ 'one character short' => '0123456789abcde', 'no hex at all' => 'not-a-token' }.each do |label, bad|
+ it "uses no token with #{label}" do
+ sign_in admin
+
+ post_link('', modal_token: bad)
+
+ expect(response).to have_http_status(:unprocessable_content)
+ expect(response.body).to include("action=\"replace\" target=\"#{ActionView::RecordIdentifier.dom_id(meeting, :participants)}\"",
+ I18n.t('services.actors.link_meeting_participant.nothing_picked'))
+ expect(response.body).not_to include('target="meeting-participant-link-modal-')
+ end
+ end
+
+ it 'removes no dialog after a link without a token' do
+ sign_in admin
+
+ post_link("person:#{contact.id}", modal_token: '')
+
+ expect(response).to have_http_status(:ok)
+ expect(response.body).to include("action=\"replace\" target=\"#{ActionView::RecordIdentifier.dom_id(meeting, :participants)}\"")
+ expect(response.body).not_to include('action="remove"')
+ end
+
it 'creates a person and links it' do
sign_in writer('manage_people')
@@ -386,6 +455,29 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :reque
expect_unchanged
end
+ # Unlinking reads nothing of the directory, so only the controller's checks hold it.
+ it 'refuses to unlink for a writer without view_people' do
+ participant.update!(person: contact)
+ sign_in writer
+
+ delete link_path, params: { modal_token: modal_token }, headers: stream
+
+ expect(response).to have_http_status(:found)
+ expect(participant.reload.person_id).to eq(contact.id)
+ end
+
+ it 'refuses to unlink for a reader of the meeting with view_people' do
+ participant.update!(person: contact)
+ reader = member_with(role_with('manage_people'), first_name: 'Rita')
+ create(:project_permission, user: reader, project: project, meetings_access: :read_only)
+ sign_in reader
+
+ delete link_path, params: { modal_token: modal_token }, headers: stream
+
+ expect(response).to have_http_status(:found)
+ expect(participant.reload.person_id).to eq(contact.id)
+ end
+
it 'refuses a member of another organisation' do
stranger_org = create(:organisation)
stranger = ActsAsTenant.with_tenant(stranger_org) do
diff --git a/spec/services/actors/link_meeting_participant_spec.rb b/spec/services/actors/link_meeting_participant_spec.rb
index 6577494..9240ace 100644
--- a/spec/services/actors/link_meeting_participant_spec.rb
+++ b/spec/services/actors/link_meeting_participant_spec.rb
@@ -117,6 +117,20 @@ RSpec.describe Actors::LinkMeetingParticipant, :ci_guard do
expect(result.errors).to eq([I18n.t('services.actors.link_meeting_participant.member_name_taken')])
expect(participant.reload.user_id).to be_nil
end
+
+ # The claim writes without the meeting lock, so its row can land after both the
+ # actor's check and the model's uniqueness validation. The partial unique index on
+ # (meeting_id, user_id) then refuses, and the actor answers as the check would.
+ it 'turns the unique index into the same refusal when a write lands past both checks' do
+ create(:meeting_participant, meeting: meeting, display_name: 'Carl der Andere', user: colleague)
+ allow_any_instance_of(described_class).to receive(:taken_by_another?).and_return(false)
+ allow_any_instance_of(MeetingParticipant).to receive(:valid?).and_return(true)
+
+ result = link(member_id: colleague.id)
+
+ expect(result.code).to eq(:member_already_participant)
+ expect(participant.reload.user_id).to be_nil
+ end
end
describe 'a participant that is a member' do
@@ -172,6 +186,13 @@ RSpec.describe Actors::LinkMeetingParticipant, :ci_guard do
expect(participant.reload.person_id).to eq(created.id)
end
+ # The dialog sends a name only; the rest of the row is the people page's.
+ it 'takes only the name from the new person' do
+ link(new_person: { name: 'J. Weber', email: '[email protected]', function: 'Hoster' })
+
+ expect(participant.reload.person).to have_attributes(name: 'J. Weber', email: nil, function: nil)
+ end
+
it 'creates nothing when the name is blank' do
result = nil
expect { result = link(new_person: { name: ' ' }) }.not_to change(Person, :count)