Removes _PushStatus from system classes, uses direct DB access to write
This commit is contained in:
@@ -283,11 +283,18 @@ describe('PushController', () => {
|
|||||||
Parse.Object.saveAll(installations).then(() => {
|
Parse.Object.saveAll(installations).then(() => {
|
||||||
return pushController.sendPush(payload, {}, config, auth);
|
return pushController.sendPush(payload, {}, config, auth);
|
||||||
}).then((result) => {
|
}).then((result) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
resolve();
|
||||||
|
}, 1000);
|
||||||
|
});
|
||||||
|
}).then(() => {
|
||||||
let query = new Parse.Query('_PushStatus');
|
let query = new Parse.Query('_PushStatus');
|
||||||
return query.find({useMasterKey: true});
|
return query.find({useMasterKey: true});
|
||||||
}).then((results) => {
|
}).then((results) => {
|
||||||
expect(results.length).toBe(1);
|
expect(results.length).toBe(1);
|
||||||
let result = results[0];
|
let result = results[0];
|
||||||
|
expect(result.createdAt instanceof Date).toBe(true);
|
||||||
expect(result.get('source')).toEqual('rest');
|
expect(result.get('source')).toEqual('rest');
|
||||||
expect(result.get('query')).toEqual(JSON.stringify({}));
|
expect(result.get('query')).toEqual(JSON.stringify({}));
|
||||||
expect(result.get('payload')).toEqual(payload.data);
|
expect(result.get('payload')).toEqual(payload.data);
|
||||||
@@ -300,6 +307,11 @@ describe('PushController', () => {
|
|||||||
expect(result.get('failedPerType')).toEqual({
|
expect(result.get('failedPerType')).toEqual({
|
||||||
'android': 5 // android
|
'android': 5 // android
|
||||||
});
|
});
|
||||||
|
// Try to get it without masterKey
|
||||||
|
let query = new Parse.Query('_PushStatus');
|
||||||
|
return query.find();
|
||||||
|
}).then((results) => {
|
||||||
|
expect(results.length).toBe(0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ var requiredColumns = {
|
|||||||
_Role: ["name", "ACL"]
|
_Role: ["name", "ACL"]
|
||||||
}
|
}
|
||||||
|
|
||||||
const systemClasses = ['_User', '_Installation', '_Role', '_Session', '_Product', '_PushStatus'];
|
const systemClasses = ['_User', '_Installation', '_Role', '_Session', '_Product'];
|
||||||
|
|
||||||
// 10 alpha numberic chars + uppercase
|
// 10 alpha numberic chars + uppercase
|
||||||
const userIdRegex = /^[a-zA-Z0-9]{10}$/;
|
const userIdRegex = /^[a-zA-Z0-9]{10}$/;
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
import RestWrite from './RestWrite';
|
import { md5Hash, newObjectId } from './cryptoUtils';
|
||||||
import { md5Hash } from './cryptoUtils';
|
|
||||||
|
|
||||||
export default function pushStatusHandler(config) {
|
export default function pushStatusHandler(config) {
|
||||||
|
|
||||||
let initialPromise;
|
let initialPromise;
|
||||||
let pushStatus;
|
let pushStatus;
|
||||||
|
|
||||||
|
let collection = function() {
|
||||||
|
return config.database.adaptiveCollection('_PushStatus');
|
||||||
|
}
|
||||||
|
|
||||||
let setInitial = function(body, where, options = {source: 'rest'}) {
|
let setInitial = function(body, where, options = {source: 'rest'}) {
|
||||||
|
let now = new Date();
|
||||||
let object = {
|
let object = {
|
||||||
pushTime: (new Date()).toISOString(),
|
objectId: newObjectId(),
|
||||||
|
pushTime: now.toISOString(),
|
||||||
|
_created_at: now,
|
||||||
query: JSON.stringify(where),
|
query: JSON.stringify(where),
|
||||||
payload: body.data,
|
payload: body.data,
|
||||||
source: options.source,
|
source: options.source,
|
||||||
@@ -16,21 +23,27 @@ export default function pushStatusHandler(config) {
|
|||||||
status: "pending",
|
status: "pending",
|
||||||
numSent: 0,
|
numSent: 0,
|
||||||
pushHash: md5Hash(JSON.stringify(body.data)),
|
pushHash: md5Hash(JSON.stringify(body.data)),
|
||||||
ACL: new Parse.ACL() // lockdown!
|
// lockdown!
|
||||||
|
_wperm: [],
|
||||||
|
_rperm: []
|
||||||
}
|
}
|
||||||
let restWrite = new RestWrite(config, {isMaster: true},'_PushStatus',null, object);
|
initialPromise = collection().then((collection) => {
|
||||||
initialPromise = restWrite.execute().then((res) => {
|
return collection.insertOne(object);
|
||||||
pushStatus = res.response;
|
}).then((res) => {
|
||||||
|
pushStatus = {
|
||||||
|
objectId: object.objectId
|
||||||
|
};
|
||||||
return Promise.resolve(pushStatus);
|
return Promise.resolve(pushStatus);
|
||||||
});
|
})
|
||||||
return initialPromise;
|
return initialPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
let setRunning = function() {
|
let setRunning = function() {
|
||||||
return initialPromise.then(() => {
|
return initialPromise.then(() => {
|
||||||
let restWrite = new RestWrite(config, {isMaster: true}, '_PushStatus', {status:"pending", objectId: pushStatus.objectId}, {status: "running"});
|
return collection();
|
||||||
return restWrite.execute();
|
}).then((collection) => {
|
||||||
})
|
return collection.updateOne({status:"pending", objectId: pushStatus.objectId}, {$set: {status: "running"}});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let complete = function(results) {
|
let complete = function(results) {
|
||||||
@@ -63,9 +76,10 @@ export default function pushStatusHandler(config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return initialPromise.then(() => {
|
return initialPromise.then(() => {
|
||||||
let restWrite = new RestWrite(config, {isMaster: true}, '_PushStatus', {status:"running", objectId: pushStatus.objectId}, update);
|
return collection();
|
||||||
return restWrite.execute();
|
}).then((collection) => {
|
||||||
})
|
return collection.updateOne({status:"running", objectId: pushStatus.objectId}, {$set: update});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return Object.freeze({
|
return Object.freeze({
|
||||||
|
|||||||
Reference in New Issue
Block a user