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
[#47051] Open root folder if project folder not visible
Eric Schubert34c426f0948a
diff --git a/frontend/src/app/shared/components/storages/file-picker-base-modal.component.ts/file-picker-base-modal.component.ts b/frontend/src/app/shared/components/storages/file-picker-base-modal.component.ts/file-picker-base-modal.component.tsindex 4357ee58d96..a7145c437cf 100644--- a/frontend/src/app/shared/components/storages/file-picker-base-modal.component.ts/file-picker-base-modal.component.ts+++ b/frontend/src/app/shared/components/storages/file-picker-base-modal.component.ts/file-picker-base-modal.component.ts@@ -34,10 +34,17 @@ import {OnDestroy,OnInit,} from '@angular/core';-import { BehaviorSubject, Observable, Subscription } from 'rxjs';-import { map } from 'rxjs/operators';--import { IHalResourceLink } from 'core-app/core/state/hal-resource';+import { HttpErrorResponse } from '@angular/common/http';+import {+ BehaviorSubject,+ Observable,+ of,+ Subscription,+ switchMap,+} from 'rxjs';+import { catchError, map } from 'rxjs/operators';++import { IStorage } from 'core-app/core/state/storages/storage.model';import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';import { OpModalLocalsMap } from 'core-app/shared/components/modal/modal.types';import { OpModalComponent } from 'core-app/shared/components/modal/modal.component';@@ -62,16 +69,18 @@ export abstract class FilePickerBaseModalComponent extends OpModalComponent implprotected currentDirectory:IStorageFile;- protected get storageLink():IHalResourceLink {- return this.locals.storageLink as IHalResourceLink;+ protected get storage():IStorage {+ return this.locals.storage as IStorage;}public breadcrumbs:BreadcrumbsContent = new BreadcrumbsContent([{- text: this.locals.storageName as string,- icon: getIconForStorageType(this.locals.storageType as string),+ text: this.storage.name,+ icon: getIconForStorageType(this.storage._links.type.href),navigate: () => {},}]);+ public noAccessWarning = new BehaviorSubject(false);+public listItems$:Observable<StorageFileListItem[]> = this.storageFiles$.pipe(map((files) =>@@ -94,10 +103,11 @@ export abstract class FilePickerBaseModalComponent extends OpModalComponent implngOnInit():void {super.ngOnInit();- const location = this.locals.location as string || '/';-- this.storageFilesResourceService- .files(makeFilesCollectionLink(this.storageLink, location))+ this.entryLocation()+ .pipe(+ this.untilDestroyed(),+ switchMap((location:string) => this.storageFilesResourceService.files(makeFilesCollectionLink(this.storage._links.self, location))),+ ).subscribe((storageFiles) => {this.currentDirectory = storageFiles.parent;this.breadcrumbs = this.makeBreadcrumbs(storageFiles.ancestors, storageFiles.parent);@@ -112,6 +122,10 @@ export abstract class FilePickerBaseModalComponent extends OpModalComponent implthis.storageFilesResourceService.reset();}+ public closeWarning():void {+ this.noAccessWarning.next(false);+ }+protected abstract storageFileToListItem(file:IStorageFile, index:number):StorageFileListItem;protected enterDirectoryCallback(directory:IStorageFile):() => void {@@ -127,7 +141,7 @@ export abstract class FilePickerBaseModalComponent extends OpModalComponent implthis.loading$.next(true);this.loadingSubscription = this.storageFilesResourceService- .files(makeFilesCollectionLink(this.storageLink, ancestor.location))+ .files(makeFilesCollectionLink(this.storage._links.self, ancestor.location)).subscribe((storageFiles) => {this.currentDirectory = storageFiles.parent;this.breadcrumbs = this.makeBreadcrumbs(storageFiles.ancestors, storageFiles.parent);@@ -136,6 +150,26 @@ export abstract class FilePickerBaseModalComponent extends OpModalComponent impl});}+ private entryLocation():Observable<string> {+ if (this.locals.projectFolderId === null) {+ return of('/');+ }++ return this.storageFilesResourceService+ .file(this.storage.id, this.locals.projectFolderId as string)+ .pipe(+ map((file) => file.location),+ catchError((error:HttpErrorResponse) => {+ if (error.status !== 403) {+ throw new Error(error.message);+ }++ this.noAccessWarning.next(true);+ return of('/');+ }),+ );+ }+private cancelCurrentLoading():void {this.loadingSubscription?.unsubscribe();}@@ -143,8 +177,8 @@ export abstract class FilePickerBaseModalComponent extends OpModalComponent implprivate makeBreadcrumbs(ancestors:IStorageFile[], parent:IStorageFile):BreadcrumbsContent {const crumbs = ancestors.concat(parent).map((ancestor):Breadcrumb => {const isRoot = ancestor.location === '/';- const icon = isRoot ? getIconForStorageType(this.locals.storageType as string) : undefined;- const text = isRoot ? this.locals.storageName as string : ancestor.name;+ const icon = isRoot ? getIconForStorageType(this.storage._links.type.href) : undefined;+ const text = isRoot ? this.storage.name : ancestor.name;return { icon, text, navigate: () => this.changeLevel(ancestor) };});diff --git a/frontend/src/app/shared/components/storages/file-picker-modal/file-picker-modal.component.html b/frontend/src/app/shared/components/storages/file-picker-modal/file-picker-modal.component.htmlindex 682756053df..56af7ae1519 100644--- a/frontend/src/app/shared/components/storages/file-picker-modal/file-picker-modal.component.html+++ b/frontend/src/app/shared/components/storages/file-picker-modal/file-picker-modal.component.html@@ -9,6 +9,21 @@<div class="spot-divider"></div><div class="spot-modal--body spot-container op-file-picker--modal-body">+ <div+ *ngIf="noAccessWarning | async"+ class="op-toast -warning"+ >+ <div class="op-toast--content">+ <p>{{text.warningNoAccess}}</p>+ <button+ class="spot-link op-toast--close"+ (click)="closeWarning()"+ >+ <span class="spot-icon spot-icon_close"></span>+ </button>+ </div>+ </div>+<spot-breadcrumbs [content]="breadcrumbs"></spot-breadcrumbs><ng-container *ngIf="(loading$ | async) === false; else loadingTemplate">diff --git a/frontend/src/app/shared/components/storages/file-picker-modal/file-picker-modal.component.ts b/frontend/src/app/shared/components/storages/file-picker-modal/file-picker-modal.component.tsindex c8e801e751f..8353efe2afc 100644--- a/frontend/src/app/shared/components/storages/file-picker-modal/file-picker-modal.component.ts+++ b/frontend/src/app/shared/components/storages/file-picker-modal/file-picker-modal.component.ts@@ -58,6 +58,7 @@ import { HttpErrorResponse } from '@angular/common/http';export class FilePickerModalComponent extends FilePickerBaseModalComponent {public readonly text = {header: this.i18n.t('js.storages.file_links.select'),+ warningNoAccess: this.i18n.t('js.storages.files.project_folder_no_access'),content: {empty: this.i18n.t('js.storages.files.empty_folder'),},@@ -113,7 +114,7 @@ export class FilePickerModalComponent extends FilePickerBaseModalComponent {this.fileLinksResourceService.addFileLinks(this.locals.collectionKey as string,this.locals.addFileLinksHref as string,- this.storageLink,+ this.storage._links.self,files,).subscribe((fileLinks) => { this.toastService.addSuccess(this.text.toast.successFileLinksCreated(fileLinks.count)); },diff --git a/frontend/src/app/shared/components/storages/location-picker-modal/location-picker-modal.component.html b/frontend/src/app/shared/components/storages/location-picker-modal/location-picker-modal.component.htmlindex 8ba223626de..586289c87ff 100644--- a/frontend/src/app/shared/components/storages/location-picker-modal/location-picker-modal.component.html+++ b/frontend/src/app/shared/components/storages/location-picker-modal/location-picker-modal.component.html@@ -9,6 +9,21 @@<div class="spot-divider"></div><div class="spot-modal--body spot-container op-file-picker--modal-body">+ <div+ *ngIf="noAccessWarning | async"+ class="op-toast -warning"+ >+ <div class="op-toast--content">+ <p>{{text.warningNoAccess}}</p>+ <button+ class="spot-link op-toast--close"+ (click)="closeWarning()"+ >+ <span class="spot-icon spot-icon_close"></span>+ </button>+ </div>+ </div>+<spot-breadcrumbs [content]="breadcrumbs"></spot-breadcrumbs><ng-container *ngIf="(loading$ | async) === false; else loadingTemplate">diff --git a/frontend/src/app/shared/components/storages/location-picker-modal/location-picker-modal.component.ts b/frontend/src/app/shared/components/storages/location-picker-modal/location-picker-modal.component.tsindex f5346b435fd..fe153419c7a 100644--- a/frontend/src/app/shared/components/storages/location-picker-modal/location-picker-modal.component.ts+++ b/frontend/src/app/shared/components/storages/location-picker-modal/location-picker-modal.component.ts@@ -58,6 +58,7 @@ export class LocationPickerModalComponent extends FilePickerBaseModalComponent {public readonly text = {header: this.i18n.t('js.storages.select_location'),+ warningNoAccess: this.i18n.t('js.storages.files.project_folder_no_access'),content: {empty: this.i18n.t('js.storages.files.empty_folder'),emptyHint: this.i18n.t('js.storages.files.empty_folder_location_hint'),diff --git a/frontend/src/app/shared/components/storages/storage/storage.component.ts b/frontend/src/app/shared/components/storages/storage/storage.component.tsindex fdfcd58f224..586aa7521a1 100644--- a/frontend/src/app/shared/components/storages/storage/storage.component.ts+++ b/frontend/src/app/shared/components/storages/storage/storage.component.ts@@ -177,6 +177,18 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnDreturn (this.resource.$links as unknown&{ addFileLink:IHalResourceLink }).addFileLink.href;}+ private get projectFolderId():string|null {+ if (this.projectStorage.projectFolderMode === 'inactive') {+ return null;+ }++ if (this.projectStorage.projectFolderId === null) {+ throw new Error(`Project folder id 'null' not allowed for project folder mode '${this.projectStorage.projectFolderMode}'.`);+ }++ return this.projectStorage.projectFolderId;+ }+private onGlobalDragLeave:(_event:DragEvent) => void = (_event) => {this.dragging = Math.max(this.dragging - 1, 0);this.cdRef.detectChanges();@@ -276,17 +288,14 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnDcombineLatest([this.storage,this.fileLinks,- this.storage.pipe(switchMap((storage) => this.entryLocation(storage))),this.collectionKey(),]).pipe(first())- .subscribe(([storage, fileLinks, location, collectionKey]) => {+ .subscribe(([storage, fileLinks, collectionKey]) => {const locals = {- storageType: storage._links.type.href,- storageName: storage.name,- storageLink: storage._links.self,addFileLinksHref: this.addFileLinksHref,+ projectFolderId: this.projectFolderId,+ storage,collectionKey,- location,fileLinks,};this.opModalService.show<FilePickerModalComponent>(FilePickerModalComponent, 'global', locals);@@ -306,20 +315,6 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnDthis.filePicker.nativeElement.value = '';}- private entryLocation(storage:IStorage):Observable<string> {- if (this.projectStorage.projectFolderMode === 'inactive') {- return of('/');- }-- if (this.projectStorage.projectFolderId === null) {- throw new Error(`Project folder id 'null' not allowed for project folder mode '${this.projectStorage.projectFolderMode}'.`);- }-- return this.storageFilesResourceService- .file(storage.id, this.projectStorage.projectFolderId)- .pipe(map((file) => file.location));- }-private storageFileUpload(file:File):void {this.storage.pipe(@@ -332,15 +327,13 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnD}private selectUploadLocation(storage:IStorage):Observable<LocationData> {- return this.entryLocation(storage)+ const locals = {+ projectFolderId: this.projectFolderId,+ storage,+ };++ return this.opModalService.show<LocationPickerModalComponent>(LocationPickerModalComponent, 'global', locals).pipe(- map((location):Record<string, unknown> => ({- storageType: storage._links.type.href,- storageName: storage.name,- storageLink: storage._links.self,- location,- })),- switchMap((locals) => this.opModalService.show<LocationPickerModalComponent>(LocationPickerModalComponent, 'global', locals)),switchMap((modal) => modal.closingEvent),filter((modal) => modal.submitted),first(),diff --git a/modules/storages/app/common/storages/peripherals/storage_error_helper.rb b/modules/storages/app/common/storages/peripherals/storage_error_helper.rbindex 4d95ed96f96..47b626fdf43 100644--- a/modules/storages/app/common/storages/peripherals/storage_error_helper.rb+++ b/modules/storages/app/common/storages/peripherals/storage_error_helper.rb@@ -36,6 +36,8 @@ module Storages::Peripheralsraise API::Errors::OutboundRequestNotFound.newwhen :bad_requestraise API::Errors::BadRequest.new(error.log_message)+ when :forbidden+ raise API::Errors::Unauthorized.newelseraise API::Errors::InternalError.newenddiff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_query.rbindex 690ceee3eb0..953a211eb4f 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_query.rb@@ -44,6 +44,7 @@ module Storages::Peripherals::StorageInteraction::Nextclouddef query(file_id)file_info(file_id) >>+ method(:handle_access_control) >>method(:storage_file)end@@ -82,19 +83,27 @@ module Storages::Peripherals::StorageInteraction::Nextcloud# rubocop:enable Metrics/AbcSize- # rubocop:disable Metrics/AbcSize- def storage_file(file_info_response)+ def handle_access_control(file_info_response)data = file_info_response.ocs.data- storage_file = ::Storages::StorageFile.new(data.id,- data.name,- data.size,- data.mimetype,- Time.zone.at(data.ctime),- Time.zone.at(data.mtime),- data.owner_name,- data.modifier_name,- location(data.path),- data.dav_permissions)+ if data.statuscode == 403+ error(:forbidden)+ else+ ServiceResult.success(result: data)+ end+ end++ # rubocop:disable Metrics/AbcSize+ def storage_file(file_info_data)+ storage_file = ::Storages::StorageFile.new(file_info_data.id,+ file_info_data.name,+ file_info_data.size,+ file_info_data.mimetype,+ Time.zone.at(file_info_data.ctime),+ Time.zone.at(file_info_data.mtime),+ file_info_data.owner_name,+ file_info_data.modifier_name,+ location(file_info_data.path),+ file_info_data.dav_permissions)ServiceResult.success(result: storage_file)enddiff --git a/modules/storages/config/locales/js-en.yml b/modules/storages/config/locales/js-en.ymlindex 5f1b15968a7..f5bdb891a1a 100644--- a/modules/storages/config/locales/js-en.yml+++ b/modules/storages/config/locales/js-en.yml@@ -39,6 +39,9 @@ en:empty_folder: "This folder is empty."empty_folder_location_hint: "Click the button below to upload the file to this location."file_not_selectable_location: "Selecting a file is not possible in the process of choosing a location."+ project_folder_no_access: >+ You have no access to the project folder. Please, contact your administrator to get access or+ upload the file in another location.upload_keep_both: "Keep both"upload_replace: "Replace"