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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#44856] use prepare link from storage response
Eric Schubertfd652900676d
diff --git a/frontend/src/app/core/state/storage-files/storage-files.service.ts b/frontend/src/app/core/state/storage-files/storage-files.service.tsindex 5c137f4f86e..6db9cb54836 100644--- a/frontend/src/app/core/state/storage-files/storage-files.service.ts+++ b/frontend/src/app/core/state/storage-files/storage-files.service.ts@@ -40,6 +40,7 @@ import { IHalResourceLink } from 'core-app/core/state/hal-resource';import { StorageFilesStore } from 'core-app/core/state/storage-files/storage-files.store';import { insertCollectionIntoState } from 'core-app/core/state/collection-store';import { IUploadLink } from 'core-app/core/state/storage-files/upload-link.model';+import { IPrepareUploadLink } from 'core-app/core/state/storages/storage.model';@Injectable()export class StorageFilesResourceService extends ResourceCollectionService<IStorageFile> {@@ -62,11 +63,8 @@ export class StorageFilesResourceService extends ResourceCollectionService<IStor);}- uploadLink(link:IHalResourceLink, fileName:string, parent:string):Observable<IUploadLink> {- return this.http.post<IUploadLink>(link.href, {- fileName,- parent,- });+ uploadLink(link:IPrepareUploadLink):Observable<IUploadLink> {+ return this.http.request<IUploadLink>(link.method, link.href, { body: link.payload });}reset():void {diff --git a/frontend/src/app/core/state/storages/storage.model.ts b/frontend/src/app/core/state/storages/storage.model.tsindex b99ae935753..b3f84d87bdd 100644--- a/frontend/src/app/core/state/storages/storage.model.ts+++ b/frontend/src/app/core/state/storages/storage.model.ts@@ -27,14 +27,24 @@//++import { ID } from '@datorama/akita';-import { IHalResourceLink, IHalResourceLinks } from 'core-app/core/state/hal-resource';+import { IHalMethodResourceLink, IHalResourceLink, IHalResourceLinks } from 'core-app/core/state/hal-resource';++export interface IPrepareUploadBody {+ projectId:ID;+ fileName:string;+ parent:string;+}++export interface IPrepareUploadLink extends IHalMethodResourceLink {+ payload:IPrepareUploadBody+}export interface IStorageHalResourceLinks extends IHalResourceLinks {- self:IHalResourceLink;type:IHalResourceLink;origin:IHalResourceLink;open:IHalResourceLink;authorizationState:IHalResourceLink;+ prepareUpload:IPrepareUploadLink[];authorize?:IHalResourceLink;}diff --git a/frontend/src/app/shared/components/storages/storage/storage.component.ts b/frontend/src/app/shared/components/storages/storage/storage.component.tsindex bed8895cd40..79d9d42cc31 100644--- a/frontend/src/app/shared/components/storages/storage/storage.component.ts+++ b/frontend/src/app/shared/components/storages/storage/storage.component.ts@@ -36,18 +36,14 @@ import {OnInit,ViewChild,} from '@angular/core';-import {- BehaviorSubject,- Observable,- throwError,-} from 'rxjs';+import { BehaviorSubject, Observable, throwError } from 'rxjs';import { catchError, switchMap, take } from 'rxjs/operators';import { CookieService } from 'ngx-cookie-service';import { v4 as uuidv4 } from 'uuid';import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { IFileLink } from 'core-app/core/state/file-links/file-link.model';-import { IStorage } from 'core-app/core/state/storages/storage.model';+import { IPrepareUploadLink, IStorage } from 'core-app/core/state/storages/storage.model';import { FileLinksResourceService } from 'core-app/core/state/file-links/file-links.service';import {fileLinkViewError,@@ -257,11 +253,7 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnDlet isUploadError = false;this.storageFilesResourceService- .uploadLink(- this.UploadResourceLink(this.storage._links.self),- file.name,- location,- )+ .uploadLink(this.uploadResourceLink(file.name, location)).pipe(switchMap((link) => this.uploadStorageFilesService.uploadFile(link, file)),catchError((error) => {@@ -291,10 +283,22 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnD);}- private UploadResourceLink(storageLink:IHalResourceLink):IHalResourceLink {+ private uploadResourceLink(fileName:string, location:string):IPrepareUploadLink {+ const project = (this.resource.project as unknown&{ id:string }).id;+ const link = this.storage._links.prepareUpload.filter((value) => project === value.payload.projectId.toString());+ if (link.length === 0) {+ throw new Error('Cannot upload to this storage. Missing permissions in project.');+ }+return {- href: `${storageLink.href}/files/prepare_upload`,- title: 'Upload resource link',+ href: link[0].href,+ method: link[0].method,+ title: link[0].title,+ payload: {+ projectId: link[0].payload.projectId,+ parent: location,+ fileName,+ },};}diff --git a/modules/storages/lib/api/v3/storages/storage_representer.rb b/modules/storages/lib/api/v3/storages/storage_representer.rbindex cd1b80ea484..9d26004ec62 100644--- a/modules/storages/lib/api/v3/storages/storage_representer.rb+++ b/modules/storages/lib/api/v3/storages/storage_representer.rb@@ -109,7 +109,7 @@ module API::V3::Storagesrepresented.host = fragment['href'].gsub(/\/+$/, '')}- links :prepare_upload do+ links :prepareUpload dostorage_projects_ids(represented).map do |project_id|{href: api_v3_paths.prepare_upload(represented.id),