Skip to content
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

Aid29 issue26 #1

Merged
merged 4 commits into from
Jul 10, 2015
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
39 changes: 33 additions & 6 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,41 @@ module.exports = function (badgerService) {

// Create a badge instance -- need to add auth around this
app.post('/papers/:doi1/:doi2/users/:orcid/badges/:badge', function (request, response) {
if (!request.params.doi1 || !request.params.doi2 || !request.params.orcid || !request.params.badge) {
response.status(400).end();
var orcid;
if (request.session.orcid_token && request.session.orcid_token.token) {
orcid = request.session.orcid_token.token.orcid;
}
if (orcid !== request.params.orcid) {
response.status(403).end();
return;
}
returnBadges(badgerService.createBadge(request.params.orcid, request.params.badge, {
'_1': request.params.doi1,
'_2': request.params.doi2
}), request, response);
var pretty = request.query.pretty;
// Create a badge.
var badge = request.params.badge,
evidence = helpers.DOIFromURL(request.params.doi1 + '/' + request.params.doi2),
context = {
system: system,
badge: badge,
instance: {
email: helpers.emailFromORCID(orcid),
evidenceUrl: helpers.urlFromDOI(evidence)
}
};
client.createBadgeInstance(context, function (err, badge) {
if (err) {
console.error(err);
response.send(err);
return;
}
helpers.modEntry(badge, orcid);
if (pretty) {
response.render(path.join(__dirname, '..', '/public/code.jade'), {
data: JSON.stringify(badge, null, 2)
});
} else {
response.send(badge);
}
});
});

app.get('*', function (request, response) {
Expand Down
2 changes: 1 addition & 1 deletion src/startApp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = function (startAppCallback) {
var env = require('./environments');
var env = require('./environments');
var badgeClient = require('./badgeClient.js')(env);
var badgeService = require('./badgeService.js')(badgeClient, env);
var app = require('./app')(badgeService);
Expand Down
3 changes: 2 additions & 1 deletion templates/pages/issue.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ var Issue = React.createClass({
var url = '/papers/' + path[path.length-2] + '/' + path[path.length-1] + '/users/' + orcid + '/badges/' + badge;

fetch(url, {
method: 'post'
method: 'post',
credentials: 'same-origin'
})
.then((response) => {
if (response.status >= 400) {
Expand Down
3 changes: 1 addition & 2 deletions test/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
var request = require('supertest');
var assert = require('assert');

var Habitat = require('habitat');
var testEnv = new Habitat();
var testEnv = require('../src/environments');
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@acabunoc I need to make this change on my branch issue26?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried the change out for you -- you can merge the changes to your branch by going here:
#1

And clicking 'merge'


var badgeClient = require('../src/badgeClient.js')(testEnv);
var badgeService = require('../src/badgeService.js')(badgeClient, testEnv);
Expand Down