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

Show an error when WP cannot be loaded

Oliver Günthere0f5dee13d21
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 04c650f8167..094358dea2f 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -295,11 +295,16 @@ class ApplicationController < ActionController::Base
def require_admin
return unless require_login
+
render_403 unless User.current.admin?
end
- def deny_access
- User.current.logged? ? render_403 : require_login
+ def deny_access(not_found: false)
+ if User.current.logged?
+ not_found ? render_404 : render_403
+ else
+ require_login
+ end
end
# Authorize the user for the requested action
diff --git a/app/controllers/work_packages_controller.rb b/app/controllers/work_packages_controller.rb
index a139d0c078e..e86efd714d0 100644
--- a/app/controllers/work_packages_controller.rb
+++ b/app/controllers/work_packages_controller.rb
@@ -140,7 +140,7 @@ class WorkPackagesController < ApplicationController
end
def authorize_on_work_package
- deny_access unless work_package
+ deny_access(not_found: true) unless work_package
end
def protect_from_unauthorized_export
diff --git a/frontend/src/app/components/states/state-cache.service.ts b/frontend/src/app/components/states/state-cache.service.ts
index 6ebf1fcb529..3dc01879230 100644
--- a/frontend/src/app/components/states/state-cache.service.ts
+++ b/frontend/src/app/components/states/state-cache.service.ts
@@ -108,7 +108,10 @@ export abstract class StateCacheService<T> {
// Refresh when stale or being forced
if (this.stale(state) || force) {
- this.load(id).then(wp => state.putValue(wp));
+ return this.load(id).then(wp => {
+ state.putValue(wp);
+ return wp;
+ });
}
return state.valuesPromise() as Promise<T>;
diff --git a/frontend/src/app/modules/work_packages/routing/wp-view-base/work-package-single-view.base.ts b/frontend/src/app/modules/work_packages/routing/wp-view-base/work-package-single-view.base.ts
index 68e47e6b1e0..c00564c395c 100644
--- a/frontend/src/app/modules/work_packages/routing/wp-view-base/work-package-single-view.base.ts
+++ b/frontend/src/app/modules/work_packages/routing/wp-view-base/work-package-single-view.base.ts
@@ -43,6 +43,7 @@ import {
IWorkPackageEditingService,
IWorkPackageEditingServiceToken
} from "core-components/wp-edit-form/work-package-editing.service.interface";
+import {WorkPackageNotificationService} from "core-components/wp-edit/wp-notification.service";
export class WorkPackageSingleViewBase implements OnDestroy {
@@ -53,6 +54,7 @@ export class WorkPackageSingleViewBase implements OnDestroy {
public PathHelper:PathHelperService = this.injector.get(PathHelperService);
protected wpEditing:IWorkPackageEditingService = this.injector.get(IWorkPackageEditingServiceToken);
protected wpTableFocus:WorkPackageViewFocusService = this.injector.get(WorkPackageViewFocusService);
+ protected wpNotifications:WorkPackageNotificationService = this.injector.get(WorkPackageNotificationService);
protected projectCacheService:ProjectCacheService = this.injector.get(ProjectCacheService);
protected authorisationService:AuthorisationService = this.injector.get(AuthorisationService);
protected cdRef:ChangeDetectorRef = this.injector.get(ChangeDetectorRef);
@@ -82,7 +84,13 @@ export class WorkPackageSingleViewBase implements OnDestroy {
* Needs to be run explicitly by descendants.
*/
protected observeWorkPackage() {
- this.wpCacheService.loadWorkPackage(this.workPackageId).values$()
+ /** Require the work package once to ensure we're displaying errors */
+ this.wpCacheService.require(this.workPackageId)
+ .catch((error) => this.wpNotifications.handleRawError(error));
+
+ /** Stream updates of the work package */
+ this.wpCacheService.state(this.workPackageId)
+ .values$()
.pipe(
takeUntil(componentDestroyed(this))
)
diff --git a/spec/controllers/work_packages_controller_spec.rb b/spec/controllers/work_packages_controller_spec.rb
index 7a4f236ca4e..8a4959213a2 100644
--- a/spec/controllers/work_packages_controller_spec.rb
+++ b/spec/controllers/work_packages_controller_spec.rb
@@ -51,8 +51,8 @@ describe WorkPackagesController, type: :controller do
call_action
end
- it 'should render a 403' do
- expect(response.response_code).to be === 403
+ it 'should render a 404' do
+ expect(response.response_code).to be === 404
end
end
diff --git a/spec/features/work_packages/navigation_spec.rb b/spec/features/work_packages/navigation_spec.rb
index a7adf83e06e..63f06d02029 100644
--- a/spec/features/work_packages/navigation_spec.rb
+++ b/spec/features/work_packages/navigation_spec.rb
@@ -144,13 +144,17 @@ RSpec.feature 'Work package navigation', js: true, selenium: true do
full_work_package.ensure_page_loaded
end
- scenario 'show 404 upon wrong url' do
- visit '/work_packages/0'
+ scenario 'loading an unknown work package ID' do
+ visit '/work_packages/999999999'
- expect(page).to have_selector('.errorExplanation',
- text: I18n.t('notice_not_authorized'))
+ page404 = ::Pages::Page.new
+ page404.expect_notification type: :error, message: I18n.t(:notice_file_not_found)
+
+ visit "/projects/#{project.identifier}/work_packages/999999999"
+ page404.expect_and_dismiss_notification type: :error, message: I18n.t('api_v3.errors.code_404')
end
+
# Regression #29994
scenario 'access the work package views directly from a non-angular view' do
visit project_path(project)