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

Make RSVP and PARTSTAT depending on if we build a full calendar export or a single invitation

Klaus Zanders4db4c8f95b73
diff --git a/modules/meeting/app/services/all_meetings/ical_service.rb b/modules/meeting/app/services/all_meetings/ical_service.rb
index 9fd9d11dced..6f456beb3ed 100644
--- a/modules/meeting/app/services/all_meetings/ical_service.rb
+++ b/modules/meeting/app/services/all_meetings/ical_service.rb
@@ -46,6 +46,7 @@ module AllMeetings
end
calendar.preload_for_recurring_meetings(recurring_meetings: recurring_meetings)
+ calendar.mark_current_user_having_accepted_all_invitations!
recurring_meetings.each do |recurring_meeting|
calendar.add_series_event(recurring_meeting:, cancelled: false)
diff --git a/modules/meeting/app/services/meetings/ical_service.rb b/modules/meeting/app/services/meetings/ical_service.rb
index fb93492ea81..83d07401c0a 100644
--- a/modules/meeting/app/services/meetings/ical_service.rb
+++ b/modules/meeting/app/services/meetings/ical_service.rb
@@ -40,7 +40,7 @@ module Meetings
def call(cancelled: false)
User.execute_as(user) do
- calendar = Meetings::IcalendarBuilder.new(timezone: Time.zone || Time.zone_default)
+ calendar = Meetings::IcalendarBuilder.new(timezone: Time.zone || Time.zone_default, user: user)
calendar.add_single_meeting_event(meeting:, cancelled:)
calendar.update_calendar_status(cancelled:)
diff --git a/modules/meeting/app/services/meetings/icalendar_builder.rb b/modules/meeting/app/services/meetings/icalendar_builder.rb
index 460d9abc8d4..cba5e39140b 100644
--- a/modules/meeting/app/services/meetings/icalendar_builder.rb
+++ b/modules/meeting/app/services/meetings/icalendar_builder.rb
@@ -32,9 +32,10 @@ require "icalendar/tzinfo"
module Meetings
class IcalendarBuilder
- attr_reader :timezone, :calendar, :all_times, :tzid
+ attr_reader :timezone, :calendar, :all_times, :tzid, :current_user
- def initialize(timezone:)
+ def initialize(timezone:, user: User.current)
+ @current_user = user
@timezone = timezone
@tzid = timezone.tzinfo.canonical_identifier
@calendar = build_icalendar
@@ -42,6 +43,11 @@ module Meetings
@excluded_dates_cache = {}
@instantiated_occurrences_cache = {}
@series_cache_loaded = false
+ @action_needed_from_user_as_attendee = true
+ end
+
+ def mark_current_user_having_accepted_all_invitations!
+ @action_needed_from_user_as_attendee = false
end
def add_single_meeting_event(meeting:, cancelled: false) # rubocop:disable Metrics/AbcSize
@@ -171,8 +177,8 @@ module Meetings
{
"CN" => user.name,
"EMAIL" => user.mail,
- "PARTSTAT" => "ACCEPTED", # until we handle RSVPs properly, we assume participants have accepted
- "RSVP" => "TRUE",
+ "PARTSTAT" => attendee_participation_status(user),
+ "RSVP" => attendee_rsvp_needed?(user) ? "TRUE" : "FALSE",
"CUTYPE" => "INDIVIDUAL",
"ROLE" => "REQ-PARTICIPANT"
}
@@ -182,6 +188,18 @@ module Meetings
end
end
+ def attendee_participation_status(user)
+ if current_user == user && @action_needed_from_user_as_attendee
+ "NEEDS-ACTION"
+ else
+ "ACCEPTED" # until we handle RSVPs properly, we assume participants have accepted
+ end
+ end
+
+ def attendee_rsvp_needed?(user)
+ current_user == user && @action_needed_from_user_as_attendee
+ end
+
def ical_datetime(time)
time_in_time_zone = time.in_time_zone(timezone)
all_times << time_in_time_zone
diff --git a/modules/meeting/app/services/recurring_meetings/ical_service.rb b/modules/meeting/app/services/recurring_meetings/ical_service.rb
index b214f79af22..279f566ac8a 100644
--- a/modules/meeting/app/services/recurring_meetings/ical_service.rb
+++ b/modules/meeting/app/services/recurring_meetings/ical_service.rb
@@ -42,7 +42,7 @@ module RecurringMeetings
def generate_series(cancelled: false) # rubocop:disable Metrics/AbcSize
User.execute_as(user) do
- calendar = Meetings::IcalendarBuilder.new(timezone: Time.zone || Time.zone_default)
+ calendar = Meetings::IcalendarBuilder.new(timezone: Time.zone || Time.zone_default, user: user)
calendar.add_series_event(recurring_meeting: series, cancelled:)
calendar.update_calendar_status(cancelled:)
diff --git a/modules/meeting/spec/services/meetings/icalendar_builder_spec.rb b/modules/meeting/spec/services/meetings/icalendar_builder_spec.rb
index 325d525760a..c41699eb1c3 100644
--- a/modules/meeting/spec/services/meetings/icalendar_builder_spec.rb
+++ b/modules/meeting/spec/services/meetings/icalendar_builder_spec.rb
@@ -4,45 +4,75 @@ require "rails_helper"
RSpec.describe Meetings::IcalendarBuilder,
with_settings: { mail_from: "[email protected]", app_title: "OpenProject Testing" } do
- subject(:builder) { described_class.new(timezone:) }
-
- let(:parsed_calendar) { Icalendar::Calendar.parse(builder.to_ical).first }
-
let(:timezone) { ActiveSupport::TimeZone["Europe/Berlin"] }
context "with a single meeting" do
let(:meeting) { create(:meeting, :author_participates, start_time: Time.zone.parse("2025-08-30 10:00")) }
- it "adds basic event data" do
- builder.add_single_meeting_event(meeting:)
- builder.update_calendar_status(cancelled: false)
-
- event = parsed_calendar.events.first
- expect(event.summary).to include(meeting.title)
- expect(event.description).to include(I18n.t(:label_meeting))
- expect(event.uid).to eq(meeting.uid)
- # Organizer
- expect(event.organizer.to_s).to include("mailto:[email protected]")
- # Attendees (author participates)
- expect(event.attendee.first.to_s).to include("mailto:#{meeting.author.mail}")
- # Timezone parameter
- expect(event.dtstart.ical_params["tzid"]).to eq([timezone.tzinfo.canonical_identifier])
- # Method defaults to REQUEST when not cancelled
- expect(parsed_calendar.ip_method).to eq("REQUEST")
+ context "when current user needs to take action" do
+ subject(:builder) { described_class.new(timezone:, user: meeting.author) }
+
+ let(:parsed_calendar) { Icalendar::Calendar.parse(builder.to_ical).first }
+
+ it "sets PARTSTAT to NEEDS-ACTION and RSVP to TRUE for current user" do
+ builder.add_single_meeting_event(meeting:)
+ builder.update_calendar_status(cancelled: false)
+
+ event = parsed_calendar.events.first
+ expect(event.attendee).not_to be_empty
+
+ # Find the current user's attendee entry
+ current_user_attendee = event.attendee.find { |a| a.to_s.include?(meeting.author.mail) }
+ expect(current_user_attendee).to be_present
+ expect(current_user_attendee.ical_params["partstat"]).to eq(["NEEDS-ACTION"])
+ expect(current_user_attendee.ical_params["rsvp"]).to eq(["TRUE"])
+ expect(current_user_attendee.ical_params["cutype"]).to eq(["INDIVIDUAL"])
+ expect(current_user_attendee.ical_params["role"]).to eq(["REQ-PARTICIPANT"])
+ end
end
- it "sets PARTSTAT to ACCEPTED for all attendees" do
- builder.add_single_meeting_event(meeting:)
- builder.update_calendar_status(cancelled: false)
+ context "when current user has accepted all invitations" do
+ subject(:builder) do
+ described_class.new(timezone:, user: meeting.author).tap(&:mark_current_user_having_accepted_all_invitations!)
+ end
+
+ let(:parsed_calendar) { Icalendar::Calendar.parse(builder.to_ical).first }
+
+ it "sets PARTSTAT to ACCEPTED and RSVP to FALSE for all attendees" do
+ builder.add_single_meeting_event(meeting:)
+ builder.update_calendar_status(cancelled: false)
+
+ event = parsed_calendar.events.first
+ expect(event.attendee).not_to be_empty
+
+ event.attendee.each do |attendee|
+ expect(attendee.ical_params["partstat"]).to eq(["ACCEPTED"])
+ expect(attendee.ical_params["rsvp"]).to eq(["FALSE"])
+ expect(attendee.ical_params["cutype"]).to eq(["INDIVIDUAL"])
+ expect(attendee.ical_params["role"]).to eq(["REQ-PARTICIPANT"])
+ end
+ end
+ end
+
+ context "when current user is not a participant" do
+ let(:other_user) { create(:user) }
+ let(:parsed_calendar) { Icalendar::Calendar.parse(builder.to_ical).first }
- event = parsed_calendar.events.first
- expect(event.attendee).not_to be_empty
+ subject(:builder) { described_class.new(timezone:, user: other_user) }
+
+ it "sets PARTSTAT to ACCEPTED and RSVP to FALSE for all attendees" do
+ builder.add_single_meeting_event(meeting:)
+ builder.update_calendar_status(cancelled: false)
- event.attendee.each do |attendee|
- expect(attendee.ical_params["partstat"]).to eq(["ACCEPTED"])
- expect(attendee.ical_params["rsvp"]).to eq(["TRUE"])
- expect(attendee.ical_params["cutype"]).to eq(["INDIVIDUAL"])
- expect(attendee.ical_params["role"]).to eq(["REQ-PARTICIPANT"])
+ event = parsed_calendar.events.first
+ expect(event.attendee).not_to be_empty
+
+ event.attendee.each do |attendee|
+ expect(attendee.ical_params["partstat"]).to eq(["ACCEPTED"])
+ expect(attendee.ical_params["rsvp"]).to eq(["FALSE"])
+ expect(attendee.ical_params["cutype"]).to eq(["INDIVIDUAL"])
+ expect(attendee.ical_params["role"]).to eq(["REQ-PARTICIPANT"])
+ end
end
end
@@ -56,35 +86,68 @@ RSpec.describe Meetings::IcalendarBuilder,
meeting
end
- it "sets PARTSTAT to ACCEPTED for all multiple attendees" do
- builder.add_single_meeting_event(meeting: meeting_with_participants)
- builder.update_calendar_status(cancelled: false)
+ context "when current user needs to take action" do
+ subject(:builder) { described_class.new(timezone:, user: user1) }
- event = parsed_calendar.events.first
- expect(event.attendee.count).to eq(2)
+ let(:parsed_calendar) { Icalendar::Calendar.parse(builder.to_ical).first }
- # Find attendees by email
- john_attendee = event.attendee.find { |a| a.to_s.include?("[email protected]") }
- jane_attendee = event.attendee.find { |a| a.to_s.include?("[email protected]") }
+ it "sets PARTSTAT to NEEDS-ACTION and RSVP to TRUE for current user, ACCEPTED and FALSE for others" do
+ builder.add_single_meeting_event(meeting: meeting_with_participants)
+ builder.update_calendar_status(cancelled: false)
- expect(john_attendee).to be_present
- expect(jane_attendee).to be_present
+ event = parsed_calendar.events.first
+ expect(event.attendee.count).to eq(2)
- [john_attendee, jane_attendee].each do |attendee|
- expect(attendee.ical_params["partstat"]).to eq(["ACCEPTED"])
- expect(attendee.ical_params["rsvp"]).to eq(["TRUE"])
- expect(attendee.ical_params["cutype"]).to eq(["INDIVIDUAL"])
- expect(attendee.ical_params["role"]).to eq(["REQ-PARTICIPANT"])
+ # Find attendees by email
+ john_attendee = event.attendee.find { |a| a.to_s.include?("[email protected]") }
+ jane_attendee = event.attendee.find { |a| a.to_s.include?("[email protected]") }
+
+ expect(john_attendee).to be_present
+ expect(jane_attendee).to be_present
+
+ # John is the current user, so he should have NEEDS-ACTION and RSVP=TRUE
+ expect(john_attendee.ical_params["partstat"]).to eq(["NEEDS-ACTION"])
+ expect(john_attendee.ical_params["rsvp"]).to eq(["TRUE"])
+ expect(john_attendee.ical_params["cutype"]).to eq(["INDIVIDUAL"])
+ expect(john_attendee.ical_params["role"]).to eq(["REQ-PARTICIPANT"])
+
+ # Jane is not the current user, so she should have ACCEPTED and RSVP=FALSE
+ expect(jane_attendee.ical_params["partstat"]).to eq(["ACCEPTED"])
+ expect(jane_attendee.ical_params["rsvp"]).to eq(["FALSE"])
+ expect(jane_attendee.ical_params["cutype"]).to eq(["INDIVIDUAL"])
+ expect(jane_attendee.ical_params["role"]).to eq(["REQ-PARTICIPANT"])
end
end
- end
- it "sets status CANCELLED when cancelled" do
- builder.add_single_meeting_event(meeting:, cancelled: true)
- builder.update_calendar_status(cancelled: true)
- event = parsed_calendar.events.first
- expect(event.status).to eq("CANCELLED")
- expect(parsed_calendar.ip_method).to eq("CANCEL")
+ context "when current user has accepted all invitations" do
+ subject(:builder) do
+ described_class.new(timezone:, user: user1).tap(&:mark_current_user_having_accepted_all_invitations!)
+ end
+
+ let(:parsed_calendar) { Icalendar::Calendar.parse(builder.to_ical).first }
+
+ it "sets PARTSTAT to ACCEPTED and RSVP to FALSE for all multiple attendees" do
+ builder.add_single_meeting_event(meeting: meeting_with_participants)
+ builder.update_calendar_status(cancelled: false)
+
+ event = parsed_calendar.events.first
+ expect(event.attendee.count).to eq(2)
+
+ # Find attendees by email
+ john_attendee = event.attendee.find { |a| a.to_s.include?("[email protected]") }
+ jane_attendee = event.attendee.find { |a| a.to_s.include?("[email protected]") }
+
+ expect(john_attendee).to be_present
+ expect(jane_attendee).to be_present
+
+ [john_attendee, jane_attendee].each do |attendee|
+ expect(attendee.ical_params["partstat"]).to eq(["ACCEPTED"])
+ expect(attendee.ical_params["rsvp"]).to eq(["FALSE"])
+ expect(attendee.ical_params["cutype"]).to eq(["INDIVIDUAL"])
+ expect(attendee.ical_params["role"]).to eq(["REQ-PARTICIPANT"])
+ end
+ end
+ end
end
end
@@ -132,62 +195,89 @@ RSpec.describe Meetings::IcalendarBuilder,
meeting.scheduled_meeting
end
- it "adds master event with RRULE and EXDATE plus override events" do
- builder.add_series_event(recurring_meeting:)
-
- master = parsed_calendar.events.find { |e| e.rrule.present? && e.recurrence_id.blank? }
- overrides = parsed_calendar.events.select { |e| e.recurrence_id.present? }
-
- expect(master).to be_present
- expect(master.uid).to eq(recurring_meeting.uid)
-
- rrule = master.rrule.first
- expect(rrule.frequency).to eq("WEEKLY")
- expect(rrule.count).to eq(10)
-
- # EXDATE contains cancelled schedule start (original scheduled time, not moved time)
- exdates = Array(master.exdate).flat_map { |ex| Array(ex) }.map(&:value)
- expect(exdates).to include(second_occurrence.start_time.in_time_zone(timezone))
- # One override for instantiated schedule
- expect(overrides.size).to eq(1)
- ov = overrides.first
- expect(ov.recurrence_id.value).to eq(third_occurence.start_time.in_time_zone(timezone))
- # Override start reflects moved meeting start time (+10m)
- expect(ov.dtstart.to_time.min).to eq(third_occurence.meeting.start_time.min)
- expect(ov.dtstart.to_time.min).not_to eq(third_occurence.start_time.min)
- expect(ov.sequence.to_i).to eq(third_occurence.meeting.lock_version)
- end
+ context "when current user needs to take action" do
+ subject(:builder) { described_class.new(timezone:, user: user1) }
- it "sets PARTSTAT to ACCEPTED for all attendees in recurring meeting series" do
- builder.add_series_event(recurring_meeting:)
+ let(:parsed_calendar) { Icalendar::Calendar.parse(builder.to_ical).first }
- master = parsed_calendar.events.find { |e| e.rrule.present? && e.recurrence_id.blank? }
- overrides = parsed_calendar.events.select { |e| e.recurrence_id.present? }
+ it "sets PARTSTAT to NEEDS-ACTION and RSVP to TRUE for current user in recurring meeting series" do
+ builder.add_series_event(recurring_meeting:)
- # Check master event attendees
- expect(master.attendee).not_to be_empty
- master.attendee.each do |attendee|
- expect(attendee.ical_params["partstat"]).to eq(["ACCEPTED"])
- expect(attendee.ical_params["rsvp"]).to eq(["TRUE"])
- expect(attendee.ical_params["cutype"]).to eq(["INDIVIDUAL"])
- expect(attendee.ical_params["role"]).to eq(["REQ-PARTICIPANT"])
+ master = parsed_calendar.events.find { |e| e.rrule.present? && e.recurrence_id.blank? }
+ overrides = parsed_calendar.events.select { |e| e.recurrence_id.present? }
+
+ # Check master event attendees
+ expect(master.attendee).not_to be_empty
+ current_user_attendee = master.attendee.find { |a| a.to_s.include?(user1.mail) }
+ other_user_attendee = master.attendee.find { |a| a.to_s.include?(user2.mail) }
+
+ # Current user should have NEEDS-ACTION and RSVP=TRUE
+ expect(current_user_attendee.ical_params["partstat"]).to eq(["NEEDS-ACTION"])
+ expect(current_user_attendee.ical_params["rsvp"]).to eq(["TRUE"])
+ expect(current_user_attendee.ical_params["cutype"]).to eq(["INDIVIDUAL"])
+ expect(current_user_attendee.ical_params["role"]).to eq(["REQ-PARTICIPANT"])
+
+ # Other user should have ACCEPTED and RSVP=FALSE
+ expect(other_user_attendee.ical_params["partstat"]).to eq(["ACCEPTED"])
+ expect(other_user_attendee.ical_params["rsvp"]).to eq(["FALSE"])
+ expect(other_user_attendee.ical_params["cutype"]).to eq(["INDIVIDUAL"])
+ expect(other_user_attendee.ical_params["role"]).to eq(["REQ-PARTICIPANT"])
+
+ # Check override event attendees
+ overrides.each do |override_event|
+ expect(override_event.attendee).not_to be_empty
+ current_user_override = override_event.attendee.find { |a| a.to_s.include?(user1.mail) }
+ other_user_override = override_event.attendee.find { |a| a.to_s.include?(user2.mail) }
+
+ expect(current_user_override.ical_params["partstat"]).to eq(["NEEDS-ACTION"])
+ expect(current_user_override.ical_params["rsvp"]).to eq(["TRUE"])
+ expect(other_user_override.ical_params["partstat"]).to eq(["ACCEPTED"])
+ expect(other_user_override.ical_params["rsvp"]).to eq(["FALSE"])
+ end
+ end
+ end
+
+ context "when current user has accepted all invitations" do
+ subject(:builder) do
+ described_class.new(timezone:, user: user1).tap(&:mark_current_user_having_accepted_all_invitations!)
end
- # Check override event attendees
- overrides.each do |override_event|
- expect(override_event.attendee).not_to be_empty
- override_event.attendee.each do |attendee|
+ let(:parsed_calendar) { Icalendar::Calendar.parse(builder.to_ical).first }
+
+ it "sets PARTSTAT to ACCEPTED and RSVP to FALSE for all attendees in recurring meeting series" do
+ builder.add_series_event(recurring_meeting:)
+
+ master = parsed_calendar.events.find { |e| e.rrule.present? && e.recurrence_id.blank? }
+ overrides = parsed_calendar.events.select { |e| e.recurrence_id.present? }
+
+ # Check master event attendees
+ expect(master.attendee).not_to be_empty
+ master.attendee.each do |attendee|
expect(attendee.ical_params["partstat"]).to eq(["ACCEPTED"])
- expect(attendee.ical_params["rsvp"]).to eq(["TRUE"])
+ expect(attendee.ical_params["rsvp"]).to eq(["FALSE"])
expect(attendee.ical_params["cutype"]).to eq(["INDIVIDUAL"])
expect(attendee.ical_params["role"]).to eq(["REQ-PARTICIPANT"])
end
+
+ # Check override event attendees
+ overrides.each do |override_event|
+ expect(override_event.attendee).not_to be_empty
+ override_event.attendee.each do |attendee|
+ expect(attendee.ical_params["partstat"]).to eq(["ACCEPTED"])
+ expect(attendee.ical_params["rsvp"]).to eq(["FALSE"])
+ expect(attendee.ical_params["cutype"]).to eq(["INDIVIDUAL"])
+ expect(attendee.ical_params["role"]).to eq(["REQ-PARTICIPANT"])
+ end
+ end
end
end
end
context "for timezone component" do
let(:meeting) { create(:meeting, start_time: Time.zone.parse("2025-10-01 10:00")) }
+ let(:parsed_calendar) { Icalendar::Calendar.parse(builder.to_ical).first }
+
+ subject(:builder) { described_class.new(timezone:) }
it "includes a VTIMEZONE with TZID" do
builder.add_single_meeting_event(meeting:)
@@ -198,6 +288,10 @@ RSpec.describe Meetings::IcalendarBuilder,
end
context "for timezone transitions across multiple years" do
+ subject(:builder) { described_class.new(timezone:) }
+
+ let(:parsed_calendar) { Icalendar::Calendar.parse(builder.to_ical).first }
+
# We pick dates spread over multiple DST changes
let!(:meetings) do
[