@@ -25,19 +25,25 @@ import ExternalComputingServiceModel from 'ember-osf-web/models/external-computi
2525import ExternalCitationServiceModel from 'ember-osf-web/models/external-citation-service' ;
2626import { notifyPropertyChange } from '@ember/object' ;
2727import captureException , { getApiErrorMessage } from 'ember-osf-web/utils/capture-exception' ;
28+ import ExternalLinkServiceModel from 'ember-osf-web/models/external-link-service' ;
29+ import AuthorizedLinkAccountModel from 'ember-osf-web/models/authorized-link-account' ;
30+ import ConfiguredLinkAddonModel from 'ember-osf-web/models/configured-link-addon' ;
2831
2932export type AllProviderTypes =
3033 ExternalStorageServiceModel |
3134 ExternalComputingServiceModel |
32- ExternalCitationServiceModel ;
35+ ExternalCitationServiceModel |
36+ ExternalLinkServiceModel ;
3337export type AllAuthorizedAccountTypes =
3438 AuthorizedStorageAccountModel |
3539 AuthorizedCitationAccountModel |
36- AuthorizedComputingAccountModel ;
40+ AuthorizedComputingAccountModel |
41+ AuthorizedLinkAccountModel ;
3742export type AllConfiguredAddonTypes =
3843 ConfiguredStorageAddonModel |
3944 ConfiguredCitationAddonModel |
40- ConfiguredComputingAddonModel ;
45+ ConfiguredComputingAddonModel |
46+ ConfiguredLinkAddonModel ;
4147
4248interface ProviderTypeMapper {
4349 getAuthorizedAccounts : Task < any , any > ;
@@ -82,6 +88,11 @@ export default class Provider {
8288 createAuthorizedAccount : taskFor ( this . createAuthorizedCitationAccount ) ,
8389 createConfiguredAddon : taskFor ( this . createConfiguredCitationAddon ) ,
8490 } ,
91+ externalLinkService : {
92+ getAuthorizedAccounts : taskFor ( this . getAuthorizedLinkAccounts ) ,
93+ createAuthorizedAccount : taskFor ( this . createAuthorizedLinkAccount ) ,
94+ createConfiguredAddon : taskFor ( this . createConfiguredLinkAddon ) ,
95+ } ,
8596 } ;
8697
8798 @tracked configuredAddon ?: AllConfiguredAddonTypes ;
@@ -134,6 +145,8 @@ export default class Provider {
134145 this . providerMap = this . providerTypeMapper . externalComputingService ;
135146 } else if ( provider instanceof ExternalCitationServiceModel ) {
136147 this . providerMap = this . providerTypeMapper . externalCitationService ;
148+ } else if ( provider instanceof ExternalLinkServiceModel ) {
149+ this . providerMap = this . providerTypeMapper . externalLinkService ;
137150 }
138151 taskFor ( this . initialize ) . perform ( ) ;
139152 }
@@ -211,6 +224,14 @@ export default class Provider {
211224 . filterBy ( 'externalComputingService.id' , this . provider . id ) . toArray ( ) ;
212225 }
213226
227+ @task
228+ @waitFor
229+ async getAuthorizedLinkAccounts ( ) {
230+ const authorizedLinkAccounts = await this . userReference . authorizedLinkAccounts ;
231+ this . authorizedAccounts = authorizedLinkAccounts
232+ . filterBy ( 'externalLinkService.id' , this . provider . id ) . toArray ( ) ;
233+ }
234+
214235 @task
215236 @waitFor
216237 async getAuthorizedAccounts ( ) {
@@ -278,6 +299,25 @@ export default class Provider {
278299 return newAccount ;
279300 }
280301
302+ @task
303+ @waitFor
304+ private async createAuthorizedLinkAccount ( arg : AccountCreationArgs ) {
305+ const { credentials, apiBaseUrl, displayName, initiateOauth } = arg ;
306+ const newAccount = this . store . createRecord ( 'authorized-link-account' , {
307+ credentials,
308+ apiBaseUrl,
309+ initiateOauth,
310+ externalUserId : this . currentUser . user ?. id ,
311+ authorizedCapabilities : [ 'ACCESS' , 'UPDATE' ] ,
312+ scopes : [ ] ,
313+ externalLinkService : this . provider ,
314+ accountOwner : this . userReference ,
315+ displayName,
316+ } ) ;
317+ await newAccount . save ( ) ;
318+ return newAccount ;
319+ }
320+
281321 @task
282322 @waitFor
283323 public async createAuthorizedAccount ( arg : AccountCreationArgs ) {
@@ -339,6 +379,20 @@ export default class Provider {
339379 return await configuredComputingAddon . save ( ) ;
340380 }
341381
382+ @task
383+ @waitFor
384+ private async createConfiguredLinkAddon ( account : AuthorizedComputingAccountModel ) {
385+ const configuredLinkAddon = this . store . createRecord ( 'configured-link-addon' , {
386+ externalLinkService : this . provider ,
387+ accountOwner : this . userReference ,
388+ authorizedResourceUri : this . node ! . links . iri ,
389+ baseAccount : account ,
390+ connectedCapabilities : [ 'ACCESS' , 'UPDATE' ] ,
391+ } ) ;
392+ return await configuredLinkAddon . save ( ) ;
393+ }
394+
395+
342396 @task
343397 @waitFor
344398 public async createConfiguredAddon ( account : AllAuthorizedAccountTypes ) {
0 commit comments