-
Notifications
You must be signed in to change notification settings - Fork 40
Serializer and adapter cleanup #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
212b3f7
6f3d0e0
9408bb2
ac26c99
e6bc06d
f0f02af
ca7bef2
7f4cf23
07e5467
6c6fb33
9ebb0cf
c4882dc
6b3d6f4
86dff60
dc60e1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,22 @@ | ||
| import Ember from 'ember'; | ||
| import DS from 'ember-data'; | ||
| import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin'; | ||
| import UrlTemplates from "ember-data-url-templates"; | ||
|
|
||
| import config from 'ember-get-config'; | ||
|
|
||
| export default DS.JSONAPIAdapter.extend(UrlTemplates, DataAdapterMixin, { | ||
| export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { | ||
| authorizer: 'authorizer:osf-token', | ||
| host: config.OSF.apiUrl, | ||
| urlTemplate: '{+host}{modelName}{/id}/', | ||
| urlSegments: { | ||
| modelName (modelName) { | ||
| return Ember.String.pluralize(modelName); | ||
| } | ||
| namespace: config.OSF.apiNamespace, | ||
| pathForType: Ember.String.pluralize, | ||
|
|
||
| buildURL(modelName, id, snapshot, requestType, query) { // jshint ignore:line | ||
| var url = this._super(...arguments); | ||
| // Fix issue where CORS request failed on 301s: Ember does not seem to append trailing | ||
| // slash to URLs for single documents, but DRF redirects to force a trailing slash | ||
| if (url.lastIndexOf('/') !== 0) { | ||
| url += '/'; | ||
| } | ||
| return url; | ||
| } | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,55 +5,46 @@ var config = require('config'); | |
| module.exports = { | ||
| name: 'ember-osf', | ||
| config: function(environment, ENV) { | ||
| let BACKEND = process.env.BACKEND || 'local'; | ||
| let SETTINGS = {}; | ||
| try { | ||
| SETTINGS = config.get(BACKEND); | ||
| } | ||
| catch (e) { | ||
| console.log(`WARNING: you have specified a backend '${BACKEND}' that you have not configured in your config/<hostname>.yml`); | ||
| } | ||
| let BACKEND = process.env.BACKEND || 'local'; | ||
| let SETTINGS = {}; | ||
| try { | ||
| SETTINGS = config.get(BACKEND); | ||
| } | ||
| catch (e) { | ||
| console.log(`WARNING: you have specified a backend '${BACKEND}' that you have not configured in your config/<hostname>.yml`); | ||
| } | ||
|
|
||
| ENV.OSF = { | ||
| clientId: SETTINGS.CLIENT_ID, | ||
| scope: SETTINGS.OAUTH_SCOPES | ||
| ENV.OSF = { | ||
| clientId: SETTINGS.CLIENT_ID, | ||
| scope: SETTINGS.OAUTH_SCOPES, | ||
| apiNamespace: 'v2' // URL suffix (after host) | ||
| }; | ||
|
|
||
| if (BACKEND === 'local') { | ||
| ENV.OSF.url = 'http://localhost:5000/'; | ||
| ENV.OSF.apiUrl = 'http://localhost:8000/v2/'; | ||
| ENV.OSF.authUrl = 'http://localhost:8080/oauth2/profile'; | ||
| if (BACKEND === 'local') { | ||
| ENV.OSF.url = 'http://localhost:5000/'; | ||
| ENV.OSF.apiUrl = 'http://localhost:8000'; | ||
| ENV.OSF.authUrl = 'http://localhost:8080/oauth2/profile'; | ||
|
|
||
| ENV.OSF.accessToken = SETTINGS.PERSONAL_ACCESS_TOKEN; | ||
| ENV.OSF.isLocal = true; | ||
| } | ||
| if (BACKEND === 'stage') { | ||
| ENV.OSF.url = 'https://staging.osf.io/'; | ||
| ENV.OSF.apiUrl = 'https://staging-api.osf.io/v2/'; | ||
| ENV.OSF.authUrl = 'https://staging-accounts.osf.io/oauth2/authorize'; | ||
| } | ||
| if (BACKEND === 'stage2') { | ||
| ENV.OSF.url = 'https://staging2.osf.io/'; | ||
| ENV.OSF.apiUrl = 'https://staging2-api.osf.io/v2/'; | ||
| ENV.OSF.authUrl = 'https://staging2-accounts.osf.io/oauth2/authorize'; | ||
| } | ||
| if (BACKEND === 'prod') { | ||
| ENV.OSF.url = 'https://osf.io/'; | ||
| ENV.OSF.apiUrl = 'https://api.osf.io/v2/'; | ||
| ENV.OSF.authUrl = 'https://accounts.osf.io/oauth2/authorize'; | ||
| } | ||
|
|
||
| ENV['ember-simple-auth'] = { | ||
| authorizer: 'authorizer:osf-token' | ||
| ENV.OSF.accessToken = SETTINGS.PERSONAL_ACCESS_TOKEN; | ||
| ENV.OSF.isLocal = true; | ||
| } | ||
| if (BACKEND === 'stage') { | ||
| ENV.OSF.url = 'https://staging.osf.io/'; | ||
| ENV.OSF.apiUrl = 'https://staging-api.osf.io'; | ||
| ENV.OSF.authUrl = 'https://staging-accounts.osf.io/oauth2/authorize'; | ||
| } | ||
| if (BACKEND === 'stage2') { | ||
| ENV.OSF.url = 'https://staging2.osf.io/'; | ||
| ENV.OSF.apiUrl = 'https://staging2-api.osf.io'; | ||
| ENV.OSF.authUrl = 'https://staging2-accounts.osf.io/oauth2/authorize'; | ||
| } | ||
| if (BACKEND === 'prod') { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably shouldn't condone using
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sloria agreed, and I am trying to get the README to reflect this (we can be more explicit too), but the code should not assume that it's never being run in production.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding support for the test backend got lost in the shuffle, but I agree it should be added for use by third-party integrators. Thanks for the reminder! Presumably,
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @samchrisinger As discussed in our other thread, envvars should be used for production and any non-local deploys. |
||
| ENV.OSF.url = 'https://osf.io/'; | ||
| ENV.OSF.apiUrl = 'https://api.osf.io'; | ||
| ENV.OSF.authUrl = 'https://accounts.osf.io/oauth2/authorize'; | ||
| } | ||
| ENV['ember-simple-auth'] = { | ||
| authorizer: 'authorizer:osf-token' | ||
| }; | ||
| }, | ||
| // A small hack for ember-data-url-templates to work | ||
| // TODO: followup based on https://github.com/dfreeman/ember-cli-node-assets/issues/1 | ||
| options: { | ||
| nodeAssets: { | ||
| 'uri-templates': { | ||
| import: ['uri-templates.js'] | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,38 @@ | ||
| {{link-to 'Back to list' 'nodes' class="btn btn-default"}} | ||
| <div class="panel"> | ||
| <p><label>Title: </label>{{model.title}}</p> | ||
| <p><label>Category: </label>{{model.category}}</p> | ||
| <p><label>Date Created: </label>{{moment-format model.dateCreated}}</p> | ||
| <p><label>Date Modified: </label>{{moment-format model.dateModified}}</p> | ||
|
|
||
| <h2>Data</h2> | ||
| <p><label>Title:</label> {{model.title}}</p> | ||
| <p><label>Category:</label> {{model.category}}</p> | ||
| <p><label>Date Created:</label> {{moment-format model.dateCreated}}</p> | ||
| <p><label>Date Modified:</label> {{moment-format model.dateModified}}</p> | ||
| <p> | ||
| <a href="{{model.links.html}}" target="_blank" class="btn btn-primary"> | ||
| View on OSF | ||
| </a> | ||
| </p> | ||
| <hr> | ||
| <p> | ||
| <label>Contributors</label> | ||
| <p> | ||
|
|
||
| <h2>Contributors</h2> | ||
|
|
||
| <table class="table"> | ||
| {{#each model.contributors as |contrib|}} | ||
| <tr> | ||
| {{contrib.bibliographic}} | ||
| </tr> | ||
| {{/each}} | ||
| <tr> | ||
| <th>ID</th> | ||
| <th>Author?</th> | ||
| </tr> | ||
| {{#each model.contributors as |contrib|}} | ||
| <tr> | ||
| <td>{{contrib.id}}</td> | ||
| <td>{{contrib.bibliographic}}</td> | ||
| </tr> | ||
| {{/each}} | ||
| </table> | ||
| </p> | ||
| </p> | ||
|
|
||
|
|
||
|
|
||
| <h2>Edit this node</h2> | ||
| Title: {{input value=editedTitle}} | ||
| <button {{action "editExisting" editedTitle}} class="btn btn-primary">Edit record</button> | ||
|
|
||
| </div> | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shameless copy/paste. Will remove during merge.