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

In the event the filter is invalid, redirect to index with error message

Kabiru Mwenja0e500c32e98b
diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb
index 5e1b7de17c7..123e79088b9 100644
--- a/app/controllers/notifications_controller.rb
+++ b/app/controllers/notifications_controller.rb
@@ -34,6 +34,7 @@ class NotificationsController < ApplicationController
no_authorization_required! :index, :split_view, :update_counter, :mark_all_read, :date_alerts, :share_upsell
before_action :check_filter, only: %i[index]
+ before_action :validate_query, only: %i[index]
def index
render_notifications_layout
@@ -101,4 +102,13 @@ class NotificationsController < ApplicationController
redirect_to notifications_date_alert_upsell_path
end
end
+
+ def validate_query
+ return if params[:filter].blank?
+
+ if %w[project reason].exclude?(params[:filter]) || !filtered_query.valid?
+ flash[:error] = I18n.t("notifications.query.invalid_filter")
+ redirect_to notifications_path
+ end
+ end
end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 258f421cb52..3d7bd5d2a29 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -2100,7 +2100,7 @@ en:
plan_name: "%{plan} enterprise plan"
plan_text_html: "Available starting with the %{plan_name}."
hide_banner: "Hide this banner"
- homescreen_description: >
+ homescreen_description: >
Enterprise plans extend the Community edition of OpenProject you are currently using.
They include add-ons, additional features and professional support that enables organisations of all sizes to achieve great things together.
homescreen_subline: By upgrading, you will also be supporting an open source project.
@@ -2534,6 +2534,8 @@ en:
mentioned: "You have been mentioned in %{work_package}"
responsible: "You have become accountable for %{work_package}"
watched: "You are watching %{work_package}"
+ query:
+ invalid_filter: "Invalid notification filter"
label_accessibility: "Accessibility"
label_account: "Account"
diff --git a/spec/features/notifications/notification_center/notification_center_spec.rb b/spec/features/notifications/notification_center/notification_center_spec.rb
index ea44eaf4759..7a944a74deb 100644
--- a/spec/features/notifications/notification_center/notification_center_spec.rb
+++ b/spec/features/notifications/notification_center/notification_center_spec.rb
@@ -423,6 +423,20 @@ RSpec.describe "Notification center",
expect(notification3.reload.read_ian).to be_truthy
end
end
+
+ context "with invalid filter parameters" do
+ it "shows error message and redirects for invalid reason" do
+ visit notifications_path(filter: "reason", name: "invalid_reason")
+ expect(page).to have_current_path(notifications_path)
+ expect(page).to have_text("Invalid notification filter")
+ end
+
+ it "shows error message and redirects for invalid filter type" do
+ visit notifications_path(filter: "invalid_filter", name: "something")
+ expect(page).to have_current_path(notifications_path)
+ expect(page).to have_text("Invalid notification filter")
+ end
+ end
end
describe "logging into deep link", with_settings: { login_required: true } do