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