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
Refactored storage information box buttons
Andreas Pfohlb85e6b88f505
diff --git a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.component.ts b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.component.tsindex 1fadf723a78..edddb1987c1 100644--- a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.component.ts+++ b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.component.ts@@ -27,9 +27,11 @@//++import {- ChangeDetectionStrategy, Component, Input, OnInit,+ ChangeDetectionStrategy,+ Component,+ Input,+ OnInit,} from '@angular/core';-import { BehaviorSubject, Observable } from 'rxjs';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';@@ -44,6 +46,9 @@ import { CurrentUserService } from 'core-app/core/current-user/current-user.servimport { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';import { I18nService } from 'core-app/core/i18n/i18n.service';import isNewResource from 'core-app/features/hal/helpers/is-new-resource';+import { StorageActionButton } from 'core-app/shared/components/file-links/file-link-list/storage-action-button';++import { BehaviorSubject, Observable } from 'rxjs';import { CookieService } from 'ngx-cookie-service';import { v4 as uuidv4 } from 'uuid';@@ -63,8 +68,6 @@ export class FileLinkListComponent extends UntilDestroyedMixin implements OnInitinformationBoxContent:string;- informationBoxButton:string;-informationBoxIcon:string;allowEditing = false;@@ -73,11 +76,10 @@ export class FileLinkListComponent extends UntilDestroyedMixin implements OnInitshowFileLinks$ = new BehaviorSubject<boolean>(false);+ buttons = new BehaviorSubject<StorageActionButton[]>([]);+private readonly storageTypeMap:{ [urn:string]:string; } = {'urn:openproject-org:api:v3:storages:Nextcloud': 'Nextcloud',- 'urn:openproject-org:api:v3:storages:authorization:FailedAuthentication': 'FailedAuthentication',- 'urn:openproject-org:api:v3:storages:authorization:Error': 'Error',- 'urn:openproject-org:api:v3:storages:authorization:Connected': 'Connected',};text:{@@ -96,7 +98,9 @@ export class FileLinkListComponent extends UntilDestroyedMixin implements OnInit}};- private informationActionUrl = '#';+ private get storageLocation():string {+ return this.storage._links.origin.href;+ }constructor(private readonly i18n:I18nService,@@ -135,13 +139,7 @@ export class FileLinkListComponent extends UntilDestroyedMixin implements OnInit}public openStorageLocation():void {- const nonce = uuidv4();-- this.cookieService.set(`oauth_state_${nonce}`, window.location.href, {- path: '/',- });-- window.location.href = `${this.informationActionUrl}&state=${nonce}`;+ window.open(this.storageLocation, '_blank');}public isDisabled(fileLink:IFileLink):boolean {@@ -180,34 +178,83 @@ export class FileLinkListComponent extends UntilDestroyedMixin implements OnInit}private setAuthorizationFailureState(fileLinkCount:number):void {- this.informationBoxHeader = this.text.infoBox.authorizationFailureHeader;- this.informationBoxContent = this.text.infoBox.authorizationFailureContent;- this.informationBoxButton = this.text.infoBox.loginButton;- this.informationBoxIcon = 'import';- this.informationActionUrl = this.storage._links.authorize?.href as string;+ this.prepareInformationBox(+ this.text.infoBox.authorizationFailureHeader,+ this.text.infoBox.authorizationFailureContent,+ 'import',+ );++ this.buttons.next([+ new StorageActionButton(+ this.text.infoBox.loginButton,+ () => {+ if (this.storage._links.authorize) {+ const nonce = uuidv4();+ this.setAuthorizationCallbackCookie(nonce);+ window.location.href = FileLinkListComponent.authorizationFailureActionUrl(+ this.storage._links.authorize.href,+ nonce,+ );+ } else {+ throw new Error('Authorize link is missing!');+ }+ },+ ),+ ]);+this.showInformationBox$.next(true);this.showFileLinks$.next(fileLinkCount > 0);}+ private setAuthorizationCallbackCookie(nonce:string):void {+ this.cookieService.set(`oauth_state_${nonce}`, window.location.href, {+ path: '/',+ });+ }++ private static authorizationFailureActionUrl(baseUrl:string, nonce:string):string {+ return `${baseUrl}&state=${nonce}`;+ }+private setConnectionErrorState():void {- this.informationBoxHeader = this.text.infoBox.connectionErrorHeader;- this.informationBoxContent = this.text.infoBox.connectionErrorContent;- this.informationBoxButton = this.text.infoBox.loginButton;- this.informationBoxIcon = 'remove-link';- this.informationActionUrl = this.storage._links.origin.href;+ this.prepareInformationBox(+ this.text.infoBox.connectionErrorHeader,+ this.text.infoBox.connectionErrorContent,+ 'remove-link',+ );++ this.buttons.next([]);+this.showInformationBox$.next(true);this.showFileLinks$.next(false);}private setEmptyFileLinkListState():void {- this.informationBoxHeader = this.text.infoBox.emptyStorageHeader;- this.informationBoxContent = this.text.infoBox.emptyStorageContent;- this.informationBoxButton = this.text.infoBox.emptyStorageButton;- this.informationBoxIcon = 'add-link';+ this.prepareInformationBox(+ this.text.infoBox.emptyStorageHeader,+ this.text.infoBox.emptyStorageContent,+ 'add-link',+ );++ this.buttons.next([+ new StorageActionButton(+ this.text.infoBox.emptyStorageButton,+ () => {+ window.open(this.storageLocation, '_blank');+ },+ ),+ ]);+this.showInformationBox$.next(true);this.showFileLinks$.next(false);}+ private prepareInformationBox(header:string, content:string, icon:string):void {+ this.informationBoxHeader = header;+ this.informationBoxContent = content;+ this.informationBoxIcon = icon;+ }+private initializeLocales():void {const storageType = this.storageTypeMap[this.storage._links.type.href];this.text = {diff --git a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.html b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.htmlindex 106f885e2ef..c8d2a09aded 100644--- a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.html+++ b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.html@@ -4,11 +4,11 @@<op-storage-information*ngIf="showInformationBox$ | async"class="op-files-tab--storage-info-box"+ data-qa-selector="op-files-tab--storage-information"[infoIcon]="informationBoxIcon"[infoTextHeader]="informationBoxHeader"[infoTextContent]="informationBoxContent"- [buttonText]="informationBoxButton"- (buttonClickEventEmitter)="openStorageLocation()"+ [buttons]="buttons | async"></op-storage-information><uldiff --git a/frontend/src/app/shared/components/file-links/file-link-list/storage-action-button.ts b/frontend/src/app/shared/components/file-links/file-link-list/storage-action-button.tsnew file mode 100644index 00000000000..36000b6099d--- /dev/null+++ b/frontend/src/app/shared/components/file-links/file-link-list/storage-action-button.ts@@ -0,0 +1,3 @@+export class StorageActionButton {+ constructor(public readonly label:string, public readonly action:() => void) { }+}diff --git a/frontend/src/app/shared/components/file-links/storage-information/storage-information.component.ts b/frontend/src/app/shared/components/file-links/storage-information/storage-information.component.tsindex 2743abe3d31..222cddc12f4 100644--- a/frontend/src/app/shared/components/file-links/storage-information/storage-information.component.ts+++ b/frontend/src/app/shared/components/file-links/storage-information/storage-information.component.ts@@ -27,8 +27,9 @@//++import {- ChangeDetectionStrategy, Component, EventEmitter, Input, Output,+ ChangeDetectionStrategy, Component, Input,} from '@angular/core';+import { StorageActionButton } from 'core-app/shared/components/file-links/file-link-list/storage-action-button';@Component({selector: 'op-storage-information',@@ -42,7 +43,5 @@ export class StorageInformationComponent {@Input() infoTextContent:string;- @Input() buttonText:string;-- @Output() buttonClickEventEmitter = new EventEmitter();+ @Input() buttons:StorageActionButton[];}diff --git a/frontend/src/app/shared/components/file-links/storage-information/storage-information.html b/frontend/src/app/shared/components/file-links/storage-information/storage-information.htmlindex 9d3f9347903..af155715db6 100644--- a/frontend/src/app/shared/components/file-links/storage-information/storage-information.html+++ b/frontend/src/app/shared/components/file-links/storage-information/storage-information.html@@ -18,9 +18,9 @@<divclass="button-box">- <button+ <button *ngFor="let button of buttons"class="button op-files-tab--storage-info-box-button"- (click)="buttonClickEventEmitter.emit()"+ (click)="button.action()"><op-iconicon-classes="button--icon spot-icon spot-icon_external-link"@@ -31,6 +31,6 @@</op-icon><spanclass="button--text"- >{{buttonText}}</span>+ >{{button.label}}</span></button></div>diff --git a/modules/storages/spec/features/show_file_links_spec.rb b/modules/storages/spec/features/show_file_links_spec.rbindex f4796170d6f..237b1759cd1 100644--- a/modules/storages/spec/features/show_file_links_spec.rb+++ b/modules/storages/spec/features/show_file_links_spec.rb@@ -74,4 +74,25 @@ describe 'Showing of file links in work package', with_flag: { storages_module_aexpect(page).to have_selector('[data-qa-selector="op-tab-content--tab-section"]', count: 1)endend++ context 'if user is not authorized in Nextcloud' do+ before do+ allow(connection_manager).to receive(:authorization_state).and_return(:failed_authorization)+ allow(connection_manager).to receive(:redirect_to_oauth_authorize).and_return('https://example.com/authorize')+ end++ it 'must show storage information box with login button' do+ expect(page.find('[data-qa-selector="op-files-tab--storage-information"]')).to have_selector('button', count: 1)+ end+ end++ context 'if an error occurred while authorizing to Nextcloud' do+ before do+ allow(connection_manager).to receive(:authorization_state).and_return(:error)+ end++ it 'must show storage information box' do+ expect(page).to have_selector('[data-qa-selector="op-files-tab--storage-information"]', count: 1)+ end+ endend