Skip to content

Commit 0b06f34

Browse files
authored
[ENG-8505] Added the ability to get the oauth token for the GFP (CenterForOpenScience#297)
* chore(mocks): added global testing mocks and a new osftestingstoremodule * chore(tests): Added tests to continue the process * feat(code): added the condition for google drive * feat(google-file-picker): Added the initial google file picker component * feat(GFP-service): add the google file picker service * feat(service): added the google file picker download service * chore(npm): added strict typing for the google file picker * feat(component): added more functionality to the component with tests * feat(eng-8505): Added more logic to get the oauth token from the server * chore(test-updates): updated states, services and tests * chore(unit-tests): Added more tdd tests to get the oauth token * feat(oauth-token): added oauth token retrieval * chore(refactor): updated a model to be more explicit in the name * chore(pr review): Updates to handle comments from a PR
1 parent 17843a7 commit 0b06f34

File tree

44 files changed

+1280
-331
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1280
-331
lines changed

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ module.exports = tseslint.config(
9090
files: ['**/*.spec.ts'],
9191
rules: {
9292
'@typescript-eslint/no-explicit-any': 'off',
93+
'@typescript-eslint/no-empty-function': 'off',
9394
},
9495
}
9596
);

package-lock.json

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
"@commitlint/cli": "^19.7.1",
6868
"@commitlint/config-conventional": "^19.7.1",
6969
"@compodoc/compodoc": "^1.1.26",
70+
"@types/gapi": "^0.0.47",
71+
"@types/gapi.auth2": "^0.0.61",
7072
"@types/jest": "^29.5.14",
7173
"@types/markdown-it": "^14.1.2",
7274
"angular-eslint": "19.1.0",

