Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,4 @@
npm-debug.log
testem.log

.env
.env-local
.env-stage*
.env-prod

config/*.yml
1 change: 1 addition & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"predef": [
"server",
"document",
"window",
"-Promise"
Expand Down
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,31 @@ For local development, you will need to be running the [OSF APIv2](https://githu
To connect to the APIv2 while using [fakecas](https://github.com/CenterForOpenScience/osf.io#running-the-osf), you will need to generate a
personal access token on your local OSF instance ([here](http://localhost:5000/settings/tokens/-- go ahead and grant access to all scopes)).

#### Create a .env

Next, depending on the backend you want to target, you will need to create the .env file. For:
- local: .env-local
- staging: .env-stage
- staging2: .env-stage2
- production: .env-prod
#### Create a local settings file

To do this:
```bash
ember g env <backend>
ember g ember-osf-settings `echo $HOSTNAME`
```

Edit the new .env and replace:
- `<your_client_id>` with the client id of your developer application
- `<your_personal_access_token>` with the newly generated token (if applicable)

**Note**: For development, we reccomend point your local app to our staging servers: `ember s --environment staging`
Edit the new file (installed in the config directory) and set:
- `CLIENT_ID` to the client id of your developer application
- `PERSONAL_ACCESS_TOKEN` to the newly generated token (if applicable, optional for staging development)

## Running

* `ember server`
* Visit your app at http://localhost:4200.
First, decide which backend you would like to target. Typically we reccomend developers use either our staging or test servers:
- staging (`stage`): contains bleeding edge features, but less stable
- test (`test`): matches production features, very stable

Other options include:
- local (`local`): for developers running the OSF stack locally
- staging2 (`stage2`): another version of staging using running a specific feature branch

Then (using staging as an example) run:
`BACKEND=stage ember s`

and visit your app at http://localhost:4200.

**Note:** This runs the dummy app contained in /tests/dummy

Expand Down
15 changes: 7 additions & 8 deletions addon/adapters/application.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
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(DataAdapterMixin, {
export default DS.JSONAPIAdapter.extend(UrlTemplates, DataAdapterMixin, {
authorizer: 'authorizer:osf-token',

host: config.OSF.apiUrl,
pathForType: Ember.String.pluralize,
urlForFindRecord (id, modelName/*, snapshot*/) {
return `${this.get('host')}${Ember.String.pluralize(modelName)}/${id}/`;
},
urlForFindAll (modelName) {
return `${this.get('host')}${Ember.String.pluralize(modelName)}/`;
urlTemplate: '{+host}{modelName}{/id}/',
urlSegments: {
modelName (modelName) {
return Ember.String.pluralize(modelName);
}
}
});
26 changes: 17 additions & 9 deletions addon/mixins/osf-login-route.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import Ember from 'ember';
import UnauthenticatedRouteMixin from 'ember-simple-auth/mixins/unauthenticated-route-mixin';

import config from 'ember-get-config';

