-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
87 changed files
with
1,456 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import OsfAdapter from './osf-adapter'; | ||
|
||
export default class DeveloperAppAdapter extends OsfAdapter { | ||
pathForType(_: string) { | ||
return 'applications'; | ||
} | ||
} | ||
|
||
declare module 'ember-data' { | ||
interface AdapterRegistry { | ||
'developer-app': DeveloperAppAdapter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { attr } from '@ember-decorators/data'; | ||
import { buildValidations, validator } from 'ember-cp-validations'; | ||
|
||
import { Document as ApiResponseDocument } from 'osf-api'; | ||
import OsfModel from './osf-model'; | ||
|
||
const Validations = buildValidations({ | ||
name: [ | ||
validator('presence', true), | ||
validator('length', { min: 1, max: 200 }), | ||
], | ||
homeUrl: [ | ||
validator('presence', true), | ||
validator('length', { min: 1, max: 200 }), | ||
validator('format', { type: 'url' }), | ||
], | ||
description: [ | ||
validator('length', { min: 0, max: 1000 }), | ||
], | ||
callbackUrl: [ | ||
validator('presence', true), | ||
validator('length', { min: 1, max: 200 }), | ||
validator('format', { type: 'url' }), | ||
], | ||
}); | ||
|
||
export default class DeveloperAppModel extends OsfModel.extend(Validations) { | ||
@attr() callbackUrl!: string; | ||
@attr() clientId!: string; | ||
@attr() clientSecret!: string; | ||
@attr('date') dateCreated!: Date; | ||
@attr({ defaultValue: '' }) description!: string; | ||
@attr() homeUrl!: string; | ||
@attr() name!: string; | ||
@attr() owner!: string; | ||
|
||
// TODO (EMB-407) When the API is updated, remove this method and reset the secret | ||
// by PATCHing `clientSecret` to `null` | ||
async resetSecret(): Promise<void> { | ||
const resetUrl = this.links.reset; | ||
const adapter = this.store.adapterFor('developer-app'); | ||
const serializer = this.store.serializerFor('developer-app'); | ||
|
||
// @ts-ignore -- Private API | ||
const snapshot = this._createSnapshot(); | ||
|
||
const response: ApiResponseDocument = await adapter.ajax(resetUrl, 'POST', { | ||
data: serializer.serialize(snapshot, { | ||
includeId: true, | ||
osf: { | ||
includeCleanData: true, | ||
}, | ||
}), | ||
}); | ||
|
||
if ('data' in response && 'id' in response.data) { | ||
this.store.pushPayload('developer-app', response); | ||
} else if ('errors' in response) { | ||
throw new Error(response.errors.map(error => error.detail).join('\n')); | ||
} else { | ||
throw new Error('Unexpected response while resetting client secret for developer app'); | ||
} | ||
} | ||
} | ||
|
||
declare module 'ember-data' { | ||
interface ModelRegistry { | ||
'developer-app': DeveloperAppModel; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import OsfSerializer from './osf-serializer'; | ||
|
||
export default class DeveloperAppSerializer extends OsfSerializer { | ||
attrs: any = { | ||
// eslint-disable-next-line ember/no-attrs-in-components | ||
...this.attrs, // from OsfSerializer | ||
|
||
clientSecret: { | ||
serialize: false, | ||
}, | ||
clientId: { | ||
serialize: false, | ||
}, | ||
}; | ||
} | ||
|
||
declare module 'ember-data' { | ||
interface SerializerRegistry { | ||
'developer-app': DeveloperAppSerializer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.