Skip to content

Commit 485f0de

Browse files
Lucian MateescuLucian Mateescu
authored andcommitted
Merge remote-tracking branch 'upstream/master'
2 parents 171cba6 + c37db7b commit 485f0de

16 files changed

+204
-107
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ node_modules
2828

2929
# Emacs
3030
*~
31+
32+
# WebStorm/IntelliJ
33+
.idea

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
branches:
2+
only:
3+
- master
4+
language: node_js
5+
node_js:
6+
- "4.1"
7+
- "4.2"
8+
env:
9+
- MONGODB_VERSION=3.0.8
10+
after_success: ./node_modules/.bin/codecov

ExportAdapter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ExportAdapter.prototype.connect = function() {
3535
}
3636

3737
//http://regexr.com/3cn6m
38-
if (!this.mongoURI.match(/^mongodb:\/\/((.+):(.+)@)?([^:@]+):([^:]+)\/(.+?)$/gm)) {
38+
if (!this.mongoURI.match(/^mongodb:\/\/((.+):(.+)@)?([^:@]+):{0,1}([^:]+)\/(.+?)$/gm)) {
3939
throw new Error("Invalid mongoURI: " + this.mongoURI)
4040
}
4141
var usernameStart = this.mongoURI.indexOf('://') + 3;

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## parse-server
22

3+
[![Build Status](https://img.shields.io/travis/ParsePlatform/parse-server/master.svg?style=flat)](https://travis-ci.org/ParsePlatform/parse-server)
4+
[![Coverage Status](https://img.shields.io/codecov/c/github/ParsePlatform/parse-server/master.svg)](https://codecov.io/github/ParsePlatform/parse-server?branch=master)
5+
[![npm version](https://img.shields.io/npm/v/parse-server.svg?style=flat)](https://www.npmjs.com/package/parse-server)
6+
37
A Parse.com API compatible router package for Express
48

59
Read the announcement blog post here: http://blog.parse.com/announcements/introducing-parse-server-and-the-database-migration-tool/

RestWrite.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ RestWrite.prototype.handleFacebookAuthData = function() {
230230
this.className,
231231
{'authData.facebook.id': facebookData.id}, {});
232232
}).then((results) => {
233+
this.storage['authProvider'] = "facebook";
233234
if (results.length > 0) {
234235
if (!this.query) {
235236
// We're signing up, but this user already exists. Short-circuit
@@ -238,6 +239,7 @@ RestWrite.prototype.handleFacebookAuthData = function() {
238239
response: results[0],
239240
location: this.location()
240241
};
242+
this.data.objectId = results[0].objectId;
241243
return;
242244
}
243245

@@ -250,6 +252,8 @@ RestWrite.prototype.handleFacebookAuthData = function() {
250252
// We're trying to create a duplicate FB auth. Forbid it
251253
throw new Parse.Error(Parse.Error.ACCOUNT_ALREADY_LINKED,
252254
'this auth is already used');
255+
} else {
256+
this.data.username = rack();
253257
}
254258

255259
// This FB auth does not already exist, so transform it to a
@@ -263,7 +267,7 @@ RestWrite.prototype.handleFacebookAuthData = function() {
263267

264268
// The non-third-party parts of User transformation
265269
RestWrite.prototype.transformUser = function() {
266-
if (this.response || this.className !== '_User') {
270+
if (this.className !== '_User') {
267271
return;
268272
}
269273

@@ -273,7 +277,8 @@ RestWrite.prototype.transformUser = function() {
273277
var token = 'r:' + rack();
274278
this.storage['token'] = token;
275279
promise = promise.then(() => {
276-
// TODO: Proper createdWith options, pass installationId
280+
var expiresAt = new Date();
281+
expiresAt.setFullYear(expiresAt.getFullYear() + 1);
277282
var sessionData = {
278283
sessionToken: token,
279284
user: {
@@ -283,10 +288,15 @@ RestWrite.prototype.transformUser = function() {
283288
},
284289
createdWith: {
285290
'action': 'login',
286-
'authProvider': 'password'
291+
'authProvider': this.storage['authProvider'] || 'password'
287292
},
288-
restricted: false
293+
restricted: false,
294+
installationId: this.data.installationId,
295+
expiresAt: Parse._encode(expiresAt)
289296
};
297+
if (this.response && this.response.response) {
298+
this.response.response.sessionToken = token;
299+
}
290300
var create = new RestWrite(this.config, Auth.master(this.config),
291301
'_Session', null, sessionData);
292302
return create.execute();
@@ -405,6 +415,8 @@ RestWrite.prototype.handleSession = function() {
405415

406416
if (!this.query && !this.auth.isMaster) {
407417
var token = 'r:' + rack();
418+
var expiresAt = new Date();
419+
expiresAt.setFullYear(expiresAt.getFullYear() + 1);
408420
var sessionData = {
409421
sessionToken: token,
410422
user: {
@@ -416,7 +428,7 @@ RestWrite.prototype.handleSession = function() {
416428
'action': 'create'
417429
},
418430
restricted: true,
419-
expiresAt: 0
431+
expiresAt: Parse._encode(expiresAt)
420432
};
421433
for (var key in this.data) {
422434
if (key == 'objectId') {

Schema.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ Schema.prototype.validateObject = function(className, object, freeze) {
212212
var geocount = 0;
213213
var promise = this.validateClassName(className, freeze);
214214
for (var key in object) {
215+
if (object[key] === undefined) {
216+
continue;
217+
}
215218
var expected = getType(object[key]);
216219
if (expected === 'geopoint') {
217220
geocount++;

classes.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ function handleFind(req) {
4141
return rest.find(req.config, req.auth,
4242
req.params.className, body.where, options)
4343
.then((response) => {
44+
if (response && response.results) {
45+
for (result of response.results) {
46+
if (result.sessionToken) {
47+
result.sessionToken = req.info.sessionToken || result.sessionToken;
48+
}
49+
}
50+
response.results.sessionToken
51+
}
4452
return {response: response};
4553
});
4654
}

cloud/main.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@ Parse.Cloud.define('hello', function(req, res) {
44
res.success('Hello world!');
55
});
66

7-
Parse.Cloud.beforeSave('BeforeSaveFailure', function(req, res) {
7+
Parse.Cloud.beforeSave('BeforeSaveFail', function(req, res) {
88
res.error('You shall not pass!');
99
});
1010

11+
Parse.Cloud.beforeSave('BeforeSaveFailWithPromise', function (req, res) {
12+
var query = new Parse.Query('Yolo');
13+
query.find().then(() => {
14+
res.error('Nope');
15+
}, () => {
16+
res.success();
17+
});
18+
});
19+
1120
Parse.Cloud.beforeSave('BeforeSaveUnchanged', function(req, res) {
1221
res.success();
1322
});
@@ -27,6 +36,15 @@ Parse.Cloud.beforeDelete('BeforeDeleteFail', function(req, res) {
2736
res.error('Nope');
2837
});
2938

39+
Parse.Cloud.beforeSave('BeforeDeleteFailWithPromise', function (req, res) {
40+
var query = new Parse.Query('Yolo');
41+
query.find().then(() => {
42+
res.error('Nope');
43+
}, () => {
44+
res.success();
45+
});
46+
});
47+
3048
Parse.Cloud.beforeDelete('BeforeDeleteTest', function(req, res) {
3149
res.success();
3250
});

files.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ router.post('/files', function(req, res, next) {
7474
'Filename not provided.'));
7575
});
7676

77-
// TODO: do we need to allow crossdomain and method override?
7877
router.post('/files/:filename',
78+
middlewares.allowCrossDomain,
7979
bodyParser.raw({type: '*/*', limit: '20mb'}),
8080
middlewares.handleParseHeaders,
8181
processCreate);

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "parse-server",
3-
"version": "2.0.4",
3+
"version": "2.0.6",
44
"description": "An express module providing a Parse-compatible API server",
55
"main": "index.js",
66
"repository": {
@@ -22,10 +22,15 @@
2222
"request": "^2.65.0"
2323
},
2424
"devDependencies": {
25-
"jasmine": "^2.3.2"
25+
"codecov": "^1.0.1",
26+
"istanbul": "^0.4.2",
27+
"jasmine": "^2.3.2",
28+
"mongodb-runner": "^3.1.15"
2629
},
2730
"scripts": {
28-
"test": "TESTING=1 ./node_modules/.bin/jasmine"
31+
"pretest": "MONGODB_VERSION=${MONGODB_VERSION:=3.0.8} mongodb-runner start",
32+
"test": "TESTING=1 ./node_modules/.bin/istanbul cover --include-all-sources -x **/spec/** ./node_modules/.bin/jasmine",
33+
"posttest": "mongodb-runner stop"
2934
},
3035
"engines": {
3136
"node": ">=4.1"

spec/ParseAPI.spec.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,26 @@ describe('miscellaneous', function() {
153153
});
154154

155155
it('basic beforeSave rejection', function(done) {
156-
var obj = new Parse.Object('BeforeSaveFailure');
156+
var obj = new Parse.Object('BeforeSaveFail');
157+
obj.set('foo', 'bar');
158+
obj.save().then(() => {
159+
fail('Should not have been able to save BeforeSaveFailure class.');
160+
done();
161+
}, () => {
162+
done();
163+
})
164+
});
165+
166+
it('basic beforeSave rejection via promise', function(done) {
167+
var obj = new Parse.Object('BeforeSaveFailWithPromise');
157168
obj.set('foo', 'bar');
158169
obj.save().then(function() {
159170
fail('Should not have been able to save BeforeSaveFailure class.');
160171
done();
161172
}, function(error) {
173+
expect(error.code).toEqual(Parse.Error.SCRIPT_FAILED);
174+
expect(error.message).toEqual('Nope');
175+
162176
done();
163177
})
164178
});
@@ -250,6 +264,20 @@ describe('miscellaneous', function() {
250264
// We should have been able to fetch the object again
251265
fail(error);
252266
});
267+
})
268+
269+
it('basic beforeDelete rejection via promise', function(done) {
270+
var obj = new Parse.Object('BeforeDeleteFailWithPromise');
271+
obj.set('foo', 'bar');
272+
obj.save().then(function() {
273+
fail('Should not have been able to save BeforeSaveFailure class.');
274+
done();
275+
}, function(error) {
276+
expect(error.code).toEqual(Parse.Error.SCRIPT_FAILED);
277+
expect(error.message).toEqual('Nope');
278+
279+
done();
280+
})
253281
});
254282

255283
it('test beforeDelete success', function(done) {

0 commit comments

Comments
 (0)