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

Fix error reporting and add spec for it

Oliver Güntherd8e6977c8b7e
diff --git a/app/workers/work_packages/bulk_copy_job.rb b/app/workers/work_packages/bulk_copy_job.rb
index c1d09433448..0e0cdbba25f 100644
--- a/app/workers/work_packages/bulk_copy_job.rb
+++ b/app/workers/work_packages/bulk_copy_job.rb
@@ -37,5 +37,9 @@ module WorkPackages
def success_message
I18n.t(:notice_successful_create)
end
+
+ def failure_message
+ I18n.t('work_packages.bulk.copy_failed')
+ end
end
end
diff --git a/app/workers/work_packages/bulk_job.rb b/app/workers/work_packages/bulk_job.rb
index 8512b67aecd..56047f8fc0c 100644
--- a/app/workers/work_packages/bulk_job.rb
+++ b/app/workers/work_packages/bulk_job.rb
@@ -77,10 +77,6 @@ module WorkPackages
path = redirect_path(call, follow)
payload = redirect_payload(path)
- if call.errors.any?
- payload[:errors] = errors
- end
-
upsert_status status: :success,
message: success_message,
payload:
@@ -99,9 +95,12 @@ module WorkPackages
end
def failure_status_update(call)
- message = bulk_error_message(work_packages, call)
+ message = failure_message
+ html = bulk_error_message(work_packages, call)
- upsert_status status: :failure, message:
+ upsert_status status: :failure,
+ message:,
+ payload: { html: }
end
def url_helpers
diff --git a/app/workers/work_packages/bulk_move_job.rb b/app/workers/work_packages/bulk_move_job.rb
index 46ad958a6fe..9bb8370a653 100644
--- a/app/workers/work_packages/bulk_move_job.rb
+++ b/app/workers/work_packages/bulk_move_job.rb
@@ -37,5 +37,9 @@ module WorkPackages
def success_message
I18n.t(:notice_successful_update)
end
+
+ def failure_message
+ I18n.t('work_packages.bulk.move_failed')
+ end
end
end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index ca035d5e700..22a17431fcc 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -405,6 +405,8 @@ en:
other: '%{count} work package descendants'
bulk:
+ copy_failed: "The work packages could not be copied."
+ move_failed: "The work packages could not be moved."
could_not_be_saved: "The following work packages could not be saved:"
none_could_be_saved: "None of the %{total} work packages could be updated."
x_out_of_y_could_be_saved: "%{failing} out of the %{total} work packages could not be updated while %{success} could."
diff --git a/frontend/src/app/features/job-status/job-status-modal/job-status.modal.html b/frontend/src/app/features/job-status/job-status-modal/job-status.modal.html
index 8c3ce8b369a..130acfcc6fe 100644
--- a/frontend/src/app/features/job-status/job-status-modal/job-status.modal.html
+++ b/frontend/src/app/features/job-status/job-status-modal/job-status.modal.html
@@ -27,6 +27,12 @@
[attr.href]="downloadHref"
></a>
</span>
+ <ng-container *ngIf="htmlContent">
+ <div
+ class="job-status--modal-additional-content"
+ [innerHTML]="htmlContent"
+ ></div>
+ </ng-container>
<ng-container *ngIf="payload?.errors">
<h3 class="job-status--modal-additional-errors" [textContent]="text.errors"></h3>
<ul *ngFor="let error of payload.errors">
diff --git a/frontend/src/app/features/job-status/job-status-modal/job-status.modal.ts b/frontend/src/app/features/job-status/job-status-modal/job-status.modal.ts
index 86366382514..a93e721031f 100644
--- a/frontend/src/app/features/job-status/job-status-modal/job-status.modal.ts
+++ b/frontend/src/app/features/job-status/job-status-modal/job-status.modal.ts
@@ -36,6 +36,10 @@ import {
import { ToastService } from 'core-app/shared/components/toaster/toast.service';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { EXTERNAL_REQUEST_HEADER } from 'core-app/features/hal/http/openproject-header-interceptor';
+import {
+ DomSanitizer,
+ SafeHtml,
+} from '@angular/platform-browser';
@Component({
templateUrl: './job-status.modal.html',
@@ -75,6 +79,9 @@ export class JobStatusModalComponent extends OpModalComponent implements OnInit
/** Title to show */
public title:string = this.text.title;
+ /** Additional html to render */
+ public htmlContent:SafeHtml|null = null;
+
/** A link in case the job results in a download */
public downloadHref:string|null = null;
@@ -88,6 +95,7 @@ export class JobStatusModalComponent extends OpModalComponent implements OnInit
readonly apiV3Service:ApiV3Service,
readonly loadingIndicator:LoadingIndicatorService,
readonly toastService:ToastService,
+ readonly sanitization:DomSanitizer,
readonly httpClient:HttpClient) {
super(locals, cdRef, elementRef);
@@ -153,12 +161,19 @@ export class JobStatusModalComponent extends OpModalComponent implements OnInit
this.title = body.payload.title || this.text.title;
this.handleRedirect(body.payload);
this.handleDownload(body.payload?.download);
+ this.handleHTML(body.payload?.html);
}
this.statusIcon = this.iconForStatus();
this.cdRef.detectChanges();
}
+ private handleHTML(content?:string) {
+ if (content) {
+ this.htmlContent = this.sanitization.bypassSecurityTrustHtml(content);
+ }
+ }
+
private handleRedirect(payload:JobStatusInterface['payload']) {
if (payload?.redirect && !payload?.errors) {
setTimeout(() => { window.location.href = payload.redirect as string; }, 2000);
diff --git a/frontend/src/app/features/job-status/job-status.interface.ts b/frontend/src/app/features/job-status/job-status.interface.ts
index eacf0ed4216..3fed2787753 100644
--- a/frontend/src/app/features/job-status/job-status.interface.ts
+++ b/frontend/src/app/features/job-status/job-status.interface.ts
@@ -24,5 +24,6 @@ export interface JobStatusInterface {
download?:string;
redirect?:string;
errors?:string;
+ html?:string;
};
}
diff --git a/spec/features/work_packages/bulk/copy_work_package_spec.rb b/spec/features/work_packages/bulk/copy_work_package_spec.rb
index 9abd8651ad5..569a36f4502 100644
--- a/spec/features/work_packages/bulk/copy_work_package_spec.rb
+++ b/spec/features/work_packages/bulk/copy_work_package_spec.rb
@@ -193,6 +193,33 @@ describe 'Copy work packages through Rails view', js: true do
text: "#{child.id} (descendant of selected): Type #{I18n.t('activerecord.errors.messages.inclusion')}"
)
end
+
+ context 'when the limit to move in the frontend is 0',
+ with_settings: { work_packages_bulk_request_limit: 0 } do
+ it 'shows the errors properly in the frontend' do
+ click_on 'Copy and follow'
+
+ expect(page).to have_text 'The job has been queued and will be processed shortly.'
+
+ perform_enqueued_jobs
+
+ expect(page).to have_text 'The work packages could not be copied.', wait: 10
+
+ expect(page).to have_text I18n.t('work_packages.bulk.none_could_be_saved', total: 3)
+
+ expect(page)
+ .to have_text I18n.t('work_packages.bulk.selected_because_descendants', total: 3, selected: 2)
+
+ expect(page)
+ .to have_text "#{work_package.id}: Type #{I18n.t('activerecord.errors.messages.inclusion')}"
+
+ expect(page)
+ .to have_text "#{work_package2.id}: Type #{I18n.t('activerecord.errors.messages.inclusion')}"
+
+ expect(page)
+ .to have_text "#{child.id} (descendant of selected): Type #{I18n.t('activerecord.errors.messages.inclusion')}"
+ end
+ end
end
end