diff --git a/app/models/addon-operation-invocation.ts b/app/models/addon-operation-invocation.ts index 7585e2ad62..656fdf4514 100644 --- a/app/models/addon-operation-invocation.ts +++ b/app/models/addon-operation-invocation.ts @@ -4,13 +4,18 @@ import UserReferenceModel from 'ember-osf-web/models/user-reference'; import ConfiguredAddonModel from 'ember-osf-web/models/configured-addon'; import AuthorizedAccountModel from 'ember-osf-web/models/authorized-account'; -export enum ConnectedOperationNames { +export enum ConnectedStorageOperationNames { HasRevisions = 'has_revisions', ListRootItems = 'list_root_items', ListChildItems = 'list_child_items', GetItemInfo = 'get_item_info', } +export enum ConnectedCitationOperationNames { + ListRootCollections = 'list_root_collections', + ListCollectionItems = 'list_collection_items', +} + export interface OperationKwargs { itemId?: string; itemType?: ItemType; @@ -50,7 +55,7 @@ export interface Item { export default class AddonOperationInvocationModel extends Model { @attr('string') invocationStatus!: InvocationStatus; - @attr('string') operationName!: ConnectedOperationNames; + @attr('string') operationName!: ConnectedStorageOperationNames; @attr('object', {snakifyForApi: true}) operationKwargs!: Partial; @attr('object', {snakifyForApi: true}) operationResult!: OperationResult; @attr('date') created!: Date; diff --git a/app/models/authorized-account.ts b/app/models/authorized-account.ts index efc4a1725a..bddf3f3877 100644 --- a/app/models/authorized-account.ts +++ b/app/models/authorized-account.ts @@ -1,7 +1,5 @@ import Model, { attr } from '@ember-data/model'; -import { waitFor } from '@ember/test-waiters'; -import { task } from 'ember-concurrency'; -import { ConnectedOperationNames, OperationKwargs } from 'ember-osf-web/models/addon-operation-invocation'; +import { OperationKwargs } from 'ember-osf-web/models/addon-operation-invocation'; export enum ConnectedCapabilities { Access = 'ACCESS', @@ -33,28 +31,14 @@ export default class AuthorizedAccountModel extends Model { @attr('fixstring') readonly authUrl!: string; // Only returned when POSTing to /authorized-xyz-accounts @attr('boolean') readonly credentialsAvailable!: boolean; - @task - @waitFor - async getFolderItems(this: AuthorizedAccountModel, kwargs?: OperationKwargs) { - const operationKwargs = kwargs || {}; - const operationName = operationKwargs.itemId ? ConnectedOperationNames.ListChildItems : - ConnectedOperationNames.ListRootItems; - const newInvocation = this.store.createRecord('addon-operation-invocation', { - operationName, - operationKwargs, - thruAccount: this, - }); - return await newInvocation.save(); + async getFolderItems(this: AuthorizedAccountModel, _kwargs?: OperationKwargs) : Promise { + // To be implemented in child classes + return; } - @task - @waitFor - async getItemInfo(this: AuthorizedAccountModel, itemId: string) { - const newInvocation = this.store.createRecord('addon-operation-invocation', { - operationName: ConnectedOperationNames.GetItemInfo, - operationKwargs: { itemId }, - thruAccount: this, - }); - return await newInvocation.save(); + + async getItemInfo(this: AuthorizedAccountModel, _itemId: string) : Promise { + // To be implemented in child classes + return; } } diff --git a/app/models/authorized-citation-account.ts b/app/models/authorized-citation-account.ts index ccb838aedf..697879b152 100644 --- a/app/models/authorized-citation-account.ts +++ b/app/models/authorized-citation-account.ts @@ -1,4 +1,8 @@ import { AsyncBelongsTo, belongsTo } from '@ember-data/model'; +import { waitFor } from '@ember/test-waiters'; +import { task } from 'ember-concurrency'; +import { ConnectedCitationOperationNames, OperationKwargs } from 'ember-osf-web/models/addon-operation-invocation'; + import ExternalCitationServiceModel from './external-citation-service'; import AuthorizedAccountModel from './authorized-account'; @@ -10,6 +14,31 @@ export default class AuthorizedCitationAccountModel extends AuthorizedAccountMod @belongsTo('external-citation-service') externalCitationService!: AsyncBelongsTo & ExternalCitationServiceModel; + + @task + @waitFor + async getFolderItems(this: AuthorizedAccountModel, kwargs?: OperationKwargs) { + const operationKwargs = kwargs || {}; + const operationName = operationKwargs.itemId ? ConnectedCitationOperationNames.ListCollectionItems : + ConnectedCitationOperationNames.ListRootCollections; + // rename 'itemId' key to 'collectionId' + delete Object.assign(operationKwargs, { ['collectionId']: operationKwargs['itemId'] })['itemId']; + // gravyvalet doesn't like 'itemType' as a parameter + delete operationKwargs.itemType; + const newInvocation = this.store.createRecord('addon-operation-invocation', { + operationName, + operationKwargs, + thruAccount: this, + }); + return await newInvocation.save(); + } + + @task + @waitFor + async getItemInfo(this: AuthorizedAccountModel, _itemId: string) { + // This is a noop because gravyvalet does not have getItemInfo operation for citation addons + return; + } } declare module 'ember-data/types/registries/model' { diff --git a/app/models/authorized-storage-account.ts b/app/models/authorized-storage-account.ts index bb1bedd984..45ea1d0668 100644 --- a/app/models/authorized-storage-account.ts +++ b/app/models/authorized-storage-account.ts @@ -1,4 +1,7 @@ import { AsyncBelongsTo, belongsTo } from '@ember-data/model'; +import { waitFor } from '@ember/test-waiters'; +import { task } from 'ember-concurrency'; +import { ConnectedStorageOperationNames, OperationKwargs } from 'ember-osf-web/models/addon-operation-invocation'; import ExternalStorageServiceModel from './external-storage-service'; import AuthorizedAccountModel from './authorized-account'; @@ -10,6 +13,31 @@ export default class AuthorizedStorageAccountModel extends AuthorizedAccountMode @belongsTo('external-storage-service') externalStorageService!: AsyncBelongsTo & ExternalStorageServiceModel; + + @task + @waitFor + async getFolderItems(this: AuthorizedAccountModel, kwargs?: OperationKwargs) { + const operationKwargs = kwargs || {}; + const operationName = operationKwargs.itemId ? ConnectedStorageOperationNames.ListChildItems : + ConnectedStorageOperationNames.ListRootItems; + const newInvocation = this.store.createRecord('addon-operation-invocation', { + operationName, + operationKwargs, + thruAccount: this, + }); + return await newInvocation.save(); + } + + @task + @waitFor + async getItemInfo(this: AuthorizedAccountModel, itemId: string) { + const newInvocation = this.store.createRecord('addon-operation-invocation', { + operationName: ConnectedStorageOperationNames.GetItemInfo, + operationKwargs: { itemId }, + thruAccount: this, + }); + return await newInvocation.save(); + } } declare module 'ember-data/types/registries/model' { diff --git a/app/models/configured-addon.ts b/app/models/configured-addon.ts index 3f094459d6..215735b35b 100644 --- a/app/models/configured-addon.ts +++ b/app/models/configured-addon.ts @@ -2,8 +2,7 @@ import Model, { AsyncBelongsTo, attr, belongsTo } from '@ember-data/model'; import { waitFor } from '@ember/test-waiters'; import { task } from 'ember-concurrency'; -import { ConnectedOperationNames, OperationKwargs } from './addon-operation-invocation'; -import ResourceReferenceModel from './resource-reference'; +import { ConnectedStorageOperationNames, OperationKwargs } from './addon-operation-invocation'; import UserReferenceModel from './user-reference'; import { ConnectedCapabilities } from './authorized-account'; @@ -21,22 +20,19 @@ export default class ConfiguredAddonModel extends Model { @attr('string') authorizedResourceUri?: string; @attr('array') connectedCapabilities!: ConnectedCapabilities[]; - @attr('array') connectedOperationNames!: ConnectedOperationNames[]; + @attr('array') connectedOperationNames!: ConnectedStorageOperationNames[]; @attr('fixstring') rootFolder!: string; @belongsTo('user-reference', { inverse: null }) accountOwner!: AsyncBelongsTo & UserReferenceModel; - @belongsTo('resource-reference', { inverse: 'configuredStorageAddons' }) - authorizedResource!: AsyncBelongsTo & ResourceReferenceModel; - @task @waitFor async getFolderItems(this: ConfiguredAddonModel, kwargs?: OperationKwargs) { const operationKwargs = kwargs || {}; - const operationName = operationKwargs.itemId ? ConnectedOperationNames.ListChildItems : - ConnectedOperationNames.ListRootItems; + const operationName = operationKwargs.itemId ? ConnectedStorageOperationNames.ListChildItems : + ConnectedStorageOperationNames.ListRootItems; const newInvocation = this.store.createRecord('addon-operation-invocation', { operationName, operationKwargs, @@ -49,7 +45,7 @@ export default class ConfiguredAddonModel extends Model { @waitFor async getItemInfo(this: ConfiguredAddonModel, itemId: string) { const newInvocation = this.store.createRecord('addon-operation-invocation', { - operationName: ConnectedOperationNames.GetItemInfo, + operationName: ConnectedStorageOperationNames.GetItemInfo, operationKwargs: { itemId }, thruAddon: this, }); diff --git a/app/models/configured-citation-addon.ts b/app/models/configured-citation-addon.ts index 3388c99eab..388b18ff9b 100644 --- a/app/models/configured-citation-addon.ts +++ b/app/models/configured-citation-addon.ts @@ -1,5 +1,6 @@ import { AsyncBelongsTo, belongsTo } from '@ember-data/model'; +import ResourceReferenceModel from 'ember-osf-web/models/resource-reference'; import AuthorizedCitationAccountModel from './authorized-citation-account'; import ExternalCitationServiceModel from './external-citation-service'; import ConfiguredAddonModel from './configured-addon'; @@ -11,6 +12,9 @@ export default class ConfiguredCitationAddonModel extends ConfiguredAddonModel { @belongsTo('authorized-citation-account') baseAccount!: AsyncBelongsTo & AuthorizedCitationAccountModel; + @belongsTo('resource-reference', { inverse: 'configuredCitationAddons' }) + authorizedResource!: AsyncBelongsTo & ResourceReferenceModel; + get externalServiceId() { return (this as ConfiguredCitationAddonModel).belongsTo('externalCitationService').id(); } diff --git a/app/models/configured-computing-addon.ts b/app/models/configured-computing-addon.ts index d77edffc50..6009a14ba2 100644 --- a/app/models/configured-computing-addon.ts +++ b/app/models/configured-computing-addon.ts @@ -1,5 +1,6 @@ import { AsyncBelongsTo, belongsTo } from '@ember-data/model'; +import ResourceReferenceModel from 'ember-osf-web/models/resource-reference'; import AuthorizedComputingAccount from './authorized-computing-account'; import ExternalComputingService from './external-computing-service'; import ConfiguredAddonModel from './configured-addon'; @@ -11,6 +12,9 @@ export default class ConfiguredComputingAddonModel extends ConfiguredAddonModel @belongsTo('authorized-computing-account') baseAccount!: AsyncBelongsTo & AuthorizedComputingAccount; + @belongsTo('resource-reference', { inverse: 'configuredComputingAddons' }) + authorizedResource!: AsyncBelongsTo & ResourceReferenceModel; + get externalServiceId() { return (this as ConfiguredComputingAddonModel).belongsTo('externalComputingService').id(); } diff --git a/app/models/configured-storage-addon.ts b/app/models/configured-storage-addon.ts index ebfe6c8880..ed78d8ca16 100644 --- a/app/models/configured-storage-addon.ts +++ b/app/models/configured-storage-addon.ts @@ -1,4 +1,5 @@ import { AsyncBelongsTo, attr, belongsTo } from '@ember-data/model'; +import ResourceReferenceModel from 'ember-osf-web/models/resource-reference'; import AuthorizedStorageAccountModel from './authorized-storage-account'; import ConfiguredAddonModel from './configured-addon'; @@ -14,6 +15,9 @@ export default class ConfiguredStorageAddonModel extends ConfiguredAddonModel { @belongsTo('authorized-storage-account') baseAccount!: AsyncBelongsTo & AuthorizedStorageAccountModel; + @belongsTo('resource-reference', { inverse: 'configuredStorageAddons' }) + authorizedResource!: AsyncBelongsTo & ResourceReferenceModel; + get externalServiceId() { return (this as ConfiguredStorageAddonModel).belongsTo('externalStorageService').id(); } diff --git a/app/packages/files/service-file.ts b/app/packages/files/service-file.ts index dd1cedbf9e..44483e4cd8 100644 --- a/app/packages/files/service-file.ts +++ b/app/packages/files/service-file.ts @@ -6,8 +6,8 @@ import { task } from 'ember-concurrency'; import Intl from 'ember-intl/services/intl'; import Toast from 'ember-toastr/services/toast'; import ConfiguredStorageAddonModel from 'ember-osf-web/models/configured-storage-addon'; -import { ConnectedOperationNames } from 'ember-osf-web/models/addon-operation-invocation'; import { ConnectedCapabilities } from 'ember-osf-web/models/authorized-account'; +import { ConnectedStorageOperationNames } from 'ember-osf-web/models/addon-operation-invocation'; import FileModel from 'ember-osf-web/models/file'; import NodeModel from 'ember-osf-web/models/node'; import { Permission } from 'ember-osf-web/models/osf-model'; @@ -77,9 +77,9 @@ export default class ServiceFile { this.canMoveToThisProvider = false; this.getSupportedFeatures(); this.providerHandlesVersioning = configuredStorageAddon.connectedOperationNames - .includes(ConnectedOperationNames.HasRevisions); + .includes(ConnectedStorageOperationNames.HasRevisions); this.shouldShowRevisions = configuredStorageAddon.connectedOperationNames - .includes(ConnectedOperationNames.HasRevisions); + .includes(ConnectedStorageOperationNames.HasRevisions); this.parallelUploadsLimit = configuredStorageAddon.concurrentUploads; } diff --git a/app/packages/files/service-provider-file.ts b/app/packages/files/service-provider-file.ts index 9c2eb5d2f4..db7a71c92d 100644 --- a/app/packages/files/service-provider-file.ts +++ b/app/packages/files/service-provider-file.ts @@ -12,8 +12,8 @@ import CurrentUserService from 'ember-osf-web/services/current-user'; import captureException, { getApiErrorMessage } from 'ember-osf-web/utils/capture-exception'; import { ErrorDocument } from 'osf-api'; import ConfiguredStorageAddonModel from 'ember-osf-web/models/configured-storage-addon'; -import { ConnectedOperationNames } from 'ember-osf-web/models/addon-operation-invocation'; import { ConnectedCapabilities } from 'ember-osf-web/models/authorized-account'; +import { ConnectedStorageOperationNames } from 'ember-osf-web/models/addon-operation-invocation'; import ServiceFile from 'ember-osf-web/packages/files/service-file'; import { ExternalServiceCapabilities } from 'ember-osf-web/models/external-service'; @@ -43,7 +43,7 @@ export default class ServiceProviderFile { this.canMoveToThisProvider = false; this.getSupportedFeatures(); this.providerHandlesVersioning = configuredStorageAddon.connectedOperationNames - .includes(ConnectedOperationNames.HasRevisions); + .includes(ConnectedStorageOperationNames.HasRevisions); this.parallelUploadsLimit = configuredStorageAddon.concurrentUploads; } diff --git a/mirage/views/addons.ts b/mirage/views/addons.ts index 77abca3402..e77522960c 100644 --- a/mirage/views/addons.ts +++ b/mirage/views/addons.ts @@ -1,7 +1,10 @@ import { HandlerContext, ModelInstance, NormalizedRequestAttrs, Request, Response, Schema } from 'ember-cli-mirage'; import { timeout } from 'ember-concurrency'; -import { ConnectedOperationNames, InvocationStatus, ItemType } from 'ember-osf-web/models/addon-operation-invocation'; +import { + ConnectedStorageOperationNames, + InvocationStatus, ItemType, +} from 'ember-osf-web/models/addon-operation-invocation'; import AuthorizedCitationAccountModel from 'ember-osf-web/models/authorized-citation-account'; import AuthorizedComputingAccountModel from 'ember-osf-web/models/authorized-computing-account'; import { AddonCredentialFields} from 'ember-osf-web/models/authorized-account'; @@ -262,7 +265,7 @@ export function createAddonOperationInvocation(this: HandlerContext, schema: Sch const item_type = kwargs.item_type || ItemType.Folder; const fakePath = folderId.split('-') .map((folder: string) => ({ item_id: folder, item_name: folder, item_type: ItemType.Folder })); - if (attrs.operationName === ConnectedOperationNames.GetItemInfo) { + if (attrs.operationName === ConnectedStorageOperationNames.GetItemInfo) { result = { item_id: folderId, item_name: `Folder with ID ${folderId}`,