Skip to content

Commit

Permalink
[ENG-6630] Fix citation addons (#2424)
Browse files Browse the repository at this point in the history
* fix citation addons

* add authorizedResource relationship to ConfiguredComputingAddon
  • Loading branch information
adlius authored Dec 9, 2024
1 parent 3629226 commit 0f31c61
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 42 deletions.
9 changes: 7 additions & 2 deletions app/models/addon-operation-invocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<OperationKwargs>;
@attr('object', {snakifyForApi: true}) operationResult!: OperationResult;
@attr('date') created!: Date;
Expand Down
32 changes: 8 additions & 24 deletions app/models/authorized-account.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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<any> {
// 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<any> {
// To be implemented in child classes
return;
}
}
29 changes: 29 additions & 0 deletions app/models/authorized-citation-account.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -10,6 +14,31 @@ export default class AuthorizedCitationAccountModel extends AuthorizedAccountMod

@belongsTo('external-citation-service')
externalCitationService!: AsyncBelongsTo<ExternalCitationServiceModel> & 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' {
Expand Down
28 changes: 28 additions & 0 deletions app/models/authorized-storage-account.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -10,6 +13,31 @@ export default class AuthorizedStorageAccountModel extends AuthorizedAccountMode

@belongsTo('external-storage-service')
externalStorageService!: AsyncBelongsTo<ExternalStorageServiceModel> & 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' {
Expand Down
14 changes: 5 additions & 9 deletions app/models/configured-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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> & UserReferenceModel;

@belongsTo('resource-reference', { inverse: 'configuredStorageAddons' })
authorizedResource!: AsyncBelongsTo<ResourceReferenceModel> & 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,
Expand All @@ -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,
});
Expand Down
4 changes: 4 additions & 0 deletions app/models/configured-citation-addon.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -11,6 +12,9 @@ export default class ConfiguredCitationAddonModel extends ConfiguredAddonModel {
@belongsTo('authorized-citation-account')
baseAccount!: AsyncBelongsTo<AuthorizedCitationAccountModel> & AuthorizedCitationAccountModel;

@belongsTo('resource-reference', { inverse: 'configuredCitationAddons' })
authorizedResource!: AsyncBelongsTo<ResourceReferenceModel> & ResourceReferenceModel;

get externalServiceId() {
return (this as ConfiguredCitationAddonModel).belongsTo('externalCitationService').id();
}
Expand Down
4 changes: 4 additions & 0 deletions app/models/configured-computing-addon.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -11,6 +12,9 @@ export default class ConfiguredComputingAddonModel extends ConfiguredAddonModel
@belongsTo('authorized-computing-account')
baseAccount!: AsyncBelongsTo<AuthorizedComputingAccount> & AuthorizedComputingAccount;

@belongsTo('resource-reference', { inverse: 'configuredComputingAddons' })
authorizedResource!: AsyncBelongsTo<ResourceReferenceModel> & ResourceReferenceModel;

get externalServiceId() {
return (this as ConfiguredComputingAddonModel).belongsTo('externalComputingService').id();
}
Expand Down
4 changes: 4 additions & 0 deletions app/models/configured-storage-addon.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -14,6 +15,9 @@ export default class ConfiguredStorageAddonModel extends ConfiguredAddonModel {
@belongsTo('authorized-storage-account')
baseAccount!: AsyncBelongsTo<AuthorizedStorageAccountModel> & AuthorizedStorageAccountModel;

@belongsTo('resource-reference', { inverse: 'configuredStorageAddons' })
authorizedResource!: AsyncBelongsTo<ResourceReferenceModel> & ResourceReferenceModel;

get externalServiceId() {
return (this as ConfiguredStorageAddonModel).belongsTo('externalStorageService').id();
}
Expand Down
6 changes: 3 additions & 3 deletions app/packages/files/service-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions app/packages/files/service-provider-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
}

Expand Down
7 changes: 5 additions & 2 deletions mirage/views/addons.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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}`,
Expand Down

0 comments on commit 0f31c61

Please sign in to comment.