src/@types/global.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type gapi from 'gapi-script'; // or just `import gapi from 'gapi-script';`
2+
3+
declare global {
4+
interface Window {
5+
gapi: typeof gapi;
6+
google: {
7+
picker: typeof google.picker;
8+
};
9+
}
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { InjectionToken } from '@angular/core';
2+
3+
import { environment } from 'src/environments/environment';
4+
5+
export const ENVIRONMENT = new InjectionToken<typeof environment>('App Environment', {
6+
providedIn: 'root',
7+
factory: () => environment,
8+
});

src/app/features/project/addons/components/configure-addon/configure-addon.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('Component: Configure Addon', () => {
7373
});
7474

7575
it('should validate the constuctor values', () => {
76-
expect(component.storageAddon()).toBeUndefined();
76+
expect(component.storageAddon()).toBeNull();
7777
expect(component.addon()).toEqual(
7878
Object({
7979
attributes: {

src/app/features/project/addons/components/configure-addon/configure-addon.component.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class ConfigureAddonComponent implements OnInit {
7676
* Signal representing the currently selected `Addon` from the list of available storage addons.
7777
* This value updates reactively as the selection changes.
7878
*/
79-
public storageAddon = signal<AddonModel | undefined>(undefined);
79+
public storageAddon = signal<AddonModel | null>(null);
8080
/**
8181
* Signal representing the currently selected and configured storage addon model.
8282
* This may be `null` if no addon has been configured.
@@ -128,9 +128,7 @@ export class ConfigureAddonComponent implements OnInit {
128128

129129
if (addon) {
130130
this.storageAddon.set(
131-
this.store.selectSnapshot((state) =>
132-
AddonsSelectors.getStorageAddon(state.addons, addon.externalStorageServiceId || '')
133-
)
131+
this.store.selectSnapshot(AddonsSelectors.getStorageAddon(addon.externalStorageServiceId || ''))
134132
);
135133

136134
this.addon.set(addon);

src/app/features/project/addons/components/connect-configured-addon/connect-configured-addon.component.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ import { AddonConfigMap } from '@osf/features/project/addons/utils';
1818
import { SubHeaderComponent } from '@osf/shared/components';
1919
import { ProjectAddonsStepperValue } from '@osf/shared/enums';
2020
import { getAddonTypeString } from '@osf/shared/helpers';
21+
import { AuthorizedAccountModel } from '@osf/shared/models/addons/authorized-account.model';
2122
import {
2223
AddonSetupAccountFormComponent,
2324
AddonTermsComponent,
2425
FolderSelectorComponent,
2526
} from '@shared/components/addons';
26-
import { AddonModel, AddonTerm, AuthorizedAddon, AuthorizedAddonRequestJsonApi } from '@shared/models';
27+
import { AddonModel, AddonTerm, AuthorizedAddonRequestJsonApi } from '@shared/models';
2728
import { AddonDialogService, AddonFormService, AddonOperationInvocationService, ToastService } from '@shared/services';
2829
import {
2930
AddonsSelectors,
@@ -74,9 +75,9 @@ export class ConnectConfiguredAddonComponent {
7475
protected readonly stepper = viewChild(Stepper);
7576
protected accountNameControl = new FormControl('');
7677
protected terms = signal<AddonTerm[]>([]);
77-
protected addon = signal<AddonModel | AuthorizedAddon | null>(null);
78+
protected addon = signal<AddonModel | AuthorizedAccountModel | null>(null);
7879
protected addonAuthUrl = signal<string>('/settings/addons');
79-
protected currentAuthorizedAddonAccounts = signal<AuthorizedAddon[]>([]);
80+
protected currentAuthorizedAddonAccounts = signal<AuthorizedAccountModel[]>([]);
8081
protected chosenAccountId = signal('');
8182
protected chosenAccountName = signal('');
8283
protected selectedRootFolderId = signal('');
@@ -114,7 +115,6 @@ export class ConnectConfiguredAddonComponent {
114115

115116
protected resourceUri = computed(() => {
116117
const id = this.route.parent?.parent?.snapshot.params['id'];
117-
118118
return `${environment.webUrl}/${id}`;
119119
});
120120

@@ -128,7 +128,7 @@ export class ConnectConfiguredAddonComponent {
128128
});
129129

130130
constructor() {
131-
const addon = this.router.getCurrentNavigation()?.extras.state?.['addon'] as AddonModel | AuthorizedAddon;
131+
const addon = this.router.getCurrentNavigation()?.extras.state?.['addon'] as AddonModel | AuthorizedAccountModel;
132132
if (!addon) {
133133
this.router.navigate([`${this.baseUrl()}/addons`]);
134134
}
@@ -243,7 +243,7 @@ export class ConnectConfiguredAddonComponent {
243243

244244
private processAuthorizedAddons(
245245
addonConfig: AddonConfigMap[keyof AddonConfigMap],
246-
currentAddon: AddonModel | AuthorizedAddon
246+
currentAddon: AddonModel | AuthorizedAccountModel
247247
) {
248248
const authorizedAddons = addonConfig.getAuthorizedAddons();
249249
const matchingAddons = this.findMatchingAddons(authorizedAddons, currentAddon);
@@ -261,9 +261,9 @@ export class ConnectConfiguredAddonComponent {
261261
}
262262

263263
private findMatchingAddons(
264-
authorizedAddons: AuthorizedAddon[],
265-
currentAddon: AddonModel | AuthorizedAddon
266-
): AuthorizedAddon[] {
264+
authorizedAddons: AuthorizedAccountModel[],
265+
currentAddon: AddonModel | AuthorizedAccountModel
266+
): AuthorizedAccountModel[] {
267267
return authorizedAddons.filter((addon) => addon.externalServiceName === currentAddon.externalServiceName);
268268
}
269269

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Observable } from 'rxjs';
22

3-
import { AuthorizedAddon } from '@shared/models';
3+
import { AuthorizedAccountModel } from '@shared/models';
44

55
export interface AddonConfigActions {
66
getAddons: () => Observable<void>;
7-
getAuthorizedAddons: () => AuthorizedAddon[];
7+
getAuthorizedAddons: () => AuthorizedAccountModel[];
88
}

src/app/features/settings/addons/addons.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,14 @@ export class AddonsComponent {
140140
}
141141

142142
constructor() {
143+
// TODO There should not be three effects
143144
effect(() => {
144145
if (this.currentUser()) {
145146
this.actions.getAddonsUserReference();
146147
}
147148
});
148149

150+
// TODO There should not be three effects
149151
effect(() => {
150152
if (this.currentUser() && this.userReferenceId()) {
151153
const action = this.currentAction();
@@ -157,6 +159,7 @@ export class AddonsComponent {
157159
}
158160
});
159161

162+
// TODO There should not be three effects
160163
effect(() => {
161164
if (this.currentUser() && this.userReferenceId()) {
162165
this.fetchAllAuthorizedAddons(this.userReferenceId());

0 commit comments

Comments
 (0)