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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
End recurring meetings early
Oliver Güntherab0788e1eb01
diff --git a/modules/meeting/app/components/recurring_meetings/end_series_dialog_component.html.erb b/modules/meeting/app/components/recurring_meetings/end_series_dialog_component.html.erbnew file mode 100644index 00000000000..b81a50c539f--- /dev/null+++ b/modules/meeting/app/components/recurring_meetings/end_series_dialog_component.html.erb@@ -0,0 +1,48 @@+<%#-- copyright+OpenProject is an open source project management software.+Copyright (C) the OpenProject GmbH++This program is free software; you can redistribute it and/or+modify it under the terms of the GNU General Public License version 3.++OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+Copyright (C) 2006-2013 Jean-Philippe Lang+Copyright (C) 2010-2013 the ChiliProject Team++This program is free software; you can redistribute it and/or+modify it under the terms of the GNU General Public License+as published by the Free Software Foundation; either version 2+of the License, or (at your option) any later version.++This program is distributed in the hope that it will be useful,+but WITHOUT ANY WARRANTY; without even the implied warranty of+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+GNU General Public License for more details.++You should have received a copy of the GNU General Public License+along with this program; if not, write to the Free Software+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.++See COPYRIGHT and LICENSE files for more details.++++#%>++<%=+ render(Primer::OpenProject::DangerConfirmationDialog.new(+ id: "recurring-meetings-end-series-dialog",+ title: I18n.t(:text_are_you_sure),+ form_arguments: {+ action: end_series_recurring_meeting_path(@series),+ method: :post+ }+ )) do |dialog|+ dialog.with_show_button { I18n.t(:label_recurring_meeting_series_confirm) }+ dialog.with_confirmation_message do |message|+ message.with_heading(tag: :h2) { I18n.t(:text_meeting_series_end_early_heading) }+ message.with_description_content(I18n.t(:text_meeting_series_end_early))++ end++ dialog.with_confirmation_check_box_content(I18n.t("text_permanent_delete_confirmation_checkbox_label"))+ end+%>diff --git a/modules/meeting/app/components/recurring_meetings/end_series_dialog_component.rb b/modules/meeting/app/components/recurring_meetings/end_series_dialog_component.rbnew file mode 100644index 00000000000..ab3076ae9dc--- /dev/null+++ b/modules/meeting/app/components/recurring_meetings/end_series_dialog_component.rb@@ -0,0 +1,41 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module RecurringMeetings+ class EndSeriesDialogComponent < ApplicationComponent+ include ApplicationHelper+ include OpTurbo::Streamable++ def initialize(series)+ super+ @series = series+ end+ end+enddiff --git a/modules/meeting/app/components/recurring_meetings/show_page_header_component.html.erb b/modules/meeting/app/components/recurring_meetings/show_page_header_component.html.erbindex 6ba8d651df3..c648bf1cd59 100644--- a/modules/meeting/app/components/recurring_meetings/show_page_header_component.html.erb+++ b/modules/meeting/app/components/recurring_meetings/show_page_header_component.html.erb@@ -35,7 +35,7 @@},'aria-label': t(:label_recurring_meeting_series_edit),test_selector: "edit-meeting-details-button",- ) do |item|+ ) do |item|item.with_leading_visual_icon(icon: :pencil)end@@ -54,6 +54,17 @@item.with_leading_visual_icon(icon: :mail)end+ menu.with_item(+ label: t(:label_recurring_meeting_series_end),+ href: end_series_dialog_recurring_meeting_path(@meeting),+ tag: :a,+ content_arguments: {+ data: { controller: 'async-dialog' },+ }+ ) do |item|+ item.with_leading_visual_icon(icon: :"x-circle")+ end if @meeting.start_time.to_date <= Time.zone.today+menu.with_item(label: I18n.t(:label_recurring_meeting_series_delete),href: polymorphic_path([@project, @meeting]),diff --git a/modules/meeting/app/controllers/recurring_meetings_controller.rb b/modules/meeting/app/controllers/recurring_meetings_controller.rbindex 9c5c71f7c29..1e58b185382 100644--- a/modules/meeting/app/controllers/recurring_meetings_controller.rb+++ b/modules/meeting/app/controllers/recurring_meetings_controller.rb@@ -10,7 +10,7 @@ class RecurringMeetingsController < ApplicationControllerbefore_action :find_meeting,only: %i[show update details_dialog destroy edit init- delete_scheduled template_completed download_ics notify]+ delete_scheduled template_completed download_ics notify end_series end_series_dialog]before_action :find_optional_project,only: %i[index show new create update details_dialog destroy edit delete_scheduled notify]before_action :authorize_global, only: %i[index new create]@@ -139,6 +139,23 @@ class RecurringMeetingsController < ApplicationControllerendend+ def end_series_dialog+ respond_with_dialog RecurringMeetings::EndSeriesDialogComponent.new(@recurring_meeting)+ end++ def end_series+ call = ::RecurringMeetings::UpdateService+ .new(model: @recurring_meeting, user: current_user)+ .call(end_after: "specific_date", end_date: Time.zone.today)++ if call.success?+ @recurring_meeting.scheduled_meetings.upcoming.destroy_all+ else+ flash[:error] = call.message+ end+ redirect_to action: :show+ end+def destroyif @recurring_meeting.destroyflash[:notice] = I18n.t(:notice_successful_delete)diff --git a/modules/meeting/config/locales/en.yml b/modules/meeting/config/locales/en.ymlindex 4e49c570381..3b6349de139 100644--- a/modules/meeting/config/locales/en.yml+++ b/modules/meeting/config/locales/en.yml@@ -155,6 +155,8 @@ en:label_recurring_meeting_series_create: "Create meeting series"label_recurring_meeting_series_edit: "Edit meeting series"label_recurring_meeting_series_delete: "Delete meeting series"+ label_recurring_meeting_series_end: "End meeting series"+ label_recurring_meeting_series_confirm: "End series"label_my_meetings: "My meetings"label_all_meetings: "All meetings"label_upcoming_meetings: "Upcoming meetings"@@ -293,6 +295,8 @@ en:text_duration_in_hours: "Duration in hours"text_in_hours: "in hours"text_meeting_agenda_for_meeting: 'agenda for the meeting "%{meeting}"'+ text_meeting_series_end_early_heading: "Delete future occurrences?"+ text_meeting_series_end_early: "Ending the series will delete any future open or scheduled meeting occurrences"text_meeting_closing_are_you_sure: "Are you sure you want to close the meeting agenda?"text_meeting_agenda_open_are_you_sure: "This will overwrite all changes in the minutes! Do you want to continue?"text_meeting_minutes_for_meeting: 'minutes for the meeting "%{meeting}"'diff --git a/modules/meeting/config/routes.rb b/modules/meeting/config/routes.rbindex a87305227bf..5bb5ebfeb3b 100644--- a/modules/meeting/config/routes.rb+++ b/modules/meeting/config/routes.rb@@ -64,6 +64,8 @@ Rails.application.routes.draw dopost :delete_scheduledpost :template_completedpost :notify+ post :end_series+ get :end_series_dialogendcollection doget :humanize_schedule, controller: "recurring_meetings/schedule", action: :humanize_schedulediff --git a/modules/meeting/lib/open_project/meeting/engine.rb b/modules/meeting/lib/open_project/meeting/engine.rbindex 7f2a0816d9f..fccbea65629 100644--- a/modules/meeting/lib/open_project/meeting/engine.rb+++ b/modules/meeting/lib/open_project/meeting/engine.rb@@ -63,7 +63,7 @@ module OpenProject::Meeting{meetings: %i[edit cancel_edit update update_title details_dialog update_details update_participants],recurring_meetings: %i[edit cancel_edit update update_title details_dialog update_details- notify],+ notify end_series end_series_dialog],work_package_meetings_tab: %i[add_work_package_to_meeting_dialog add_work_package_to_meeting]},permissible_on: :project,diff --git a/modules/meeting/spec/features/recurring_meetings/recurring_meeting_end_series_spec.rb b/modules/meeting/spec/features/recurring_meetings/recurring_meeting_end_series_spec.rbnew file mode 100644index 00000000000..7ca05b92b8f--- /dev/null+++ b/modules/meeting/spec/features/recurring_meetings/recurring_meeting_end_series_spec.rb@@ -0,0 +1,105 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require "spec_helper"++require_relative "../../support/pages/meetings/new"+require_relative "../../support/pages/structured_meeting/show"+require_relative "../../support/pages/recurring_meeting/show"+require_relative "../../support/pages/meetings/index"++RSpec.describe "Recurring meetings end series",+ :js,+ with_flag: { recurring_meetings: true } do+ include Components::Autocompleter::NgSelectAutocompleteHelpers++ before_all do+ travel_to(Date.new(2025, 1, 29))+ end++ after(:all) do # rubocop:disable RSpec/BeforeAfterAll+ travel_back+ end++ shared_let(:project) { create(:project, enabled_module_names: %w[meetings]) }+ shared_let(:user) do+ create :user,+ lastname: "First",+ preferences: { time_zone: "Etc/UTC" },+ member_with_permissions: { project => %i[view_meetings create_meetings edit_meetings delete_meetings] }+ end+ shared_let(:meeting) do+ create :recurring_meeting,+ project:,+ start_time: DateTime.parse("2025-01-29T10:30:00Z"),+ duration: 1,+ frequency: "weekly",+ end_after: "never",+ author: user+ end++ let(:current_user) { user }+ let(:show_page) { Pages::RecurringMeeting::Show.new(meeting) }+ let(:meetings_page) { Pages::Meetings::Index.new(project:) }++ before do+ login_as current_user++ # Assuming the first init job has run+ RecurringMeetings::InitNextOccurrenceJob.perform_now(meeting, meeting.first_occurrence.to_time)+ end++ it "can end the meeting early" do+ show_page.visit!++ page.find_test_selector("recurring-meeting-action-menu").click+ click_on "End meeting series"+ expect(page).to have_css("#recurring-meetings-end-series-dialog")+ expect(page).to have_text("Ending the series will delete any future open or scheduled meeting occurrences")+ check "I understand that this deletion cannot be reversed"++ click_on "Delete permanently"++ expect(page).to have_current_path recurring_meeting_path(meeting)+ show_page.expect_no_open_meeting date: "01/29/2025"+ end++ context "when meeting start time is in the future" do+ before do+ meeting.update! start_time: DateTime.parse("2025-01-30T10:30:00Z")+ end++ it "does not show this action" do+ show_page.visit!+ page.find_test_selector("recurring-meeting-action-menu").click+ expect(page).to have_no_text "End meeting series"+ end+ end+enddiff --git a/modules/meeting/spec/requests/recurring_meetings/recurring_meetings_end_series_spec.rb b/modules/meeting/spec/requests/recurring_meetings/recurring_meetings_end_series_spec.rbnew file mode 100644index 00000000000..08213830028--- /dev/null+++ b/modules/meeting/spec/requests/recurring_meetings/recurring_meetings_end_series_spec.rb@@ -0,0 +1,195 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require "spec_helper"+require_relative "../../support/pages/recurring_meeting/show"++RSpec.describe "Recurring meetings complete template",+ :skip_csrf,+ type: :rails_request,+ with_settings: { date_format: "%Y-%m-%d" } do+ include Redmine::I18n++ shared_let(:project) { create(:project, enabled_module_names: %i[meetings]) }+ shared_let(:user) { create(:user, member_with_permissions: { project => %i[view_meetings create_meetings edit_meetings] }) }+ shared_let(:recurring_meeting) do+ create :recurring_meeting,+ project:,+ author: user,+ start_time: DateTime.parse("2024-12-05T10:00:00Z"),+ frequency: "daily"+ end++ let(:current_user) { user }+ let(:show_page) { Pages::RecurringMeeting::Show.new(recurring_meeting).with_capybara_page(page) }+ let(:request) do+ post end_series_recurring_meeting_path(recurring_meeting)+ end++ subject do+ Timecop.freeze("2025-01-29T10:00:00Z".to_datetime) { request }+ end++ before do+ login_as(current_user)+ end++ context "when past occurrence is already created" do+ let!(:meeting) { create(:structured_meeting, recurring_meeting:, start_time: recurring_meeting.start_time) }+ let!(:schedule) do+ create :scheduled_meeting,+ meeting:,+ recurring_meeting:,+ start_time: recurring_meeting.start_time+ end++ it "does not delete that one" do+ expect { subject }.not_to change(recurring_meeting.scheduled_meetings, :count)+ expect(response).to be_redirect++ expect(recurring_meeting.scheduled_meetings.count).to eq(1)+ first = recurring_meeting.scheduled_meetings.first.meeting+ expect(first).to eq(meeting)+ end+ end++ context "when start_time < current time" do+ let!(:meeting) { create(:structured_meeting, recurring_meeting:, start_time: recurring_meeting.start_time) }+ let!(:schedule) do+ create :scheduled_meeting,+ meeting:,+ recurring_meeting:,+ start_time: recurring_meeting.start_time+ end++ subject do+ Timecop.freeze("2024-12-04T10:00:00Z".to_datetime) { request }+ end++ it "returns an error" do+ expect { subject }.not_to change { recurring_meeting.reload.updated_at }+ expect(response).to be_redirect+ expect(flash[:error]).to include "End date must be after 2024-12-05."+ end+ end++ context "when first occurrence is cancelled" do+ let!(:schedule) do+ create :scheduled_meeting,+ :cancelled,+ recurring_meeting:,+ start_time: recurring_meeting.start_time+ end++ it "does not delete this occurrence" do+ expect { subject }.not_to change(recurring_meeting.scheduled_meetings, :count)+ expect(response).to be_redirect++ recurring_meeting.reload+ expect(recurring_meeting.end_date).to eq Date.parse("2025-01-29")++ expect(recurring_meeting.scheduled_meetings.count).to eq(1)+ first = recurring_meeting.scheduled_meetings.first+ expect(first).to be_cancelled+ end+ end++ context "when todays occurrence is present, but we're later" do+ let!(:schedule) do+ create :scheduled_meeting,+ recurring_meeting:,+ start_time: DateTime.parse("2024-12-05T10:00:00Z")+ end++ subject do+ Timecop.freeze("2024-12-05T10:01:00Z".to_datetime) { request }+ end++ it "does not delete this occurrence" do+ expect { subject }.not_to change(recurring_meeting.scheduled_meetings, :count)+ expect(response).to be_redirect++ recurring_meeting.reload+ expect(recurring_meeting.end_date).to eq Date.parse("2024-12-05")+ expect(recurring_meeting.scheduled_meetings.count).to eq(1)+ end+ end++ context "when todays occurrence is present, but we're sooner" do+ let!(:schedule) do+ create :scheduled_meeting,+ recurring_meeting:,+ start_time: DateTime.parse("2024-12-05T10:00:00Z")+ end++ subject do+ Timecop.freeze("2024-12-05T09:59:00Z".to_datetime) { request }+ end++ it "does delete this occurrence" do+ expect { subject }.to change(recurring_meeting.scheduled_meetings, :count).by(-1)+ expect(response).to be_redirect++ recurring_meeting.reload+ expect(recurring_meeting.end_date).to eq Date.parse("2024-12-05")+ end+ end++ context "when next occurrence is present" do+ let!(:schedule) do+ create :scheduled_meeting,+ recurring_meeting:,+ start_time: DateTime.parse("2024-12-06T10:00:00Z")+ end++ subject do+ Timecop.freeze("2024-12-05T10:00:00Z".to_datetime) { request }+ end++ it "does delete this occurrence" do+ expect { subject }.to change(recurring_meeting.scheduled_meetings, :count).by(-1)+ expect(response).to be_redirect++ recurring_meeting.reload+ expect(recurring_meeting.end_date).to eq Date.parse("2024-12-05")+ expect(recurring_meeting.scheduled_meetings.count).to eq(0)+ expect { schedule.reload }.to raise_error(ActiveRecord::RecordNotFound)+ end+ end++ context "when user has no permissions to access" do+ let(:current_user) { create(:user) }++ it "does not authorize" do+ subject+ expect(response).to have_http_status(:not_found)+ end+ end+end