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
[#45799] Race condition with outdated on OAuth access token
Pavel Balashov6481f97e31c0
diff --git a/frontend/src/app/core/state/file-links/file-links.service.ts b/frontend/src/app/core/state/file-links/file-links.service.tsindex 5d6edbdbea5..7daf6512726 100644--- a/frontend/src/app/core/state/file-links/file-links.service.ts+++ b/frontend/src/app/core/state/file-links/file-links.service.ts@@ -31,10 +31,12 @@ import { Injectable } from '@angular/core';import { HttpHeaders } from '@angular/common/http';import { from } from 'rxjs';import {+ catchError,groupBy,mergeMap,reduce,switchMap,+ map,tap,} from 'rxjs/operators';@@ -53,8 +55,8 @@ import idFromLink from 'core-app/features/hal/helpers/id-from-link';export class FileLinksResourceService extends ResourceCollectionService<IFileLink> {@InjectField() toastService:ToastService;- updateCollectionsForWorkPackage(fileLinksSelfLink:string):void {- this.http+ updateCollectionsForWorkPackage(fileLinksSelfLink:string):any {+ return this.http.get<IHALCollection<IFileLink>>(fileLinksSelfLink).pipe(tap((collection) => insertCollectionIntoState(this.store, collection, fileLinksSelfLink)),@@ -70,15 +72,13 @@ export class FileLinksResourceService extends ResourceCollectionService<IFileLinreturn acc;}, seed));}),- )- .subscribe(- (fileLinkCollections) => {+ map((fileLinkCollections) => {const storageId = idFromLink(fileLinkCollections.storage);const collectionKey = `${fileLinksSelfLink}?filters=[{"storage":{"operator":"=","values":["${storageId}"]}}]`;const collection = { _embedded: { elements: fileLinkCollections.fileLinks } } as IHALCollection<IFileLink>;insertCollectionIntoState(this.store, collection, collectionKey);- },- this.toastAndThrow.bind(this),+ }),+ catchError(this.toastAndThrow.bind(this)),);}diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.tsindex 0c32feccb48..9d571d144d6 100644--- a/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.ts+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.ts@@ -191,21 +191,23 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {const attachments = this.workPackage.attachments as unknown&{ href:string };this.attachmentsResourceService.fetchAttachments(attachments.href).subscribe();- // Fetch file link collections for work package (only if storages module is enabled)if (this.workPackage.$links.fileLinks) {- this.fileLinkResourceService.updateCollectionsForWorkPackage(this.workPackage.$links.fileLinks.href as string);+ this.fileLinkResourceService+ .updateCollectionsForWorkPackage(this.workPackage.$links.fileLinks.href as string)+ .subscribe(+ () => {+ this.projectsResourceService+ .lookup((this.workPackage.project as unknown&{ id:string }).id)+ .pipe(this.untilDestroyed())+ .subscribe((project) => {+ if (project._links.storages) {+ this.storages.updateCollection(project._links.self.href, project._links.storages);+ }+ });+ },+ );}- // Fetch storages for work package's project (only if storages module is enabled)- this.projectsResourceService- .lookup((this.workPackage.project as unknown&{ id:string }).id)- .pipe(this.untilDestroyed())- .subscribe((project) => {- if (project._links.storages) {- this.storages.updateCollection(project._links.self.href, project._links.storages);- }- });-// Listen to tab changes to update the tab labelthis.keepTab.observable.pipe(this.untilDestroyed())diff --git a/modules/storages/app/services/storages/file_link_sync_service.rb b/modules/storages/app/services/storages/file_link_sync_service.rbindex 65b1aba2886..2afbccfc962 100644--- a/modules/storages/app/services/storages/file_link_sync_service.rb+++ b/modules/storages/app/services/storages/file_link_sync_service.rb@@ -30,17 +30,11 @@class Storages::FileLinkSyncServiceFILESINFO_URL_PATH = "/ocs/v1.php/apps/integration_openproject/filesinfo".freeze- # @param user Current user- # @param file_links An array of FileLink objectsdef initialize(user:)@user = user@service_result = ServiceResult.success(result: [])end- # Synchronize the "cached" FileLinks in the database with a Nextcloud response.- # We assume a OAuthClientToken is present, because this service is called after- # the storage endpoint.- # @return ServiceResult with FileLinks in the resultdef call(file_links)@file_links = file_linksstorage_file_link_hash = @file_links.group_by(&:storage_id)@@ -215,7 +209,7 @@ class Storages::FileLinkSyncServicedef parse_files_info_response(response)return ServiceResult.failure(result: :error) if files_info_response_error?(response)return ServiceResult.failure(result: :not_authorized) if ["401", "403"].include?(response.code)- return ServiceResult.failure(result: :error) unless response.code == "200" # Interpret any other response as an error+ return ServiceResult.failure(result: :error) unless response.code == "200"beginresponse_hash = JSON.parse(response.body).dig('ocs', 'data')diff --git a/modules/storages/lib/api/v3/storages/storage_representer.rb b/modules/storages/lib/api/v3/storages/storage_representer.rbindex e755b55a90f..e369cdf8820 100644--- a/modules/storages/lib/api/v3/storages/storage_representer.rb+++ b/modules/storages/lib/api/v3/storages/storage_representer.rb@@ -74,8 +74,7 @@ module API::V3::Storagesendlink :authorizationState do- state = @connection_manager.authorization_state- urn = case state+ urn = case authorization_statewhen :connectedURN_CONNECTION_CONNECTEDwhen :failed_authorization@@ -83,13 +82,13 @@ module API::V3::StorageselseURN_CONNECTION_ERRORend- title = I18n.t(:"oauth_client.urn_connection_status.#{state}")+ title = I18n.t(:"oauth_client.urn_connection_status.#{authorization_state}"){ href: urn, title: }endlink :authorize do- next unless @connection_manager.authorization_state == :failed_authorization+ next unless authorization_state == :failed_authorization{ href: @connection_manager.get_authorization_uri, title: 'Authorize' }end@@ -97,5 +96,11 @@ module API::V3::Storagesdef _type'Storage'end++ private++ def authorization_state+ @authorization_state ||= @connection_manager.authorization_state+ endendend