export default Ember.Mixin.create(UnauthenticatedRouteMixin, {
session: Ember.inject.service(),
beforeModel() {
// Acquire an OSF access token, then exchange it for a Jam token
var hash = window.location.hash.substring(1).split('&').map(function(str) {
return this[str.split('=')[0]] = str.split('=')[1], this;
}.bind({}))[0];
if (!hash || !hash.access_token) {
return null;
var accessToken;
if (config.OSF.local) {
accessToken = config.OSF.accessToken;
} else {
// Acquire an OSF access token, then exchange it for a Jam token
var hash = window.location.hash.substring(1).split('&').map(function(str) {
return this[str.split('=')[0]] = str.split('=')[1], this;
}.bind({}))[0];
if (!hash || !hash.access_token) {
return null;
}
window.location.hash = '';
accessToken = hash.access_token;
}
window.location.hash = '';
var accessToken = hash.access_token;
return this.get('session').authenticate('authenticator:osf-token', accessToken)

return this.get('session').authenticate('authenticator:osf-token', accessToken)
.then(() => this.transitionTo('index'));
}
});
2 changes: 1 addition & 1 deletion addon/models/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default OsfModel.extend({
description: DS.attr('string'),
category: DS.attr('string'),

currentUserPermissions: DS.attr(''),
currentUserPermissions: DS.attr('string'),

fork: DS.attr('boolean'),
collection: DS.attr('boolean'),
Expand Down
4 changes: 4 additions & 0 deletions addon/serializers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export default DS.JSONAPISerializer.extend({
if (record.links) {
record.attributes.links = record.links;
}
if (record.embeds) {
// TODO, actually merge in embedded data?
record.attributes.embeds = record.embeds;
}
return record;
},
normalizeSingleResponse(_, __, payload) {
Expand Down
19 changes: 19 additions & 0 deletions blueprints/ember-osf-settings/files/config/__name__.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# local:
# CLIENT_ID: null
# PERSONAL_ACCESS_TOKEN: null
# OAUTH_SCOPES: osf.full_read osf.full_write

stage:
CLIENT_ID: null
PERSONAL_ACCESS_TOKEN: null
OAUTH_SCOPES: osf.full_read osf.full_write

# stage2:
# CLIENT_ID: null
# PERSONAL_ACCESS_TOKEN: null
# OAUTH_SCOPES: osf.full_read osf.full_write

# test:
# CLIENT_ID: null
# PERSONAL_ACCESS_TOKEN: null
# OAUTH_SCOPES: osf.full_read osf.full_write
File renamed without changes.
6 changes: 0 additions & 6 deletions blueprints/env/files/.env-__name__

This file was deleted.

23 changes: 13 additions & 10 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"name": "ember-osf",
"dependencies": {
"ember": "~2.4.3",
"ember-cli-shims": "0.1.1",
"ember-cli-test-loader": "0.2.2",
"ember-qunit-notifications": "0.1.0"
},
"devDependencies": {
"bootstrap": "^3.3.6"
}
"name": "ember-osf",
"dependencies": {
"ember": "~2.4.3",
"ember-cli-shims": "0.1.1",
"ember-cli-test-loader": "0.2.1",
"ember-qunit-notifications": "0.1.0",
"Faker": "~3.0.0",
"pretender": "~0.10.1",
"lodash": "~3.7.0"
},
"devDependencies": {
"bootstrap": "^3.3.6"
}
}
32 changes: 14 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,40 @@
/* jshint node: true */
'use strict';
var dotenv = require('dotenv');
var config = require('config');

module.exports = {
name: 'ember-osf',
config: function(environment, ENV) {
dotenv.config({
path:'.env-' + {
development: 'local',
test: 'test',
staging: 'stage',
staging2: 'stage2',
production: 'prod'
}[environment]
});
let BACKEND = process.env.BACKEND || 'local';
if (!config.has(BACKEND)) {
throw new Error(`WARNING: you have specified a backend: ${BACKEND} that you have not configured in your local.yml`);
}
let SETTINGS = config.get(BACKEND);

ENV.OSF = {
clientId: process.env.OSF_CLIENT_ID,
scope: process.env.OSF_SCOPE
clientId: SETTINGS.CLIENT_ID,
scope: SETTINGS.OAUTH_SCOPES
};

if (environment === 'development') {
if (BACKEND === 'local') {
ENV.OSF.url = 'http://localhost:5000/';
ENV.OSF.apiUrl = 'http://localhost:8000/v2/';
ENV.OSF.authUrl = 'http://localhost:8080/oauth2/profile';

ENV.OSF.accessToken = process.env.OSF_ACCESS_TOKEN;
ENV.DEV = true;
ENV.OSF.accessToken = SETTINGS.PERSONAL_ACCESS_TOKEN;
ENV.OSF.local = true;
}
if (environment === 'staging') {
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 (environment === 'staging2') {
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 (environment === 'production') {
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';
Expand Down
115 changes: 61 additions & 54 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,56 +1,63 @@
{
"name": "ember-osf",
"version": "0.0.1",
"description": "Ember Data models for the OSF APIv2",
"directories": {
"doc": "doc",
"test": "tests"
},
"scripts": {
"build": "ember build",
"start": "ember server",
"test": "ember test"
},
"repository": "",
"engines": {
"node": ">= 0.10.0"
},
"author": "",
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.2.0",
"ember-ajax": "0.7.1",
"ember-cli": "^2.4.3",
"ember-cli-app-version": "^1.0.0",
"ember-cli-dependency-checker": "^1.2.0",
"ember-cli-htmlbars": "^1.0.1",
"ember-cli-htmlbars-inline-precompile": "^0.3.1",
"ember-cli-inject-live-reload": "^1.3.1",
"ember-cli-qunit": "^1.2.1",
"ember-cli-release": "0.2.8",
"ember-cli-sri": "^2.0.0",
"ember-cli-uglify": "^1.2.0",
"ember-data": "^2.3.0",
"ember-disable-prototype-extensions": "^1.0.0",
"ember-disable-proxy-controllers": "^1.0.1",
"ember-export-application-global": "^1.0.4",
"ember-load-initializers": "0.5.1",
"ember-resolver": "2.0.3",
"loader": "2.1.0",
"loader.js": "4.0.3"
},
"keywords": [
"ember-addon"
],
"dependencies": {
"ember-cli-babel": "^5.1.5",
"loader": "^2.1.0",
"ember-simple-auth": "1.1.0-beta.5",
"ember-get-config": "0.0.2",
"ember-moment": "6.1.0",
"dotenv": "^2.0.0"
},
"ember-addon": {
"configPath": "tests/dummy/config"
}
"name": "ember-osf",
"version": "0.0.1",
"description": "Ember Data models for the OSF APIv2",
"directories": {
"doc": "doc",
"test": "tests"
},
"scripts": {
"build": "ember build",
"start": "ember server",
"test": "ember test"
},
"repository": "",
"engines": {
"node": ">= 0.10.0"
},
"author": "",
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.2.0",
"config": "^1.20.1",
"ember-ajax": "0.7.1",
"ember-cli": "^2.4.3",
"ember-cli-app-version": "^1.0.0",
"ember-cli-dependency-checker": "^1.2.0",
"ember-cli-htmlbars": "^1.0.1",
"ember-cli-htmlbars-inline-precompile": "^0.3.1",
"ember-cli-inject-live-reload": "^1.3.1",
"ember-cli-mirage": "0.1.13",
"ember-cli-moment-shim": "1.1.0",
"ember-cli-qunit": "^1.2.1",
"ember-cli-release": "0.2.8",
"ember-cli-sri": "^2.0.0",
"ember-cli-uglify": "^1.2.0",
"ember-data": "^2.3.0",
"ember-data-url-templates": "0.1.1",
"ember-disable-prototype-extensions": "^1.0.0",
"ember-disable-proxy-controllers": "^1.0.1",
"ember-export-application-global": "^1.0.4",
"ember-load-initializers": "0.5.1",
"ember-moment": "6.1.0",
"ember-resolver": "2.0.3",
"js-yaml": "^3.6.0",
"loader": "2.1.0",
"loader.js": "4.0.3",
"moment": "^2.13.0"
},
"keywords": [
"ember-addon"
],
"dependencies": {
"ember-cli-babel": "^5.1.5",
"loader": "^2.1.0",
"ember-simple-auth": "1.1.0-beta.5",
"ember-get-config": "0.0.2",
"ember-moment": "6.1.0",
"dotenv": "^2.0.0"
},
"ember-addon": {
"configPath": "tests/dummy/config"
}
}
1 change: 1 addition & 0 deletions tests/.jshintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"predef": [
"server",
"document",
"window",
"location",
Expand Down
Loading