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

Only select current members as copied members

Oliver Güntherb3568c6443dd
diff --git a/modules/meeting/app/models/meeting.rb b/modules/meeting/app/models/meeting.rb
index b03fc714959..64837b77d68 100644
--- a/modules/meeting/app/models/meeting.rb
+++ b/modules/meeting/app/models/meeting.rb
@@ -157,7 +157,7 @@ class Meeting < ApplicationRecord
copy.set_initial_values
copy.participants.clear
- copy.participants_attributes = participants.collect(&:copy_attributes)
+ copy.participants_attributes = allowed_participants.collect(&:copy_attributes)
copy
end
@@ -212,6 +212,17 @@ class Meeting < ApplicationRecord
protected
+ # Participants of older meetings
+ # might contain users no longer in the project
+ #
+ # This returns the set currently allowed to view the meeting
+ def allowed_participants
+ available_members = User.allowed_members(:view_meetings, project).select(:id)
+
+ participants
+ .where(user_id: available_members)
+ end
+
def set_initial_values
# set defaults
write_attribute(:start_time, Date.tomorrow + 10.hours) if start_time.nil?
diff --git a/modules/meeting/spec/models/meeting_spec.rb b/modules/meeting/spec/models/meeting_spec.rb
index b18039072a2..e3c89f45135 100644
--- a/modules/meeting/spec/models/meeting_spec.rb
+++ b/modules/meeting/spec/models/meeting_spec.rb
@@ -222,5 +222,16 @@ describe Meeting, type: :model do
copy = meeting.copy({})
expect(copy.participants.all? { |p| p.id.nil? && !p.attended }).to be_truthy
end
+
+ context 'when old meeting as user no longer in project' do
+ before do
+ user2.memberships.destroy_all
+ end
+
+ it 'does not copy that user' do
+ copy = meeting.copy({})
+ expect(copy.participants.map(&:user_id)).to eq [user1.id]
+ end
+ end
end
end