Skip to content

Commit 7077299

Browse files
committed
Merge branch 'release/0.2.0'
2 parents 212539b + 1943f20 commit 7077299

File tree

132 files changed

+7845
-408
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+7845
-408
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ indent_size = 4
3232

3333
[*.{diff,md}]
3434
trim_trailing_whitespace = false
35+
36+
[{package.json,.travis.yml}]
37+
indent_style = space
38+
indent_size = 2

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## Ticket
2+
https://openscience.atlassian.net/browse/EOSF-
23

34
# Purpose
45

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
/connect.lock
1414
/coverage/*
1515
/libpeerconnection.log
16+
.npmrc
1617
npm-debug.log
1718
testem.log
1819

20+
# Never commit configuration or private settings
1921
config/*.yml

.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"forin": false,
1616
"immed": false,
1717
"laxbreak": false,
18+
"loopfunc": true,
1819
"newcap": true,
1920
"noarg": true,
2021
"noempty": false,

.npmignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
/bower_components
2+
/config/coverage.js
23
/config/ember-try.js
4+
/config/*.yml
5+
/coverage
36
/dist
7+
/docs
8+
/.github
9+
/.idea
410
/tests
511
/tmp
612
**/.gitkeep
@@ -9,6 +15,8 @@
915
.ember-cli
1016
.gitignore
1117
.jshintrc
18+
.npmrc
19+
.nvmrc
1220
.watchmanconfig
1321
.travis.yml
1422
bower.json

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lts/boron

.template-lintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
extends: 'recommended',
66

77
rules: {
8-
'block-indentation': 4
8+
'block-indentation': 4,
9+
'bare-strings': false
910
}
1011
};

.travis.yml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
---
21
language: node_js
3-
node_js:
4-
- "4.3.2"
52

63
sudo: false
4+
dist: trusty
5+
6+
env:
7+
global:
8+
- SUPPRESS_NO_CONFIG_WARNING=true
79

810
cache:
11+
yarn: true
912
directories:
1013
- node_modules
11-
12-
before_install:
13-
- export PATH=/usr/local/phantomjs-2.0.0/bin:$PATH
14-
- "npm config set spin false"
15-
- "npm install -g npm@^2"
14+
- $HOME/.cache # includes bowers cache
1615

1716
install:
18-
- npm install -g bower
19-
- npm install
20-
- bower install
17+
- curl -o- -L https://yarnpkg.com/install.sh | bash
18+
- export PATH=$HOME/.yarn/bin:$PATH
19+
- yarn --pure-lockfile
20+
- ./node_modules/bower/bin/bower install --config.interactive=false
2121

2222
script:
23-
- npm run check-style && npm test
23+
- yarn test:cover
24+
25+
after_success:
26+
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ APPENDIX: How to apply the Apache License to your work.
187187
same "printed page" as the copyright notice for easier
188188
identification within third-party archives.
189189

190-
Copyright 2013-2016 Center for Open Science
190+
Copyright 2013-2017 Center for Open Science
191191

192192
Licensed under the Apache License, Version 2.0 (the "License");
193193
you may not use this file except in compliance with the License.

README.md

Lines changed: 112 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,34 @@
22

