Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[39853] Destroy MeetingParticipant when user gets deleted

Oliver Günther5bb48f54a374
diff --git a/app/models/user.rb b/app/models/user.rb
index 9fceb1fcb05..55bd055c8d0 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -66,6 +66,12 @@ class User < Principal
class_name: 'Doorkeeper::Application',
as: :owner
+ # Meeting memberships
+ has_many :meeting_participants,
+ class_name: 'MeetingParticipant',
+ inverse_of: :user,
+ dependent: :destroy
+
has_many :notification_settings, dependent: :destroy
# Users blocked via brute force prevention
diff --git a/modules/meeting/app/helpers/meetings_helper.rb b/modules/meeting/app/helpers/meetings_helper.rb
index 4e95698f3f0..42652cbcdca 100644
--- a/modules/meeting/app/helpers/meetings_helper.rb
+++ b/modules/meeting/app/helpers/meetings_helper.rb
@@ -29,7 +29,12 @@
module MeetingsHelper
def format_participant_list(participants)
if participants.any?
- participants.sort.map { |p| link_to_user p.user }.join('; ').html_safe
+ user_links = participants
+ .sort
+ .reject { |p| p.user.nil? }
+ .map { |p| link_to_user p.user }
+
+ safe_join(user_links, '; ')
else
t('placeholders.default')
end
diff --git a/modules/meeting/app/models/meeting.rb b/modules/meeting/app/models/meeting.rb
index 3c44476dd8f..bbb257f1f4e 100644
--- a/modules/meeting/app/models/meeting.rb
+++ b/modules/meeting/app/models/meeting.rb
@@ -136,7 +136,9 @@ class Meeting < ApplicationRecord
changeable_participants = changeable_participants + \
User.allowed_members(:view_meetings, project)
- changeable_participants.uniq(&:id)
+ changeable_participants
+ .compact
+ .uniq(&:id)
end
def copy(attrs)
diff --git a/modules/meeting/app/models/meeting_participant.rb b/modules/meeting/app/models/meeting_participant.rb
index 60068f63821..04200374247 100644
--- a/modules/meeting/app/models/meeting_participant.rb
+++ b/modules/meeting/app/models/meeting_participant.rb
@@ -34,11 +34,11 @@ class MeetingParticipant < ApplicationRecord
scope :attended, -> { where(attended: true) }
def name
- user.present? ? user.name : name
+ user.present? ? user.name : I18n.t('user.deleted')
end
def mail
- user.present? ? user.mail : mail
+ user.present? ? user.mail : I18n.t('user.deleted')
end
def <=>(other)
diff --git a/modules/meeting/spec/features/meetings_participants_spec.rb b/modules/meeting/spec/features/meetings_participants_spec.rb
index 3f0dba3d3ce..59980980b6c 100644
--- a/modules/meeting/spec/features/meetings_participants_spec.rb
+++ b/modules/meeting/spec/features/meetings_participants_spec.rb
@@ -81,4 +81,20 @@ describe 'Meetings participants', type: :feature do
show_page.expect_uninvited(viewer_user)
end
+
+ context 'with an invalid user reference' do
+ let(:show_page) { Pages::Meetings::Show.new(meeting) }
+ let(:meeting_participant) { FactoryBot.create :meeting_participant, user: viewer_user, meeting: meeting }
+
+ before do
+ meeting_participant.update_column(:user_id, 12341234)
+ end
+
+ it 'still allows to view the meeting' do
+ show_page.visit!
+
+ show_page.expect_invited meeting.author
+ show_page.expect_uninvited viewer_user
+ end
+ end
end