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

avoid sending headers and withCredentials on job status download

ulferts5ef8bd2dfacb
diff --git a/frontend/src/app/core/file-upload/op-direct-file-upload.service.ts b/frontend/src/app/core/file-upload/op-direct-file-upload.service.ts
index 24be704f210..af2012c4f7f 100644
--- a/frontend/src/app/core/file-upload/op-direct-file-upload.service.ts
+++ b/frontend/src/app/core/file-upload/op-direct-file-upload.service.ts
@@ -78,7 +78,7 @@ export class OpenProjectDirectFileUploadService extends OpenProjectFileUploadSer
body: result.form,
// Observe the response, not the body
observe: 'events',
- // This is important as the CORS policy for the bucket is * and you can't use credentals then,
+ // This is important as the CORS policy for the bucket is * and you can't use credentials then,
// besides we don't need them here anyway.
headers: {
[EXTERNAL_REQUEST_HEADER]: 'true',
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 853b6e46df3..eb38d5a1589 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
@@ -16,6 +16,7 @@ import { PathHelperService } from 'core-app/core/path-helper/path-helper.service
import { JobStatusEnum, JobStatusInterface } from 'core-app/features/job-status/job-status.interface';
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';
@Component({
templateUrl: './job-status.modal.html',
@@ -94,7 +95,7 @@ export class JobStatusModalComponent extends OpModalComponent implements OnInit
).subscribe(
(response) => this.onResponse(response),
(error) => this.handleError(error),
- () => this.isLoading = false,
+ () => { this.isLoading = false; },
);
}
@@ -144,9 +145,9 @@ export class JobStatusModalComponent extends OpModalComponent implements OnInit
this.cdRef.detectChanges();
}
- private handleRedirect(payload:any) {
+ private handleRedirect(payload:JobStatusInterface['payload']) {
if (payload?.redirect && !payload?.errors) {
- setTimeout(() => window.location.href = payload.redirect, 2000);
+ setTimeout(() => { window.location.href = payload.redirect as string; }, 2000);
this.message += `. ${this.text.redirect}`;
}
}
@@ -158,12 +159,25 @@ export class JobStatusModalComponent extends OpModalComponent implements OnInit
.get(redirectionUrl, {
observe: 'response',
responseType: 'text',
+ // This might or might not be an external request (depending on the configuration of an S3 storage)
+ // But not having headers like X-CSRF-TOKEN set works in both cases.
+ headers: {
+ [EXTERNAL_REQUEST_HEADER]: 'true',
+ },
})
.subscribe((response) => {
this.downloadHref = response.url;
this.cdRef.detectChanges();
this.downloadLink.nativeElement.click();
+ }, (error:HttpErrorResponse) => {
+ // In this case, most typically, there is a CORS error.
+ // Instead of failing completely, we show a manual link for the user to click themselves.
+ if (error.status === 0) {
+ this.downloadHref = redirectionUrl;
+
+ this.cdRef.detectChanges();
+ }
});
}
}
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 d6b1f6b5cd4..eacf0ed4216 100644
--- a/frontend/src/app/features/job-status/job-status.interface.ts
+++ b/frontend/src/app/features/job-status/job-status.interface.ts
@@ -23,5 +23,6 @@ export interface JobStatusInterface {
title?:string;
download?:string;
redirect?:string;
+ errors?:string;
};
}