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
Add validation for interval and iterations
Oliver Günther0c9788a3bb9f
diff --git a/modules/meeting/app/components/recurring_meetings/frequency_text_component.rb b/modules/meeting/app/components/recurring_meetings/frequency_text_component.rbdeleted file mode 100644index 1ba4d9707b0..00000000000--- a/modules/meeting/app/components/recurring_meetings/frequency_text_component.rb+++ /dev/null@@ -1,56 +0,0 @@-#-- 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 FrequencyTextComponent < ApplicationComponent- include ApplicationHelper- include OpTurbo::Streamable- include OpPrimer::ComponentHelpers-- def initialize(frequency:, interval:)- super-- @frequency = frequency- @interval = interval- @current_count = count- @direction = direction- @max_count = max_count- end-- def label- count = @max_count - @current_count- label_suffix = count == 1 ? "_singular" : ""-- if @direction == "past"- I18n.t("label_recurring_meeting_more_past#{label_suffix}", count:)- else- I18n.t("label_recurring_meeting_more#{label_suffix}", count:, schedule: @meeting.schedule_in_words)- end- end- end-enddiff --git a/modules/meeting/app/models/recurring_meeting.rb b/modules/meeting/app/models/recurring_meeting.rbindex 857f4535b67..7711a705713 100644--- a/modules/meeting/app/models/recurring_meeting.rb+++ b/modules/meeting/app/models/recurring_meeting.rb@@ -1,4 +1,8 @@class RecurringMeeting < ApplicationRecord+ # Magical maximum of iterations+ MAX_ITERATIONS = 1000+ # Magical maximum of interval, derived from other calendars+ MAX_INTERVAL = 100include ::Meeting::VirtualStartTimeinclude Redmine::I18n@@ -7,15 +11,21 @@ class RecurringMeeting < ApplicationRecordvalidates_presence_of :start_time, :title, :frequency, :end_aftervalidates_presence_of :end_date, if: -> { end_after_specific_date? }- validates_numericality_of :iterations, if: -> { end_after_iterations? }+ validates_numericality_of :iterations,+ only_integer: true,+ greater_than_or_equal_to: 1,+ less_than_or_equal_to: MAX_ITERATIONS,+ if: -> { end_after_iterations? }validates_numericality_of :interval,only_integer: true,greater_than_or_equal_to: 1,+ less_than_or_equal_to: MAX_INTERVAL,if: -> { !frequency_working_days? }validate :end_date_constraints,if: -> { end_after_specific_date? }+ after_initialize :set_defaultsafter_save :unset_scheduleenum frequency: {diff --git a/modules/meeting/spec/models/recurring_meeting_spec.rb b/modules/meeting/spec/models/recurring_meeting_spec.rbindex 3c6e7f89fb1..5497bace6a7 100644--- a/modules/meeting/spec/models/recurring_meeting_spec.rb+++ b/modules/meeting/spec/models/recurring_meeting_spec.rb@@ -36,6 +36,15 @@ RSpec.describe RecurringMeeting,expect(subject.errors[:interval]).to be_emptyend+ it "validates max value" do+ subject.interval = 101+ expect(subject).not_to be_valid+ expect(subject.errors[:interval]).to include("must be less than or equal to 100.")++ subject.interval = 100+ expect(subject).to be_valid+ end+it "adds errors for invalid values", :aggregate_failures dosubject.interval = 0expect(subject).not_to be_valid@@ -55,6 +64,49 @@ RSpec.describe RecurringMeeting,endend+ describe "iterations" do+ subject { build(:recurring_meeting, end_after: "iterations") }++ it "does not validate if end_after is not iterations" do+ subject.end_after = "specific_date"+ subject.iterations = nil+ expect(subject).to be_valid+ end++ it "validates integer values >= 1" do+ subject.iterations = 1+ expect(subject).to be_valid+ expect(subject.errors[:iterations]).to be_empty+ end++ it "validates max value" do+ subject.iterations = 1001+ expect(subject).not_to be_valid+ expect(subject.errors[:iterations]).to include("must be less than or equal to 1000.")++ subject.iterations = 1000+ expect(subject).to be_valid+ end++ it "adds errors for invalid values", :aggregate_failures do+ subject.iterations = 0+ expect(subject).not_to be_valid+ expect(subject.errors[:iterations]).to include("must be greater than or equal to 1.")++ subject.iterations = -1+ expect(subject).not_to be_valid+ expect(subject.errors[:iterations]).to include("must be greater than or equal to 1.")++ subject.iterations = 0.1+ expect(subject).not_to be_valid+ expect(subject.errors[:iterations]).to include("is not an integer.")++ subject.iterations = "asdf"+ expect(subject).not_to be_valid+ expect(subject.errors[:iterations]).to include("is not a number.")+ end+ end+describe "daily schedule" dosubject dobuild(:recurring_meeting,