Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/app/core/interceptors/error-interceptor.tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { HttpContextToken } from '@angular/common/http';

export const BYPASS_ERROR_INTERCEPTOR = new HttpContextToken<boolean>(() => false);
4 changes: 2 additions & 2 deletions src/app/core/interceptors/error.interceptor.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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<boolean>(() => false);
import { BYPASS_ERROR_INTERCEPTOR } from './error-interceptor.tokens';

export const errorInterceptor: HttpInterceptorFn = (req, next) => {
const toastService = inject(ToastService);
Expand Down
7 changes: 4 additions & 3 deletions src/app/core/interceptors/index.ts
Original file line number Diff line number Diff line change
@@ -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';
2 changes: 1 addition & 1 deletion src/app/features/files/pages/files/files.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

@if (isGoogleDrive()) {
<p-button
[disabled]="isButtonDisabled()"
[disabled]="isGoogleDriveButtonDisabled()"
outlined
raised
severity="success"
Expand Down
4 changes: 4 additions & 0 deletions src/app/features/files/pages/files/files.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ export class FilesComponent {

isButtonDisabled = computed(() => 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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
);
Expand Down
23 changes: 17 additions & 6 deletions src/app/shared/services/addons/addons.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -87,14 +89,23 @@ export class AddonsService {
}

getAuthorizedStorageOauthToken(accountId: string, addonType: string): Observable<AuthorizedAccountModel> {
const context = new HttpContext();
context.set(BYPASS_ERROR_INTERCEPTOR, true);

return this.jsonApiService
.patch<AuthorizedAddonGetResponseJsonApi>(`${this.apiUrl}/authorized-${addonType}-accounts/${accountId}`, {
data: {
id: accountId,
type: `authorized-${addonType}-accounts`,
attributes: { serialize_oauth_token: 'true' },
.patch<AuthorizedAddonGetResponseJsonApi>(
`${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);
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/services/datacite/datacite.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
7 changes: 4 additions & 3 deletions src/app/shared/services/json-api.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -47,10 +47,11 @@ export class JsonApiService {
url: string,
body: unknown,
params?: Record<string, unknown>,
headers?: Record<string, string>
headers?: Record<string, string>,
context?: HttpContext
): Observable<T> {
return this.http
.patch<JsonApiResponse<T, null>>(url, body, { params: this.buildHttpParams(params), headers })
.patch<JsonApiResponse<T, null>>(url, body, { params: this.buildHttpParams(params), headers, context })
.pipe(map((response) => response.data));
}

Expand Down
Loading