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

[#44414] Fix bug of displaying empty date alert page

Dombi Attila3c9bc297b6e1
diff --git a/app/models/queries/notifications/filters/reason_filter.rb b/app/models/queries/notifications/filters/reason_filter.rb
index 1b2bade31bd..0fc088efaa9 100644
--- a/app/models/queries/notifications/filters/reason_filter.rb
+++ b/app/models/queries/notifications/filters/reason_filter.rb
@@ -32,9 +32,12 @@ class Queries::Notifications::Filters::ReasonFilter < Queries::Notifications::Fi
.except(:date_alert_start_date, :date_alert_due_date)
.merge(dateAlert: [Notification::REASONS[:date_alert_start_date],
Notification::REASONS[:date_alert_due_date]])
+ .freeze
def allowed_values
- REASONS.keys.map { |reason| [reason, reason] }
+ reasons = REASONS.keys
+ reasons = reasons.without("dateAlert") unless EnterpriseToken.allows_to?(:date_alerts)
+ reasons.map { |reason| [reason, reason] }
end
def type
diff --git a/spec/features/notifications/notification_center/notification_center_date_alerts_spec.rb b/spec/features/notifications/notification_center/notification_center_date_alerts_spec.rb
index f5e91e8e642..804419ce302 100644
--- a/spec/features/notifications/notification_center/notification_center_date_alerts_spec.rb
+++ b/spec/features/notifications/notification_center/notification_center_date_alerts_spec.rb
@@ -1,4 +1,5 @@
require 'spec_helper'
+require 'features/page_objects/notification'
# rubocop:disable RSpec/ScatteredLet
describe "Notification center date alerts", js: true, with_settings: { journal_aggregation_time_minutes: 0 } do
@@ -152,6 +153,7 @@ describe "Notification center date alerts", js: true, with_settings: { journal_a
let(:center) { ::Pages::Notifications::Center.new }
let(:side_menu) { ::Components::Notifications::Sidemenu.new }
+ let(:toaster) { PageObjects::Notifications.new(page) }
# Converts "hh:mm" into { hour: h, min: m }
def time_hash(time)
@@ -181,6 +183,10 @@ describe "Notification center date alerts", js: true, with_settings: { journal_a
expect(page).to have_current_path /notifications\/date_alerts/
expect(page).to have_text 'Date alerts is an Enterprise'
expect(page).to have_text 'Please upgrade to a paid plan '
+
+ # It does not allows direct url access
+ visit notifications_center_path(filter: 'reason', name: 'dateAlert')
+ toaster.expect_error('Filters Reason filter has invalid values.')
end
end
diff --git a/spec/models/queries/notifications/filters/reason_filter_spec.rb b/spec/models/queries/notifications/filters/reason_filter_spec.rb
new file mode 100644
index 00000000000..34e4d93ecc2
--- /dev/null
+++ b/spec/models/queries/notifications/filters/reason_filter_spec.rb
@@ -0,0 +1,56 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2022 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'
+
+describe Queries::Notifications::Filters::ReasonFilter do
+ it_behaves_like 'basic query filter' do
+ let(:class_key) { :reason }
+ let(:type) { :list }
+ let(:model) { Notification }
+ let(:attribute) { :reason }
+ let(:values) { ['mentioned'] }
+
+ it_behaves_like 'non ar filter'
+
+ describe '#allowed_values' do
+ context 'with enterprise', with_ee: [:date_alerts] do
+ it 'contains all the REASONS' do
+ expect(instance.allowed_values).to eq(described_class::REASONS.keys.map { |r| [r, r] })
+ end
+ end
+
+ context 'without enterprise', with_ee: false do
+ it 'does not contains date alerts' do
+ expect(instance.allowed_values)
+ .to eq(described_class::REASONS.keys.without("dateAlert").map { |r| [r, r] })
+ end
+ end
+ end
+ end
+end
diff --git a/spec/requests/api/v3/notifications/index_resource_spec.rb b/spec/requests/api/v3/notifications/index_resource_spec.rb
index 66aeb584daa..604140eb126 100644
--- a/spec/requests/api/v3/notifications/index_resource_spec.rb
+++ b/spec/requests/api/v3/notifications/index_resource_spec.rb
@@ -160,7 +160,7 @@ describe ::API::V3::Notifications::NotificationsAPI,
end
end
- context 'with a reason filter' do
+ context 'with a reason filter', with_ee: [:date_alerts] do
shared_let(:assigned_notification) do
create(:notification,
reason: :assigned,
@@ -193,6 +193,28 @@ describe ::API::V3::Notifications::NotificationsAPI,
let(:elements) { [responsible_notification, date_alert_notification, mentioned_notification] }
end
+ context 'when using date alerts without enterprise', with_ee: false do
+ let(:filters) do
+ [
+ {
+ 'reason' => {
+ 'operator' => '=',
+ 'values' => ['dateAlert']
+ }
+ }
+ ]
+ end
+
+ it 'returns an error' do
+ expect(last_response.status)
+ .to be 400
+
+ expect(last_response.body)
+ .to be_json_eql("Filters Reason filter has invalid values.".to_json)
+ .at_path('message')
+ end
+ end
+
context 'with an invalid reason' do
let(:filters) do
[