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

Provide better error when no projects are visible

Oliver Günthere523f7abbab8
diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb
index 40033e2a911..930caf24843 100644
--- a/app/controllers/activities_controller.rb
+++ b/app/controllers/activities_controller.rb
@@ -30,7 +30,8 @@ class ActivitiesController < ApplicationController
include Layout
menu_item :activity
- before_action :load_and_authorize_in_optional_project,
+ before_action :warn_if_no_projects_visible,
+ :load_and_authorize_in_optional_project,
:verify_activities_module_activated,
:determine_subprojects,
:determine_author,
@@ -143,4 +144,10 @@ class ActivitiesController < ApplicationController
session[:activity] = { scope: @activity.scope,
with_subprojects: @with_subprojects }
end
+
+ def warn_if_no_projects_visible
+ unless current_user.allowed_in_any_project?(:view_project_activity)
+ render_404(message: I18n.t("homescreen.additional.no_visible_projects"))
+ end
+ end
end
diff --git a/spec/controllers/activities_controller_spec.rb b/spec/controllers/activities_controller_spec.rb
index 5e7f9c7eb31..f180975dd12 100644
--- a/spec/controllers/activities_controller_spec.rb
+++ b/spec/controllers/activities_controller_spec.rb
@@ -79,6 +79,15 @@ RSpec.describe ActivitiesController do
it { expect(assigns(:events)).to be_empty }
end
+
+ describe "for a user that sees no projects" do
+ current_user { create(:user) }
+
+ it "renders 404" do
+ get "index"
+ expect(response).to have_http_status(:not_found)
+ end
+ end
end
describe "with activated activity module" do