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

[#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.ts
index 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<IFileLin
return 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.ts
index 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 label
this.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.rb
index 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::FileLinkSyncService
FILESINFO_URL_PATH = "/ocs/v1.php/apps/integration_openproject/filesinfo".freeze
- # @param user Current user
- # @param file_links An array of FileLink objects
def 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 result
def call(file_links)
@file_links = file_links
storage_file_link_hash = @file_links.group_by(&:storage_id)
@@ -215,7 +209,7 @@ class Storages::FileLinkSyncService
def 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"
begin
response_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.rb
index 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::Storages
end
link :authorizationState do
- state = @connection_manager.authorization_state
- urn = case state
+ urn = case authorization_state
when :connected
URN_CONNECTION_CONNECTED
when :failed_authorization
@@ -83,13 +82,13 @@ module API::V3::Storages
else
URN_CONNECTION_ERROR
end
- title = I18n.t(:"oauth_client.urn_connection_status.#{state}")
+ title = I18n.t(:"oauth_client.urn_connection_status.#{authorization_state}")
{ href: urn, title: }
end
link :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::Storages
def _type
'Storage'
end
+
+ private
+
+ def authorization_state
+ @authorization_state ||= @connection_manager.authorization_state
+ end
end
end