diff --git a/src/app/core/interceptors/error-interceptor.tokens.ts b/src/app/core/interceptors/error-interceptor.tokens.ts new file mode 100644 index 000000000..83b2c9e1b --- /dev/null +++ b/src/app/core/interceptors/error-interceptor.tokens.ts @@ -0,0 +1,3 @@ +import { HttpContextToken } from '@angular/common/http'; + +export const BYPASS_ERROR_INTERCEPTOR = new HttpContextToken(() => false); diff --git a/src/app/core/interceptors/error.interceptor.ts b/src/app/core/interceptors/error.interceptor.ts index 92a513d66..6bcad88d9 100644 --- a/src/app/core/interceptors/error.interceptor.ts +++ b/src/app/core/interceptors/error.interceptor.ts @@ -1,7 +1,7 @@ import { EMPTY, throwError } from 'rxjs'; import { catchError } from 'rxjs/operators'; -import { HttpContextToken, HttpErrorResponse, HttpInterceptorFn } from '@angular/common/http'; +import { HttpErrorResponse, HttpInterceptorFn } from '@angular/common/http'; import { inject } from '@angular/core'; import { Router } from '@angular/router'; @@ -12,7 +12,7 @@ import { LoaderService, ToastService } from '@osf/shared/services'; import { ERROR_MESSAGES } from '../constants'; import { AuthService } from '../services'; -export const BYPASS_ERROR_INTERCEPTOR = new HttpContextToken(() => false); +import { BYPASS_ERROR_INTERCEPTOR } from './error-interceptor.tokens'; export const errorInterceptor: HttpInterceptorFn = (req, next) => { const toastService = inject(ToastService); diff --git a/src/app/core/interceptors/index.ts b/src/app/core/interceptors/index.ts index 2f3e471eb..b3bee1a9a 100644 --- a/src/app/core/interceptors/index.ts +++ b/src/app/core/interceptors/index.ts @@ -1,3 +1,4 @@ -export * from './auth.interceptor'; -export * from './error.interceptor'; -export * from './view-only.interceptor'; +export { authInterceptor } from './auth.interceptor'; +export { errorInterceptor } from './error.interceptor'; +export { BYPASS_ERROR_INTERCEPTOR } from './error-interceptor.tokens'; +export { viewOnlyInterceptor } from './view-only.interceptor'; diff --git a/src/app/features/files/pages/files/files.component.html b/src/app/features/files/pages/files/files.component.html index aa85e6279..ecd486cbe 100644 --- a/src/app/features/files/pages/files/files.component.html +++ b/src/app/features/files/pages/files/files.component.html @@ -81,7 +81,7 @@ @if (isGoogleDrive()) { this.fileIsUploading() || this.isFilesLoading()); + isGoogleDriveButtonDisabled = computed( + () => this.isButtonDisabled() || (this.googleFilePickerComponent()?.isGFPDisabled() ?? false) + ); + readonly filesTreeActions: FilesTreeActions = { setCurrentFolder: (folder) => this.actions.setCurrentFolder(folder), setFilesIsLoading: (isLoading) => this.actions.setFilesIsLoading(isLoading), diff --git a/src/app/shared/components/google-file-picker/google-file-picker.component.ts b/src/app/shared/components/google-file-picker/google-file-picker.component.ts index f9e333d4c..6e6160851 100644 --- a/src/app/shared/components/google-file-picker/google-file-picker.component.ts +++ b/src/app/shared/components/google-file-picker/google-file-picker.component.ts @@ -112,7 +112,7 @@ export class GoogleFilePickerComponent implements OnInit { private loadOauthToken(): void { if (this.accountId()) { this.store.dispatch(new GetAuthorizedStorageOauthToken(this.accountId(), this.currentAddonType())).subscribe({ - next: () => { + complete: () => { this.accessToken.set( this.store.selectSnapshot(AddonsSelectors.getAuthorizedStorageAddonOauthToken(this.accountId())) ); diff --git a/src/app/shared/services/addons/addons.service.ts b/src/app/shared/services/addons/addons.service.ts index d04bc4eda..bf9991fdc 100644 --- a/src/app/shared/services/addons/addons.service.ts +++ b/src/app/shared/services/addons/addons.service.ts @@ -2,8 +2,10 @@ import { select } from '@ngxs/store'; import { map, Observable } from 'rxjs'; +import { HttpContext } from '@angular/common/http'; import { inject, Injectable } from '@angular/core'; +import { BYPASS_ERROR_INTERCEPTOR } from '@core/interceptors/error-interceptor.tokens'; import { ENVIRONMENT } from '@core/provider/environment.provider'; import { UserSelectors } from '@core/store/user'; import { AddonMapper } from '@osf/shared/mappers'; @@ -87,14 +89,23 @@ export class AddonsService { } getAuthorizedStorageOauthToken(accountId: string, addonType: string): Observable { + const context = new HttpContext(); + context.set(BYPASS_ERROR_INTERCEPTOR, true); + return this.jsonApiService - .patch(`${this.apiUrl}/authorized-${addonType}-accounts/${accountId}`, { - data: { - id: accountId, - type: `authorized-${addonType}-accounts`, - attributes: { serialize_oauth_token: 'true' }, + .patch( + `${this.apiUrl}/authorized-${addonType}-accounts/${accountId}`, + { + data: { + id: accountId, + type: `authorized-${addonType}-accounts`, + attributes: { serialize_oauth_token: 'true' }, + }, }, - }) + {}, + {}, + context + ) .pipe( map((response) => { return AddonMapper.fromAuthorizedAddonResponse(response as AuthorizedAddonGetResponseJsonApi); diff --git a/src/app/shared/services/datacite/datacite.service.ts b/src/app/shared/services/datacite/datacite.service.ts index 65f164292..565e4674d 100644 --- a/src/app/shared/services/datacite/datacite.service.ts +++ b/src/app/shared/services/datacite/datacite.service.ts @@ -3,7 +3,7 @@ import { EMPTY, filter, map, Observable, of, switchMap, take } from 'rxjs'; import { HttpClient, HttpContext } from '@angular/common/http'; import { inject, Injectable } from '@angular/core'; -import { BYPASS_ERROR_INTERCEPTOR } from '@core/interceptors'; +import { BYPASS_ERROR_INTERCEPTOR } from '@core/interceptors/error-interceptor.tokens'; import { ENVIRONMENT } from '@core/provider/environment.provider'; import { Identifier, IdentifiersResponseJsonApi } from '@osf/shared/models'; import { DataciteEvent } from '@osf/shared/models/datacite/datacite-event.enum'; diff --git a/src/app/shared/services/json-api.service.ts b/src/app/shared/services/json-api.service.ts index 93ec8dff3..0f702a82f 100644 --- a/src/app/shared/services/json-api.service.ts +++ b/src/app/shared/services/json-api.service.ts @@ -1,6 +1,6 @@ import { map, Observable } from 'rxjs'; -import { HttpClient, HttpEvent, HttpParams } from '@angular/common/http'; +import { HttpClient, HttpContext, HttpEvent, HttpParams } from '@angular/common/http'; import { inject, Injectable } from '@angular/core'; import { JsonApiResponse } from '@osf/shared/models'; @@ -47,10 +47,11 @@ export class JsonApiService { url: string, body: unknown, params?: Record, - headers?: Record + headers?: Record, + context?: HttpContext ): Observable { return this.http - .patch>(url, body, { params: this.buildHttpParams(params), headers }) + .patch>(url, body, { params: this.buildHttpParams(params), headers, context }) .pipe(map((response) => response.data)); }