33
`master` Build Status: [![Build Status](https://travis-ci.org/CenterForOpenScience/ember-osf.svg?branch=master)](https://travis-ci.org/CenterForOpenScience/ember-osf)
44

5-
`develop` Build Status: [![Build Status](https://travis-ci.org/CenterForOpenScience/ember-osf.svg?branch=develop)](https://travis-ci.org/CenterForOpenScience/ember-osf)
5+
`develop` Build Status: [![Build Status](https://travis-ci.org/CenterForOpenScience/ember-osf.svg?branch=develop)](https://travis-ci.org/CenterForOpenScience/ember-osf)
6+
[![Coverage Status](https://coveralls.io/repos/github/CenterForOpenScience/ember-osf/badge.svg?branch=develop)](https://coveralls.io/github/CenterForOpenScience/ember-osf?branch=develop)
67

7-
This repo contains code for interacting with the OSF APIv2 inside of an Ember app.
8+
This repo contains code for interacting with the [OSF APIv2](https://api.osf.io/v2/) inside of an Ember app. See
9+
[addon API Docs](http://centerforopenscience.github.io/ember-osf/) for a list of what this addon provides.
810

9-
## Contributing?
11+
## Contributing
1012

1113
Please read the [CONTRIBUTING.md](https://github.com/CenterForOpenScience/ember-osf/blob/develop/.github/CONTRIBUTING.md)
1214

13-
## Installation (for Development)
15+
## Installing tools to develop and modify this addon
16+
See the [yarn docs](https://yarnpkg.com/) for installing and using yarn. These instructions will prepare your
17+
environment if you plan to modify and test this addon in isolation.
1418

1519
* `git clone` this repository
16-
* `npm install`
20+
* `yarn install --pure-lockfile`
1721
* `bower install`
1822

19-
## Using this code in an Ember app
23+
## Using this addon in another Ember app
24+
### For production use
25+
Other applications that wish to consume this addon should add the following line manually to the consuming Ember app's
26+
`package.json` file, then run `yarn install` and `bower install` inside that app.
2027

28+
`"ember-osf": "git+https://github.com/CenterForOpenScience/ember-osf.git#NewestCommitHashGoesHere",`
29+
30+
In the future, we will provide an installable `npm` package to simplify this process.
31+
32+
### For local development
2133
1. Clone the repository: `git clone https://github.com/CenterForOpenScience/ember-osf.git`
2234
2. From the consuming Ember app:
2335
- install the addon and it's dependencies: `ember install ../ember-osf`
@@ -31,19 +43,26 @@ Please read the [CONTRIBUTING.md](https://github.com/CenterForOpenScience/ember-
3143
export default Ember.Route.extend(OsfLoginRouteMixin);
3244
```
3345

34-
> **Note**: Running ember install will automatically install all bower and npm dependencies for ember-osf.
46+
> **Note**: Running ember install will automatically install many bower and npm dependencies for ember-osf.
3547
3648
## Configuration
3749

50+
### Specifying configuration information
51+
3852
#### local.yml settings
3953

40-
This file is structured like:
54+
If for some reason you don't have a config/local.yml you can generate one. To do this:
55+
```bash
56+
ember generate ember-osf
57+
```
58+
59+
Ember-osf needs certain configuration variables to run. This is usually done via a config file structured as follows:
4160
```yaml
42-
<backend>:
61+
OAUTH_SCOPES: osf.full_write
62+
REDIRECT_URI: http://localhost:4200/login
63+
4364
CLIENT_ID: null
4465
PERSONAL_ACCESS_TOKEN: null
45-
OAUTH_SCOPES: osf.full_read osf.full_write
46-
REDIRECT_URI: http://localhost:4200/login
4766
```
4867
4968
You will need to fill out options for each backend you want to use (see 'Running' below).
@@ -53,66 +72,121 @@ uri is correct. If it needs a trailing slash, be sure to include a trailing sla
5372
5473
Edit the new file (installed in the config directory) and set:
5574
- `CLIENT_ID` to the client id of your developer application
56-
- `PERSONAL_ACCESS_TOKEN` to the newly generated token (Only required or recognized for the LOCAL backend; do not set this value for staging, production, or test backends)
57-
- REDIRECT_URI: Must exactly match the redirect URI used to register the OAuth developer application.
75+
- `PERSONAL_ACCESS_TOKEN` to the newly generated token (Only required or recognized for the LOCAL backend; do not set
76+
this value for staging, production, or test backends)
77+
- `REDIRECT_URI`: Must exactly match the redirect URI used to register the OAuth developer application.
5878
Default value is appropriate for local development using `ember server`, with a login page at `/login`
5979

60-
Because of the potential for this file to include sensitive information, we strongly recommend adding this file to
61-
`.gitignore` for your project.
80+
Because of the potential for this file to include sensitive information, **we strongly recommend adding this file to
81+
`.gitignore`** for your project.
6282

63-
#### Using the Test API
83+
#### Alternate option: Environment variables
84+
If you do not wish to use file-based configuration, any of the settings above can be overridden individually as
85+
environment variables with the same name as appears in the config file. Eg
6486

65-
To do this, you will need to [create a developer application](https://test.osf.io/settings/applications/) on the relevant version of the OSF.
87+
`BACKEND=test CLIENT_ID=gibberish ember server`
6688

67-
#### Running the OSF Locally (optional)
89+
If you provide a setting in both the config file and an environment variable, the environment variables take precedence.
6890

69-
For local development, you will need to be running the [OSF APIv2](https://github.com/CenterForOpenScience/osf.io#running-the-api-server).
70-
To connect to the APIv2 while using [fakecas](https://github.com/CenterForOpenScience/osf.io#running-the-osf), you will need to generate a
71-
personal access token on your local OSF instance [here](http://localhost:5000/settings/tokens/)--go ahead and grant access to all scopes.
91+
You can always override auth-related settings, but attempts to override server URLs will be ignored unless you
92+
explicitly specify `BACKEND=env` (see "Running" for example).
7293

73-
#### Create a local settings file
94+
### Using the API
95+
Most apps that use this addon will authorize requests via OAuth2. As may be apparent from the `CLIENT_ID` and
96+
`REDIRECT_URI` settings above, you will need to [create a developer application](https://test.osf.io/settings/applications/)
97+
on the relevant version of the OSF, and provide the appropriate settings for your app.
7498

75-
If for some reason you don't have a config/local.yml you can generate one. To do this:
76-
```bash
77-
ember generate ember-osf
99+
### Advanced usage: Selecting an authorization type
100+
We expect that most projects based on `ember-osf` will authenticate via OAuth 2.0 ("Token Login"); the addon is
101+
configured to use this out of the box, so long as you provide your own login page based on the appropriate mixins.
102+
This is the most effective way for third-party applications to work with our services.
103+
104+
If you are developing an application that will be hosted under the `osf.io` domain, you may wish to use cookie-based
105+
authentication instead. In that rare case, add the following lines to your `config/environment.js` file:
106+
107+
```javascript
108+
var authorizationType = 'cookie';
109+
ENV.authorizationType = authorizationType;
110+
111+
ENV['ember-simple-auth'] = {
112+
authorizer: `authorizer:osf-${authorizationType}`,
113+
authenticator: `authenticator:osf-${authorizationType}`
114+
};
78115
```
79116

80-
## Usage
117+
### Running the OSF Locally (optional)
118+
119+
For local development, you will need to be running the [OSF APIv2](https://github.com/CenterForOpenScience/osf.io#running-the-api-server).
120+
To connect to the APIv2 while using [fakecas](https://github.com/CenterForOpenScience/osf.io#running-the-osf), you
121+
will need to generate a personal access token on your local OSF instance [here](http://localhost:5000/settings/tokens/)-
122+
go ahead and grant full privilege access to all scopes (the `osf.full_write` option).
123+
124+
## Using this addon
81125

82-
#### Ember Data: Using the OSF models
126+
### Ember Data: Using the OSF models
83127

84128
The models, serializers, adapters bundled in this addon with be available to you automatically.
85129
For example, simply do:
86130
```javascript
87131
this.store.findAll('node')
88132
```
89-
to fetch all nodes.
133+
to fetch all nodes (or at least the first page of results). If you need to fetch many results, see the API docs for
134+
information about how to handle pagination. Ember-osf also provides support for
135+
[paginated relationship requests](https://github.com/mdehoog/ember-data-has-many-query) via a third-party addon.
136+
137+
### Advanced: using components and styles
138+
Some of the ember-osf components require additional configuration to take advantage of premade widgets or styles.
139+
140+
Some of these settings, as well as recommended best practices, are gathered together in a
141+
[demonstration app](https://github.com/abought/demo-ember-osf/) that consumes this addon.
90142

91143
## Running
92144

93-
We recommend developers target out test server:
145+
### Using the addon with a specific server
146+
We recommend developers target our test server:
94147
- test (`test`): matches production features, very stable
95148

96-
Other options include:
149+
Ember-osf also ships with builtin support for several other servers:
97150
- local (`local`): for developers running the OSF stack locally
98151
- staging (`stage`): contains bleeding edge features, but less stable
99-
- staging2 (`stage2`): another version of staging using running a specific feature branch
152+
- staging2 (`stage2`) or `staging3` (`stage3`): Staging servers that run specific feature branches, usually for
153+
functionality that is being tested for longer or not targeted for immediate release
154+
- production (`prod`): The main osf.io site. This is a good choice for apps you deploy, but please be a good citizen
155+
and avoid using the production server for your test data.
100156

101157
Then (using test as an example) run:
102158
`BACKEND=test ember server`
103159

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

106-
**Note:** This runs the dummy app contained in /tests/dummy
162+
**Note:** When run from within the `ember-osf` repository, this command runs the dummy app contained in /tests/dummy
107163

108-
## Running Tests
164+
### Using a custom OSF backend
165+
In certain circumstances, you may wish to use a custom set of servers not known to the `ember-osf` addon.
166+
You can elect to specify your server URLs individually, by specifying `BACKEND=env` and passing additional environment
167+
variables/config file entries. For example:
168+
169+
`BACKEND=env OSF_URL=https://e.io/ OSF_API_URL=https://api.e.io OSF_RENDER_URL=https://mfr.e.io/render OSF_FILE_URL=https://files.e.io OSF_HELP_URL=https://help.e.io OSF_COOKIE_LOGIN_URL=https://accounts.e.io/login OSF_OAUTH_URL=https://accounts.e.io/oauth2/authorize ember server`
109170

110-
* `npm test` (Runs `ember try:testall` to test your addon against multiple Ember versions)
111-
* `ember test`
112-
* `ember test --server`
171+
## Running Tests
113172

114-
## Building
173+
* `yarn test` will run all tests used by Travis
174+
* `ember test --server` will run just ember tests, and reload any time that code is changed
115175

116-
* `ember build`
117176

118177
For more information on using ember-cli, visit [http://www.ember-cli.com/](http://www.ember-cli.com/).
178+
179+
## Distribution / releases
180+
The information below applies only to package maintainers, and most users will not need this.
181+
182+
The following commands can be used to publish a new release of `ember-osf`:
183+
184+
- `yarn run bump-version [<newversion> | major | minor | patch]`: Verify that the code is in a releasable state,
185+
increment the version number without generating a new git commit, and update documentation.
186+
See [docs](https://docs.npmjs.com/cli/version) for recognized options.
187+
- `yarn run make-release`: Uses [git flow](https://github.com/nvie/gitflow) to prepare a new release.
188+
You must be on the develop branch, commit all changes, and have run `git init` in this folder at least one time (ever).
189+
- `yarn publish`: [Publish](https://docs.npmjs.com/getting-started/publishing-npm-packages) a new version of the
190+
package to the NPM registry. It is highly recommended that you do this from a fresh checkout of the repo, and
191+
[validate](https://docs.npmjs.com/misc/developers#before-publishing-make-sure-your-package-installs-and-works)
192+
the package contents before uploading. You must be a recognized NPM collaborator or this command will fail.

addon/adapters/citation.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import OsfAdapter from './osf-adapter';
2+
3+
export default OsfAdapter.extend({
4+
});

addon/adapters/license.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import OsfAdapter from './osf-adapter';
2+
3+
export default OsfAdapter.extend({
4+
});

addon/adapters/node.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,11 @@ export default OsfAdapter.extend({
1212
}
1313
}
1414
return this._super(...arguments);
15+
},
16+
_handleRelatedRequest(_, __, ___, relationship) {
17+
if (relationship.includes('license')) {
18+
return;
19+
}
20+
return this._super(...arguments);
1521
}
1622
});

addon/adapters/osf-adapter.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,28 @@ import {
2323
* @uses GenericDataAdapterMixin
2424
*/
2525
export default DS.JSONAPIAdapter.extend(HasManyQuery.RESTAdapterMixin, GenericDataAdapterMixin, {
26+
headers: {
27+
ACCEPT: 'application/vnd.api+json; version=2.3'
28+
},
2629
authorizer: config['ember-simple-auth'].authorizer,
2730
host: config.OSF.apiUrl,
2831
namespace: config.OSF.apiNamespace,
32+
/**
33+
* Overrides buildQuery method - Allows users to embed resources with findRecord
34+
* OSF APIv2 does not have "include" functionality, instead we use 'embed'.
35+
* Usage: findRecord(type, id, {include: 'resource'}) or findRecord(type, id, {include: ['resource1', resource2]})
36+
* Swaps included resources with embedded resources
37+
*
38+
* @method buildQuery
39+
*/
40+
buildQuery() {
41+
let query = this._super(...arguments);
42+
if (query.include) {
43+
query.embed = query.include;
44+
}
45+
delete query.include;
46+
return query;
47+
},
2948
buildURL(modelName, id, snapshot, requestType) {
3049
var url = this._super(...arguments);
3150
var options = (snapshot ? snapshot.adapterOptions : false) || {};
@@ -220,7 +239,7 @@ export default DS.JSONAPIAdapter.extend(HasManyQuery.RESTAdapterMixin, GenericDa
220239
data: data,
221240
isBulk: isBulk
222241
}).then(res => {
223-
if (!Ember.$.isArray(res.data)) {
242+
if (res && !Ember.$.isArray(res.data)) {
224243
res.data = [res.data];
225244
}
226245
return res;

0 commit comments

Comments
 (0)