diff --git a/app/adapters/addon-service.ts b/app/adapters/addon-service.ts new file mode 100644 index 00000000000..df5a84c140e --- /dev/null +++ b/app/adapters/addon-service.ts @@ -0,0 +1,9 @@ +import JSONAPIAdapter from '@ember-data/adapter/json-api'; +import config from 'ember-osf-web/config/environment'; + +const addonServiceUrl = config.OSF.url; + +export default class AddonServiceAdapter extends JSONAPIAdapter { + host = addonServiceUrl.replace(/\/$/, ''); // Remove trailing slash to avoid // in URLs + // TODO: namespace?? +} diff --git a/app/adapters/authorized-storage-account.ts b/app/adapters/authorized-storage-account.ts new file mode 100644 index 00000000000..a76c3b39071 --- /dev/null +++ b/app/adapters/authorized-storage-account.ts @@ -0,0 +1,10 @@ +import AddonServiceAdapter from './addon-service'; + +export default class AuthorizedStorageAccountAdapter extends AddonServiceAdapter { +} + +declare module 'ember-data/types/registries/adapter' { + export default interface AdapterRegistry { + 'authorized-storage-account': AuthorizedStorageAccountAdapter; + } // eslint-disable-line semi +} diff --git a/app/adapters/configured-storage-addon.ts b/app/adapters/configured-storage-addon.ts new file mode 100644 index 00000000000..d208d891ce8 --- /dev/null +++ b/app/adapters/configured-storage-addon.ts @@ -0,0 +1,10 @@ +import AddonServiceAdapter from './addon-service'; + +export default class ConfiguredStorageAddonAdapter extends AddonServiceAdapter { +} + +declare module 'ember-data/types/registries/adapter' { + export default interface AdapterRegistry { + 'configured-storage-addon': ConfiguredStorageAddonAdapter; + } // eslint-disable-line semi +} diff --git a/app/adapters/osf-resource.ts b/app/adapters/osf-resource.ts new file mode 100644 index 00000000000..f58b30db693 --- /dev/null +++ b/app/adapters/osf-resource.ts @@ -0,0 +1,10 @@ +import AddonServiceAdapter from './addon-service'; + +export default class OsfResourceAdapter extends AddonServiceAdapter { +} + +declare module 'ember-data/types/registries/adapter' { + export default interface AdapterRegistry { + 'osf-resource': OsfResourceAdapter; + } // eslint-disable-line semi +} diff --git a/app/adapters/osf-user.ts b/app/adapters/osf-user.ts new file mode 100644 index 00000000000..f5c13b8964a --- /dev/null +++ b/app/adapters/osf-user.ts @@ -0,0 +1,10 @@ +import AddonServiceAdapter from './addon-service'; + +export default class OsfUserAdapter extends AddonServiceAdapter { +} + +declare module 'ember-data/types/registries/adapter' { + export default interface AdapterRegistry { + 'osf-user': OsfUserAdapter; + } // eslint-disable-line semi +} diff --git a/app/adapters/storage-addon-provider.ts b/app/adapters/storage-addon-provider.ts new file mode 100644 index 00000000000..bf8e96b12fc --- /dev/null +++ b/app/adapters/storage-addon-provider.ts @@ -0,0 +1,13 @@ +import AddonServiceAdapter from './addon-service'; + +export default class StorageAddonProviderAdapter extends AddonServiceAdapter { + pathForType() { + return 'storage_providers'; + } +} + +declare module 'ember-data/types/registries/adapter' { + export default interface AdapterRegistry { + 'storage-addon-provider': StorageAddonProviderAdapter; + } // eslint-disable-line semi +} diff --git a/app/config/environment.d.ts b/app/config/environment.d.ts index a04a23a875a..ba8e2b9b1b8 100644 --- a/app/config/environment.d.ts +++ b/app/config/environment.d.ts @@ -69,6 +69,7 @@ declare const config: { apiHeaders: { [k: string]: string }; learnMoreUrl: string; renderUrl: string; + addonServiceUrl: string; waterbutlerUrl: string; helpUrl: string; shareBaseUrl: string; diff --git a/app/models/authorized-storage-account.ts b/app/models/authorized-storage-account.ts new file mode 100644 index 00000000000..a5cb1006807 --- /dev/null +++ b/app/models/authorized-storage-account.ts @@ -0,0 +1,21 @@ +import { AsyncBelongsTo, attr, belongsTo } from '@ember-data/model'; + +import OsfUserModel from './osf-user'; +import OsfModel from './osf-model'; + +export default class AuthorizedStorageAccountModel extends OsfModel { + @attr('fixstring') storageProvider!: string; + @attr('fixstring') externalUserId!: string; + @attr('fixstring') externalUserDisplayName!: string; + @attr('fixstringarray') scopes!: string[]; + @attr('fixstring') defaultRootFolder!: string; + + @belongsTo('osf-user', { inverse: 'authorizedStorageAccounts' }) + configuringUser!: AsyncBelongsTo & OsfUserModel; +} + +declare module 'ember-data/types/registries/model' { + export default interface ModelRegistry { + 'authorized-storage-account': AuthorizedStorageAccountModel; + } // eslint-disable-line semi +} diff --git a/app/models/configured-storage-addon.ts b/app/models/configured-storage-addon.ts new file mode 100644 index 00000000000..8c5fac27a79 --- /dev/null +++ b/app/models/configured-storage-addon.ts @@ -0,0 +1,28 @@ +import { AsyncBelongsTo, attr, belongsTo } from '@ember-data/model'; +import OsfResourceModel from 'ember-osf-web/models/osf-resource'; +import OsfUserModel from 'ember-osf-web/models/osf-user'; + +import OsfModel from './osf-model'; +import AuthorizedStorageAccountModel from './authorized-storage-account'; + +export default class ConfiguredStorageAddonModel extends OsfModel { + @attr('fixstring') storageProvider!: string; + @attr('fixstring') externalUserId!: string; + @attr('fixstring') externalUserDisplayName!: string; + @attr('fixstring') rootFolder!: string; + + @belongsTo('osf-user', { inverse: 'configuredResources' }) + accountOwner!: AsyncBelongsTo & OsfUserModel; + + @belongsTo('osf-resource', { inverse: 'configuredStorageAddons' }) + authorizedResource!: AsyncBelongsTo & OsfResourceModel; + + @belongsTo('authorized-storage-account') + baseAccount!: AsyncBelongsTo & AuthorizedStorageAccountModel; +} + +declare module 'ember-data/types/registries/model' { + export default interface ModelRegistry { + 'configured-storage-addon': ConfiguredStorageAddonModel; + } // eslint-disable-line semi +} diff --git a/app/models/osf-resource.ts b/app/models/osf-resource.ts new file mode 100644 index 00000000000..27bbe95562a --- /dev/null +++ b/app/models/osf-resource.ts @@ -0,0 +1,15 @@ +import { AsyncHasMany, hasMany } from '@ember-data/model'; + +import OsfModel from './osf-model'; +import ConfiguredStorageAccountModel from './configured-storage-addon'; + +export default class OsfResourceModel extends OsfModel { + @hasMany('configured-storage-account', { inverse: 'authorizedResource' }) + configuredStorageAddons!: AsyncHasMany & ConfiguredStorageAccountModel[]; +} + +declare module 'ember-data/types/registries/model' { + export default interface ModelRegistry { + 'osf-resource': OsfResourceModel; + } // eslint-disable-line semi +} diff --git a/app/models/osf-user.ts b/app/models/osf-user.ts new file mode 100644 index 00000000000..8889e0d3d85 --- /dev/null +++ b/app/models/osf-user.ts @@ -0,0 +1,19 @@ +import { AsyncHasMany, hasMany } from '@ember-data/model'; + +import AuthorizedStorageAccountModel from './authorized-storage-account'; +import OsfResourceModel from './osf-resource'; +import OsfModel from './osf-model'; + +export default class OsfUserModel extends OsfModel { + @hasMany('authorized-storage-account', { inverse: 'configuringUser' }) + authorizedStorageAccounts!: AsyncHasMany & AuthorizedStorageAccountModel[]; + + @hasMany('osf-resource') + configuredResources!: AsyncHasMany & OsfResourceModel[]; +} + +declare module 'ember-data/types/registries/model' { + export default interface ModelRegistry { + 'osf-user': OsfUserModel; + } // eslint-disable-line semi +} diff --git a/app/models/storage-addon-provider.ts b/app/models/storage-addon-provider.ts new file mode 100644 index 00000000000..cebe96630dd --- /dev/null +++ b/app/models/storage-addon-provider.ts @@ -0,0 +1,22 @@ +import { attr } from '@ember-data/model'; + +import OsfModel from './osf-model'; + +export default class StorageAddonProviderModel extends OsfModel { + @attr('fixstring') name!: string; + @attr('fixstring') iconUri!: string; + @attr('fixstring') authUri!: string; + @attr('boolean') readOnly!: boolean; + @attr('boolean') supportsCopy!: boolean; + @attr('boolean') supportsUserSpecifiedRootFolder!: boolean; + @attr('boolean') supportsFileVersioning!: boolean; + @attr('boolean') supportsBulkDownload!: boolean; + @attr('number') maxConcurrentDownloads!: number; + @attr('number') maxUploadMb!: number; +} + +declare module 'ember-data/types/registries/model' { + export default interface ModelRegistry { + 'storage-addon-provider': StorageAddonProviderModel; + } // eslint-disable-line semi +} diff --git a/app/serializers/authorized-storage-account.ts b/app/serializers/authorized-storage-account.ts new file mode 100644 index 00000000000..8ade5a4e7ae --- /dev/null +++ b/app/serializers/authorized-storage-account.ts @@ -0,0 +1,10 @@ +import OsfSerializer from './osf-serializer'; + +export default class AuthorizedStorageAccountSerializer extends OsfSerializer { +} + +declare module 'ember-data/types/registries/serializer' { + export default interface SerializerRegistry { + 'authorized-storage-account': AuthorizedStorageAccountSerializer; + } // eslint-disable-line semi +} diff --git a/app/serializers/configured-storage-addon.ts b/app/serializers/configured-storage-addon.ts new file mode 100644 index 00000000000..740e0d82334 --- /dev/null +++ b/app/serializers/configured-storage-addon.ts @@ -0,0 +1,10 @@ +import OsfSerializer from './osf-serializer'; + +export default class ConfiguredStorageAddonSerializer extends OsfSerializer { +} + +declare module 'ember-data/types/registries/serializer' { + export default interface SerializerRegistry { + 'configured-storage-addon': ConfiguredStorageAddonSerializer; + } // eslint-disable-line semi +} diff --git a/app/serializers/osf-resource.ts b/app/serializers/osf-resource.ts new file mode 100644 index 00000000000..3c9c552e1ee --- /dev/null +++ b/app/serializers/osf-resource.ts @@ -0,0 +1,10 @@ +import OsfSerializer from './osf-serializer'; + +export default class OsfResourceSerializer extends OsfSerializer { +} + +declare module 'ember-data/types/registries/serializer' { + export default interface SerializerRegistry { + 'osf-resource': OsfResourceSerializer; + } // eslint-disable-line semi +} diff --git a/app/serializers/osf-user.ts b/app/serializers/osf-user.ts new file mode 100644 index 00000000000..9eff4603424 --- /dev/null +++ b/app/serializers/osf-user.ts @@ -0,0 +1,10 @@ +import OsfSerializer from './osf-serializer'; + +export default class OsfUserSerializer extends OsfSerializer { +} + +declare module 'ember-data/types/registries/serializer' { + export default interface SerializerRegistry { + 'osf-user': OsfUserSerializer; + } // eslint-disable-line semi +} diff --git a/app/serializers/storage-addon-provider.ts b/app/serializers/storage-addon-provider.ts new file mode 100644 index 00000000000..65eae509dae --- /dev/null +++ b/app/serializers/storage-addon-provider.ts @@ -0,0 +1,10 @@ +import OsfSerializer from './osf-serializer'; + +export default class StorageAddonProviderSerializer extends OsfSerializer { +} + +declare module 'ember-data/types/registries/serializer' { + export default interface SerializerRegistry { + 'storage-addon-provider': StorageAddonProviderSerializer; + } // eslint-disable-line semi +} diff --git a/config/environment.js b/config/environment.js index e802090a825..3146de31785 100644 --- a/config/environment.js +++ b/config/environment.js @@ -46,6 +46,8 @@ const { OSF_API_VERSION: apiVersion = '2.20', OSF_RENDER_URL: renderUrl = 'http://localhost:7778/render', OSF_FILE_URL: waterbutlerUrl = 'http://localhost:7777/', + // TODO: where shold this actually go? + ADDON_SERVICE_URL: addonServiceUrl = 'http://localhost:7979/', OSF_HELP_URL: helpUrl = 'http://localhost:4200/help', OSF_AUTHENTICATOR: osfAuthenticator = 'osf-cookie', POLICY_URL_PREFIX = 'https://github.com/CenterForOpenScience/centerforopenscience.org/blob/master/', @@ -146,6 +148,7 @@ module.exports = function(environment) { learnMoreUrl: 'https://cos.io/our-products/osf/', renderUrl, waterbutlerUrl, + addonServiceUrl, helpUrl, shareBaseUrl, shareApiUrl,