Skip to content

Commit

Permalink
[ENG-4688] Addon service models (#2048)
Browse files Browse the repository at this point in the history
* Add config variable for new addon service

* WIP models for addon service

* More WIP models

* WIP

* Remove unneeded model
  • Loading branch information
futa-ikeda authored Nov 13, 2023
1 parent c8c2ed9 commit 81d0846
Show file tree
Hide file tree
Showing 18 changed files with 221 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/adapters/addon-service.ts
Original file line number Diff line number Diff line change
@@ -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??
}
10 changes: 10 additions & 0 deletions app/adapters/authorized-storage-account.ts
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 10 additions & 0 deletions app/adapters/configured-storage-addon.ts
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 10 additions & 0 deletions app/adapters/osf-resource.ts
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 10 additions & 0 deletions app/adapters/osf-user.ts
Original file line number Diff line number Diff line change
@@ -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
}
13 changes: 13 additions & 0 deletions app/adapters/storage-addon-provider.ts
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions app/config/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ declare const config: {
apiHeaders: { [k: string]: string };
learnMoreUrl: string;
renderUrl: string;
addonServiceUrl: string;
waterbutlerUrl: string;
helpUrl: string;
shareBaseUrl: string;
Expand Down
21 changes: 21 additions & 0 deletions app/models/authorized-storage-account.ts
Original file line number Diff line number Diff line change
@@ -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> & OsfUserModel;
}

declare module 'ember-data/types/registries/model' {
export default interface ModelRegistry {
'authorized-storage-account': AuthorizedStorageAccountModel;
} // eslint-disable-line semi
}
28 changes: 28 additions & 0 deletions app/models/configured-storage-addon.ts
Original file line number Diff line number Diff line change
@@ -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> & OsfUserModel;

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

@belongsTo('authorized-storage-account')
baseAccount!: AsyncBelongsTo<AuthorizedStorageAccountModel> & AuthorizedStorageAccountModel;
}

declare module 'ember-data/types/registries/model' {
export default interface ModelRegistry {
'configured-storage-addon': ConfiguredStorageAddonModel;
} // eslint-disable-line semi
}
15 changes: 15 additions & 0 deletions app/models/osf-resource.ts
Original file line number Diff line number Diff line change
@@ -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> & ConfiguredStorageAccountModel[];
}

declare module 'ember-data/types/registries/model' {
export default interface ModelRegistry {
'osf-resource': OsfResourceModel;
} // eslint-disable-line semi
}
19 changes: 19 additions & 0 deletions app/models/osf-user.ts
Original file line number Diff line number Diff line change
@@ -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> & AuthorizedStorageAccountModel[];

@hasMany('osf-resource')
configuredResources!: AsyncHasMany<OsfResourceModel> & OsfResourceModel[];
}

declare module 'ember-data/types/registries/model' {
export default interface ModelRegistry {
'osf-user': OsfUserModel;
} // eslint-disable-line semi
}
22 changes: 22 additions & 0 deletions app/models/storage-addon-provider.ts
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 10 additions & 0 deletions app/serializers/authorized-storage-account.ts
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 10 additions & 0 deletions app/serializers/configured-storage-addon.ts
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 10 additions & 0 deletions app/serializers/osf-resource.ts
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 10 additions & 0 deletions app/serializers/osf-user.ts
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 10 additions & 0 deletions app/serializers/storage-addon-provider.ts
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 3 additions & 0 deletions config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
Expand Down Expand Up @@ -146,6 +148,7 @@ module.exports = function(environment) {
learnMoreUrl: 'https://cos.io/our-products/osf/',
renderUrl,
waterbutlerUrl,
addonServiceUrl,
helpUrl,
shareBaseUrl,
shareApiUrl,
Expand Down

0 comments on commit 81d0846

Please sign in to comment.