From 9813daa9a5aebb82609c7a9f89e6da2766c02945 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Wed, 18 Jan 2017 13:14:16 -0800 Subject: [PATCH 01/44] Convert queries to promises, useMasterKey() method => { useMasterKey: true } --- cloud/POFriendRequest.js | 11 +++---- cloud/POTrip.js | 9 +++--- cloud/Stats.js | 69 +++++++++++++++++++--------------------- 3 files changed, 41 insertions(+), 48 deletions(-) diff --git a/cloud/POFriendRequest.js b/cloud/POFriendRequest.js index 365d83e60d..aacbbbfe2f 100644 --- a/cloud/POFriendRequest.js +++ b/cloud/POFriendRequest.js @@ -76,17 +76,16 @@ Parse.Cloud.afterSave("POFriendRequest", function(request) { if (!request.object.existed()) { var roleQuery = new Parse.Query(Parse.Role); roleQuery.equalTo("name", "user-" + request.user.id); - roleQuery.first({ - success: function(role) { + roleQuery.first({ useMasterKey: true }).then( + function(role) { Parse.Cloud.useMasterKey(); role.relation("users").add(request.object.get("requestedUser")); role.save(); }, - error: function(error) { + function(error) { console.log("Failed to save role for friend request with error " + error.code + " : " + error.message); - }, - useMasterKey:true - }); + } + ); } }); diff --git a/cloud/POTrip.js b/cloud/POTrip.js index 088749f982..e3c24399de 100644 --- a/cloud/POTrip.js +++ b/cloud/POTrip.js @@ -92,7 +92,6 @@ function checkTripValidity(trip) { } Parse.Cloud.define("userAggregateData", function(request, response) { - Parse.Cloud.useMasterKey(); var counts = {}; counts.sumSMS = 0; @@ -108,8 +107,8 @@ Parse.Cloud.define("userAggregateData", function(request, response) { var query = new Parse.Query("UserTotals"); query.equalTo("user", user); - query.first({ - success: function(totals) { + query.first({ useMasterKey: true }).then( + function(totals) { counts.sumSMS = totals.get("missedSMSCount"); counts.sumCall = totals.get("missedCallCount"); counts.sumOther = totals.get("missedOtherCount"); @@ -118,10 +117,10 @@ Parse.Cloud.define("userAggregateData", function(request, response) { response.success(counts); }, - error: function(error) { + function(error) { //this is valid if the user doesn't have any trips console.log("Couldn't look up UserTotals for: "+request.params.userId); response.success(counts); } - }); + ); }); diff --git a/cloud/Stats.js b/cloud/Stats.js index 2b79447896..8c77c41550 100644 --- a/cloud/Stats.js +++ b/cloud/Stats.js @@ -53,8 +53,6 @@ function sumArray(arr) { Parse.Cloud.define("stats", function(request, response) { - Parse.Cloud.useMasterKey(); - //number of queries that need to complete successfully to return success var queryCount = 4; var failureFlag = false; @@ -97,9 +95,8 @@ Parse.Cloud.define("stats", function(request, response) { }); var userQuery = new Parse.Query("POFriendRelation"); userQuery.equalTo("userId", user); - userQuery.find({ - success: function(friendRelations) { - + userQuery.find({ useMasterKey: true }).then( + function(friendRelations) { // success if (friendRelations && friendRelations.length > 0) { var friends = friendRelations.map(function(e) { return e.get("friendUser"); @@ -107,21 +104,19 @@ Parse.Cloud.define("stats", function(request, response) { var userTotalsQuery = new Parse.Query("UserTotals"); userTotalsQuery.containedIn("user", friends); - userTotalsQuery.find({ - success: function(userTotals) { - + userTotalsQuery.find().then( + function(userTotals) { //success responseObj.friends = friendsStatsFromUserTotals(userTotals, dayIntervals, monthIntervals); - if (--queryCount == 0 && !failureFlag) { response.success(responseObj); } }, - error: function(error) { + function(error) { // error failureFlag = true; console.error("Got an error " + error.code + " : " + error.message); response.error("Error retrieving monthly totals"); } - }); + ); } else { if (--queryCount == 0 && !failureFlag) { @@ -129,12 +124,12 @@ Parse.Cloud.define("stats", function(request, response) { } } }, - error: function(error) { + function(error) { // error failureFlag = true; console.error("Got an error " + error.code + " : " + error.message); response.error("Error looking up friends"); } - }); + ); //global stats @@ -143,8 +138,8 @@ Parse.Cloud.define("stats", function(request, response) { monthlyQuery.lessThan("date",new Date()); monthlyQuery.addDescending("date"); monthlyQuery.limit(monthIntervals.length); //last 12 months of data - monthlyQuery.find({ - success: function(monthlyResults) { + monthlyQuery.find({ useMasterKey: true }).then( + function(monthlyResults) { responseObj.global.minutesDrivenMonths = []; responseObj.global.kmDrivenMonths = []; @@ -175,19 +170,19 @@ Parse.Cloud.define("stats", function(request, response) { response.success(responseObj); } }, - error: function(error) { + function(error) { failureFlag = true; console.error("Got an error " + error.code + " : " + error.message); response.error("Error retrieving monthly totals"); } - }); + ); var dailyQuery = new Parse.Query("DailyTotals"); dailyQuery.lessThan("date",new Date()); dailyQuery.addDescending("date"); dailyQuery.limit(dayIntervals.length); //last 7 days of data - dailyQuery.find({ - success: function(dailyResults) { + dailyQuery.find({ useMasterKey: true }).then( + function(dailyResults) { responseObj.global.minutesDrivenDays = []; responseObj.global.kmDrivenDays = []; for (var i = 0; i < dayIntervals.length; i++) { @@ -222,16 +217,16 @@ Parse.Cloud.define("stats", function(request, response) { response.success(responseObj); } }, - error: function(error) { + function(error) { failureFlag = true; console.error("Got an error " + error.code + " : " + error.message); response.error("Error retrieving daily totals"); } - }); + ); var globalQuery = new Parse.Query("GlobalTotals"); - globalQuery.first({ - success: function(results) { + globalQuery.first({ useMasterKey: true }).then( + function(results) { responseObj.global.missedMessages = results.get("missedSMSCount"); responseObj.global.missedCalls = results.get("missedCallCount"); responseObj.global.missedNotifications = results.get("missedOtherCount"); @@ -244,12 +239,12 @@ Parse.Cloud.define("stats", function(request, response) { response.success(responseObj); } }, - error: function(error) { + function(error) { failureFlag = true; console.error("Got an error " + error.code + " : " + error.message); response.error("Error retrieving global totals"); } - }); + ); }); function friendsStatsFromUserTotals(userTotals, dayIntervals, monthIntervals) { @@ -374,8 +369,8 @@ Parse.Cloud.define("communityStats", function(request, response) { monthlyQuery.lessThan("date", new Date()); monthlyQuery.addDescending("date"); monthlyQuery.limit(monthIntervals.length); //last 12 months of data - monthlyQuery.find({ - success: function(monthlyResults) { + monthlyQuery.find().then( + function(monthlyResults) { responseObj.minutesDrivenMonths = []; responseObj.kmDrivenMonths = []; @@ -406,20 +401,20 @@ Parse.Cloud.define("communityStats", function(request, response) { response.success(responseObj); } }, - error: function(error) { + function(error) { failureFlag = true; console.error("Got an error " + error.code + " : " + error.message); response.error("Error retrieving monthly totals"); } - }); + ); var dailyQuery = new Parse.Query("CommunityDailyTotals"); dailyQuery.equalTo("community", community); dailyQuery.lessThan("date",new Date()); dailyQuery.addDescending("date"); dailyQuery.limit(dayIntervals.length); //last 7 days of data - dailyQuery.find({ - success: function(dailyResults) { + dailyQuery.find().then( + function(dailyResults) { responseObj.minutesDrivenDays = []; responseObj.kmDrivenDays = []; for (var i = 0; i < dayIntervals.length; i++) { @@ -454,17 +449,17 @@ Parse.Cloud.define("communityStats", function(request, response) { response.success(responseObj); } }, - error: function(error) { + function(error) { failureFlag = true; console.error("Got an error " + error.code + " : " + error.message); response.error("Error retrieving daily totals"); } - }); + ); var allTimeQuery = new Parse.Query("CommunityAllTimeTotals"); allTimeQuery.equalTo("community", community); - allTimeQuery.first({ - success: function(results) { + allTimeQuery.first().then( + function(results) { responseObj.missedMessages = results.get("missedSMSCount"); responseObj.missedCalls = results.get("missedCallCount"); responseObj.missedNotifications = results.get("missedOtherCount"); @@ -477,12 +472,12 @@ Parse.Cloud.define("communityStats", function(request, response) { response.success(responseObj); } }, - error: function(error) { + function(error) { failureFlag = true; console.error("Got an error " + error.code + " : " + error.message); response.error("Error retrieving all time totals"); } - }); + ); }); Parse.Cloud.job("statForwardJob", function(request, status) { From 9fb9ca1c449288e8896213501dc89ab6596b0d41 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Thu, 19 Jan 2017 11:49:13 -0800 Subject: [PATCH 02/44] Convert find/first methods to promise formatting (part 2) - convert rest of find/first methods to promise format - useMasterKey() to { useMasterKey: true } formatting --- cloud/CommunityTotals.js | 24 ++++++++-------- cloud/POFriendRelation.js | 25 ++++++++--------- cloud/POFriendRequest.js | 24 ++++++++-------- cloud/POPublicUser.js | 6 ++-- cloud/Promotion.js | 8 +++--- cloud/Stats.js | 8 +++--- cloud/Totals.js | 32 +++++++++++----------- cloud/User.js | 11 ++++---- cloud/main.js | 4 +++ scripts/parse_rest/cloudcode/cloud/main.js | 8 +++--- 10 files changed, 76 insertions(+), 74 deletions(-) diff --git a/cloud/CommunityTotals.js b/cloud/CommunityTotals.js index 06b8608d4c..beb6cf8dee 100644 --- a/cloud/CommunityTotals.js +++ b/cloud/CommunityTotals.js @@ -5,8 +5,8 @@ exports.getAllTimeTotals = function(community, callback) { var CommunityAllTimeTotals = Parse.Object.extend("CommunityAllTimeTotals"); var totalQuery = new Parse.Query(CommunityAllTimeTotals); totalQuery.equalTo("community", community); - totalQuery.first({ - success: function(object) { + totalQuery.first().then( + function(object) { // success var allTimeTotals = object; if (!allTimeTotals) { console.log("CommunityAllTimeTotals not found, creating"); @@ -24,10 +24,10 @@ exports.getAllTimeTotals = function(community, callback) { } callback(allTimeTotals); }, - error: function(error) { + function(error) { // error console.error("Got an error " + error.code + " : " + error.message); } - }); + ); } exports.getDailyTotals = function(community, date, callback, failCallback) { @@ -38,8 +38,8 @@ exports.getDailyTotals = function(community, date, callback, failCallback) { queryDate.setHours(0, 0, 0, 0); //only year, month, day remain totalQuery.equalTo("date", queryDate); totalQuery.equalTo("community", community); - totalQuery.first({ - success: function(object) { + totalQuery.first().then( + function(object) { //success var dailyTotals = object; if (!dailyTotals) { console.log("CommunityDailyTotals not found, creating"); @@ -58,14 +58,14 @@ exports.getDailyTotals = function(community, date, callback, failCallback) { } callback(dailyTotals); }, - error: function(error) { + function(error) { // error console.error("Got an error " + error.code + " : " + error.message); if (failCallback) { failCallback(error); } } - }); + ); } exports.getMonthlyTotals = function(community, date, callback, failCallback) { @@ -77,8 +77,8 @@ exports.getMonthlyTotals = function(community, date, callback, failCallback) { queryDate.setDate(1); //only year, month remain totalQuery.equalTo("date", queryDate); totalQuery.equalTo("community", community); - totalQuery.first({ - success: function(object) { + totalQuery.first().then( + function(object) { var monthlyTotals = object; if (!monthlyTotals) { console.log("CommunityMonthlyTotals not found, creating"); @@ -97,14 +97,14 @@ exports.getMonthlyTotals = function(community, date, callback, failCallback) { } callback(monthlyTotals); }, - error: function(error) { + function(error) { console.error("Got an error " + error.code + " : " + error.message); if (failCallback) { failCallback(error); } } - }); + ); } exports.updateTotals = function(trip, totals) { diff --git a/cloud/POFriendRelation.js b/cloud/POFriendRelation.js index b3245ff2ca..7a4ea05829 100644 --- a/cloud/POFriendRelation.js +++ b/cloud/POFriendRelation.js @@ -49,9 +49,8 @@ Parse.Cloud.beforeSave("POFriendRelation", function(request, response) { if (request.user.id != friendUser.id) { var roleQuery = new Parse.Query(Parse.Role); roleQuery.equalTo("name", "user-" + request.user.id); - roleQuery.first({ - success: function(role) { - Parse.Cloud.useMasterKey(); + roleQuery.first({ useMasterKey: true }).then( + function(role) { role.relation("users").add(friendUser); role.save(null, { success: function(user) { @@ -62,12 +61,12 @@ Parse.Cloud.beforeSave("POFriendRelation", function(request, response) { } }); }, - error: function(error) { + function(error) { console.log("Failed to save role for friend relation with error " + error.code + " : " + error.message); response.error("Unable to find the role"); }, useMasterKey:true - }); + ); } else { response.success(); } @@ -85,8 +84,8 @@ Parse.Cloud.afterSave("POFriendRelation", function(request) { var query = new Parse.Query("POFriendRequest"); query.equalTo("requestingUser", user); query.equalTo("requestedUser", friendUser); - query.find({ - success: function(results) { + query.find().then( + function(results) { if (results.length > 0) { for (var i = 0; i < results.length; i++) { results[i].destroy(); @@ -96,23 +95,23 @@ Parse.Cloud.afterSave("POFriendRelation", function(request) { var friendQuery = new Parse.Query("POFriendRequest"); friendQuery.equalTo("requestingUser", friendUser); friendQuery.equalTo("requestedUser", user); - friendQuery.find({ - success: function(results) { + friendQuery.find().then( + function(results) { if (results.length > 0) { for (var i = 0; i < results.length; i++) { results[i].destroy(); } } }, - error: function(error) { + function(error) { console.log("error when destroying friend request"); } - }); + ); }, - error: function(error) { + function(error) { console.log("error when destroying friend request"); } - }); + ); }); diff --git a/cloud/POFriendRequest.js b/cloud/POFriendRequest.js index aacbbbfe2f..b80d609db0 100644 --- a/cloud/POFriendRequest.js +++ b/cloud/POFriendRequest.js @@ -14,8 +14,8 @@ Parse.Cloud.beforeSave("POFriendRequest", function(request, response) { var query = new Parse.Query("POFriendRelation"); query.equalTo("friendUserId", requestingUser); query.equalTo("userId", requestedUser); - query.find({ - success: function(results) { + query.find().then( + function(results) { if (results.length > 0) { console.log("Not allowed to create a friend request when already friends."); response.error(JSON.stringify({ @@ -38,8 +38,8 @@ Parse.Cloud.beforeSave("POFriendRequest", function(request, response) { } var query = Parse.Query.or(queryFriendRequest, queryInverseFriendRequest); - query.find({ - success: function(results) { + query.find().then( + function(results) { if (results.length > 0) { console.log("Friend request already exists."); response.error(JSON.stringify({ @@ -50,18 +50,18 @@ Parse.Cloud.beforeSave("POFriendRequest", function(request, response) { response.success(); } }, - error: function(error) { + function(error) { console.log("error when checking for existing relations, allowing to continute"); response.success(); } - }); + ); } }, - error: function(error) { + function(error) { console.log("error when checking for existing relations, allowing to continute"); response.success(); } - }); + ); } else { console.log("Love thyself."); response.error(JSON.stringify({ @@ -98,8 +98,8 @@ Parse.Cloud.afterDelete("POFriendRequest", function(request) { queryInverseFriendRequest.equalTo("requestingUser", requestedUser); queryInverseFriendRequest.equalTo("requestedUser", requestingUser); - queryInverseFriendRequest.find({ - success: function(results) { + queryInverseFriendRequest.find().then( + function(results) { Parse.Object.destroyAll(results, { success: function() {}, error: function(error) { @@ -107,10 +107,10 @@ Parse.Cloud.afterDelete("POFriendRequest", function(request) { } }); }, - error: function(error) { + function(error) { console.error("Error finding inverse friend relations " + error.code + ": " + error.message); } - }); + ); }); Parse.Cloud.define("requestedFriend", function(request, response) { diff --git a/cloud/POPublicUser.js b/cloud/POPublicUser.js index eb5650878a..b1c523442b 100644 --- a/cloud/POPublicUser.js +++ b/cloud/POPublicUser.js @@ -26,8 +26,8 @@ Parse.Cloud.afterSave("POPublicUser", function(request) { if (facebookId) { var query = new Parse.Query(POPublicUser); query.equalTo("facebookIdHashed", facebookId); - query.find({ - success: function(results) { + query.find().then( + function(results) { if (results.length > 0) { for (var i = 0; i < results.length; i++) { if (user.id != results[i].id) { @@ -37,6 +37,6 @@ Parse.Cloud.afterSave("POPublicUser", function(request) { } } } - }); + ); } }); diff --git a/cloud/Promotion.js b/cloud/Promotion.js index e9e774c7af..043aa78ce0 100644 --- a/cloud/Promotion.js +++ b/cloud/Promotion.js @@ -15,8 +15,8 @@ Parse.Cloud.define("getPromotion", function(request, response) { promotionQuery.greaterThan("expiresAt", new Date()); promotionQuery.notEqualTo("viewedUsers", user); - promotionQuery.first({ - success: function(promotion) { + promotionQuery.first().then( + function(promotion) { if (promotion) { promotion.relation("viewedUsers").add(user); promotion.save(); @@ -27,9 +27,9 @@ Parse.Cloud.define("getPromotion", function(request, response) { response.success({}); } }, - error: function(error) { + function(error) { console.error("Got an error " + error.code + " : " + error.message); response.error(); } - }); + ); }); diff --git a/cloud/Stats.js b/cloud/Stats.js index 8c77c41550..80c9fd2ba2 100644 --- a/cloud/Stats.js +++ b/cloud/Stats.js @@ -485,8 +485,8 @@ Parse.Cloud.job("statForwardJob", function(request, status) { // add rows for community totals and normal totals var communityQuery = new Parse.Query("Community"); - communityQuery.find({ - success: function(results) { + communityQuery.find().then( + function(results) { var callCount = 2; callCount += results.length * 3; @@ -536,8 +536,8 @@ Parse.Cloud.job("statForwardJob", function(request, status) { }); }; }, - error: function(error) { + function(error) { status.error("error when loading communities to create total rows"); } - }); + ); }); diff --git a/cloud/Totals.js b/cloud/Totals.js index 86c641a733..38d15517a6 100644 --- a/cloud/Totals.js +++ b/cloud/Totals.js @@ -4,8 +4,8 @@ exports.getGlobalTotals = function(callback) { //retrieve the globalTotals object, create with defaults if necessary var GlobalTotals = Parse.Object.extend("GlobalTotals"); var totalQuery = new Parse.Query(GlobalTotals); - totalQuery.first({ - success: function(object) { + totalQuery.first().then( + function(object) { var globalTotals = object; if (!globalTotals) { console.log("GlobalTotals not found, creating"); @@ -21,10 +21,10 @@ exports.getGlobalTotals = function(callback) { } callback(globalTotals); }, - error: function(error) { + function(error) { console.error("Got an error " + error.code + " : " + error.message); } - }); + ); } exports.getDailyTotals = function(date, callback, failCallback) { @@ -34,8 +34,8 @@ exports.getDailyTotals = function(date, callback, failCallback) { var queryDate = new Date(date); queryDate.setHours(0, 0, 0, 0); //only year, month, day remain totalQuery.equalTo("date", queryDate); - totalQuery.first({ - success: function(object) { + totalQuery.first().then( + function(object) { var dailyTotals = object; if (!dailyTotals) { console.log("DailyTotals not found, creating"); @@ -52,14 +52,14 @@ exports.getDailyTotals = function(date, callback, failCallback) { } callback(dailyTotals); }, - error: function(error) { + function(error) { console.error("Got an error " + error.code + " : " + error.message); if (failCallback) { failCallback(error); } } - }); + ); } exports.getMonthlyTotals = function(date, callback, failCallback) { @@ -70,8 +70,8 @@ exports.getMonthlyTotals = function(date, callback, failCallback) { queryDate.setHours(0, 0, 0, 0); queryDate.setDate(1); //only year, month remain totalQuery.equalTo("date", queryDate); - totalQuery.first({ - success: function(object) { + totalQuery.first().then( + function(object) { var monthlyTotals = object; if (!monthlyTotals) { console.log("MonthlyTotals not found, creating"); @@ -88,14 +88,14 @@ exports.getMonthlyTotals = function(date, callback, failCallback) { } callback(monthlyTotals); }, - error: function(error) { + function(error) { console.error("Got an error " + error.code + " : " + error.message); if (failCallback) { failCallback(error); } } - }); + ); } exports.getUserTotals = function(userId, callback, failCallback) { @@ -106,8 +106,8 @@ exports.getUserTotals = function(userId, callback, failCallback) { id: userId }); totalQuery.equalTo("user", user); - totalQuery.first({ - success: function(object) { + totalQuery.first().then( + function(object) { var userTotals = object; if (!userTotals) { @@ -139,14 +139,14 @@ exports.getUserTotals = function(userId, callback, failCallback) { } callback(userTotals); }, - error: function(error) { + function(error) { console.error("Got an error " + error.code + " : " + error.message); if (failCallback) { failCallback(error); } } - }); + ); } exports.updateTotals = function(trip, totals) { diff --git a/cloud/User.js b/cloud/User.js index 61b4332e63..8483d7ff0d 100644 --- a/cloud/User.js +++ b/cloud/User.js @@ -108,8 +108,8 @@ Parse.Cloud.afterSave(Parse.User, function(request) { if (dirtyKeys.indexOf("channels") > -1) { var installationQuery = new Parse.Query(Parse.Installation); installationQuery.equalTo("user", user); - installationQuery.find({ - success: function(installations) { + installationQuery.find({ useMasterKey: true }).then( + function(installations) { if (installations) { for (var i = 0; i < installations.length; i++) { var installation = installations[i]; @@ -120,11 +120,10 @@ Parse.Cloud.afterSave(Parse.User, function(request) { } } }, - error: function(error) { + function(error) { console.error("Unable to find installation " + error.code + " : " + error.message); - }, - useMasterKey:true - }); + } + ); } for (var i in dirtyKeys) { diff --git a/cloud/main.js b/cloud/main.js index aff3726e9a..a8ea77bcc0 100644 --- a/cloud/main.js +++ b/cloud/main.js @@ -11,3 +11,7 @@ require('./Community.js'); require('./User.js'); require('./Installation.js'); +Parse.Cloud.define('hello', function(req, res) { + res.success('Hi'); +}); + diff --git a/scripts/parse_rest/cloudcode/cloud/main.js b/scripts/parse_rest/cloudcode/cloud/main.js index 1c5f7b48c3..255f3b1161 100644 --- a/scripts/parse_rest/cloudcode/cloud/main.js +++ b/scripts/parse_rest/cloudcode/cloud/main.js @@ -9,16 +9,16 @@ Parse.Cloud.define("hello", function(request, response) { Parse.Cloud.define("averageStars", function(request, response) { var query = new Parse.Query("Review"); query.equalTo("movie", request.params.movie); - query.find({ - success: function(results) { + query.find().then( + function(results) { var sum = 0; for (var i = 0; i < results.length; ++i) { sum += results[i].get("stars"); } response.success(sum / results.length); }, - error: function() { + function() { response.error("movie lookup failed"); } - }); + ); }); From 4d26d7a5e31f641f3e2e80751f14032f82926de6 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Thu, 19 Jan 2017 12:05:04 -0800 Subject: [PATCH 03/44] remove extraneous method argument --- cloud/POFriendRelation.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cloud/POFriendRelation.js b/cloud/POFriendRelation.js index 7a4ea05829..1df93dac91 100644 --- a/cloud/POFriendRelation.js +++ b/cloud/POFriendRelation.js @@ -64,8 +64,7 @@ Parse.Cloud.beforeSave("POFriendRelation", function(request, response) { function(error) { console.log("Failed to save role for friend relation with error " + error.code + " : " + error.message); response.error("Unable to find the role"); - }, - useMasterKey:true + } ); } else { response.success(); From 59a0f947e02ab349b73567b23032c496b508711c Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Thu, 19 Jan 2017 14:30:49 -0800 Subject: [PATCH 04/44] /parse on server url --- index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.js b/index.js index 3e34f10935..826ca7d67d 100644 --- a/index.js +++ b/index.js @@ -22,6 +22,9 @@ var api = new ParseServer({ classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions } }); +console.log("SERVER URL\n") +console.log(process.env.SERVER_URL); +console.log("\n\n\n"); // Client-keys like the javascript key or the .NET key are not necessary with parse-server // If you wish you require them, you can set them as options in the initialization above: // javascriptKey, restAPIKey, dotNetKey, clientKey From 5a3d85d36c7f6fb77c53b93a4e7eddf2b1f81f6e Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Thu, 19 Jan 2017 14:35:20 -0800 Subject: [PATCH 05/44] fixed the SERVER_URL on heroku --- index.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/index.js b/index.js index 826ca7d67d..3e34f10935 100644 --- a/index.js +++ b/index.js @@ -22,9 +22,6 @@ var api = new ParseServer({ classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions } }); -console.log("SERVER URL\n") -console.log(process.env.SERVER_URL); -console.log("\n\n\n"); // Client-keys like the javascript key or the .NET key are not necessary with parse-server // If you wish you require them, you can set them as options in the initialization above: // javascriptKey, restAPIKey, dotNetKey, clientKey From bca2eabb9e18f41d1252da77857a73537007cf38 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Thu, 19 Jan 2017 15:13:51 -0800 Subject: [PATCH 06/44] Convert find method to promise styling - missing find that hadn't been coverted --- cloud/POFriendRelation.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cloud/POFriendRelation.js b/cloud/POFriendRelation.js index 1df93dac91..726a113e9a 100644 --- a/cloud/POFriendRelation.js +++ b/cloud/POFriendRelation.js @@ -124,17 +124,16 @@ Parse.Cloud.afterDelete("POFriendRelation", function(request) { success: function(user) { var roleQuery = new Parse.Query(Parse.Role); roleQuery.equalTo("name", "user-" + user.id); - roleQuery.first({ - success: function(role) { - Parse.Cloud.useMasterKey(); + roleQuery.first({ useMasterKey: true }).then( + function(role) { role.relation("users").remove(friendUserPointer); role.save(); }, - error: function(error) { + function(error) { console.log("Failed to remove role for friend relation with error " + error.code + " : " + error.message); }, useMasterKey:true - }); + ); user.remove("channels", "friend-" + friendUserPointer.id); user.save(null, {useMasterKey:true}); }, From d7ff56224be9d72d4c56f156a8f01985cb51f996 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Thu, 19 Jan 2017 15:17:52 -0800 Subject: [PATCH 07/44] Commenting out push notifications for startDriving & stopDriving endpoints --- cloud/Driving.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cloud/Driving.js b/cloud/Driving.js index 2cd9be30d5..9b95b34b91 100644 --- a/cloud/Driving.js +++ b/cloud/Driving.js @@ -9,15 +9,15 @@ Parse.Cloud.define("startedDriving", function(request, response) { var friendChannel = "friend-" + request.user.id var data = { userId: request.user.id }; - PushNotifications.sendAndroidPush([driveChannel], "ca.appcolony.distracteddriver.STARTED_DRIVING", data, pushCallbackCounter); + // PushNotifications.sendAndroidPush([driveChannel], "ca.appcolony.distracteddriver.STARTED_DRIVING", data, pushCallbackCounter); var alert = { "loc-key": "notification-started-driving", "loc-args": [request.user.get("displayName")] }; - PushNotifications.sendIOSPush([driveChannel], alert, true, "startedDriving", data, pushCallbackCounter); + // PushNotifications.sendIOSPush([driveChannel], alert, true, "startedDriving", data, pushCallbackCounter); - PushNotifications.sendIOSPush([friendChannel], null, true, "startedDriving", data, pushCallbackCounter); + // PushNotifications.sendIOSPush([friendChannel], null, true, "startedDriving", data, pushCallbackCounter); }); Parse.Cloud.define("stoppedDriving", function(request, response) { @@ -29,8 +29,8 @@ Parse.Cloud.define("stoppedDriving", function(request, response) { var friendChannel = "friend-" + request.user.id var data = { userId: request.user.id }; - PushNotifications.sendAndroidPush([driveChannel], "ca.appcolony.distracteddriver.STOPPED_DRIVING", data, pushCallbackCounter); - PushNotifications.sendIOSPush([driveChannel, friendChannel], null, true, "stoppedDriving", data, pushCallbackCounter); + // PushNotifications.sendAndroidPush([driveChannel], "ca.appcolony.distracteddriver.STOPPED_DRIVING", data, pushCallbackCounter); + // PushNotifications.sendIOSPush([driveChannel, friendChannel], null, true, "stoppedDriving", data, pushCallbackCounter); }); Parse.Cloud.define("sendEmergencyPush", function(request, response) { From 8fbc3f14b7c55b0e00fdcfb496abc3d8b4773f5d Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Thu, 19 Jan 2017 15:20:21 -0800 Subject: [PATCH 08/44] removed extraneous masterKey input arg --- cloud/POFriendRelation.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cloud/POFriendRelation.js b/cloud/POFriendRelation.js index 726a113e9a..7964ca970d 100644 --- a/cloud/POFriendRelation.js +++ b/cloud/POFriendRelation.js @@ -131,8 +131,7 @@ Parse.Cloud.afterDelete("POFriendRelation", function(request) { }, function(error) { console.log("Failed to remove role for friend relation with error " + error.code + " : " + error.message); - }, - useMasterKey:true + } ); user.remove("channels", "friend-" + friendUserPointer.id); user.save(null, {useMasterKey:true}); From 650e59b214acf7ba6bfa6208ea318d3051012a6a Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Thu, 19 Jan 2017 15:45:28 -0800 Subject: [PATCH 09/44] Convert Save method to promise format * refer to: http://parseplatform.github.io/docs/js/guide/#promises --- cloud/POFriendRelation.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cloud/POFriendRelation.js b/cloud/POFriendRelation.js index 7964ca970d..b47f7f1692 100644 --- a/cloud/POFriendRelation.js +++ b/cloud/POFriendRelation.js @@ -17,15 +17,15 @@ Parse.Cloud.beforeSave("POFriendRelation", function(request, response) { function addAndRemoveChannels(addedChannel, removedChannel) { request.user.remove("channels", removedChannel); - request.user.save(null, { - success: function(user) { + request.user.save().then( + function(user) { request.user.addUnique("channels", addedChannel); request.user.save(null, saveOptions); }, - error: function(user, error) { + function(user, error) { response.error("Unable to save the user"); } - }); + ); } function updateChannelsIfNeeded() { From 8b73244d5ef605eb171eaa3743642c465fcac17c Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Thu, 19 Jan 2017 15:52:39 -0800 Subject: [PATCH 10/44] Convert fetch to promise format (plus two missing save method calls) * refer to http://parseplatform.github.io/docs/js/guide/#promises --- cloud/Installation.js | 11 +++++------ cloud/POFriendRelation.js | 19 +++++++++---------- cloud/User.js | 24 ++++++++++++------------ 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/cloud/Installation.js b/cloud/Installation.js index becb28e3b5..fd2096e815 100644 --- a/cloud/Installation.js +++ b/cloud/Installation.js @@ -10,17 +10,16 @@ Parse.Cloud.beforeSave(Parse.Installation, function(request, response) { id: installation.get("user").id }); - userPointer.fetch({ - success: function(user) { + userPointer.fetch({ useMasterKey: true }).then( + function(user) { installation.set("channels", user.get("channels")); response.success(); }, - error: function(myObject, error) { + function(myObject, error) { console.error("Unable to find user " + userPointer.id + " " + error.code + " : " + error.message); response.error(); - }, - useMasterKey:true - }); + } + ); } else { response.success(); } diff --git a/cloud/POFriendRelation.js b/cloud/POFriendRelation.js index b47f7f1692..7d1f22e453 100644 --- a/cloud/POFriendRelation.js +++ b/cloud/POFriendRelation.js @@ -52,14 +52,14 @@ Parse.Cloud.beforeSave("POFriendRelation", function(request, response) { roleQuery.first({ useMasterKey: true }).then( function(role) { role.relation("users").add(friendUser); - role.save(null, { - success: function(user) { + role.save().then( + function(user) { updateChannelsIfNeeded(); }, - error: function(user, error) { + function(user, error) { response.error("Unable to save the role"); } - }); + ); }, function(error) { console.log("Failed to save role for friend relation with error " + error.code + " : " + error.message); @@ -120,8 +120,8 @@ Parse.Cloud.afterDelete("POFriendRelation", function(request) { var userPointer = request.object.get("user"); var friendUserPointer = request.object.get("friendUser"); - userPointer.fetch({ - success: function(user) { + userPointer.fetch({ useMasterKey: true }).then( + function(user) { var roleQuery = new Parse.Query(Parse.Role); roleQuery.equalTo("name", "user-" + user.id); roleQuery.first({ useMasterKey: true }).then( @@ -136,9 +136,8 @@ Parse.Cloud.afterDelete("POFriendRelation", function(request) { user.remove("channels", "friend-" + friendUserPointer.id); user.save(null, {useMasterKey:true}); }, - error: function(myObject, error) { + function(myObject, error) { console.error("Unable to find user " + userPointer.id + " " + error.code + " : " + error.message); - }, - useMasterKey: true - }); + } + ); }); diff --git a/cloud/User.js b/cloud/User.js index 8483d7ff0d..4e48a72ad7 100644 --- a/cloud/User.js +++ b/cloud/User.js @@ -173,15 +173,15 @@ Parse.Cloud.define("verifyPhoneShortCode", function(request, response) { }); console.log("Saw " + request.params.userId + ". ShortCode: " + request.params.phoneShortCode); - userPointer.fetch({ - success: function(user) { + userPointer.fetch().then( + function(user) { var serverShortCode = user.get("phoneShortCode"); if (serverShortCode == request.params.phoneShortCode) { user.set("phoneNumberVerified", true); - user.save(null, { - success: function() { + user.save().then( + function() { //load sha256 library var jssha = require('./jssha256.js'); @@ -252,21 +252,21 @@ Parse.Cloud.define("verifyPhoneShortCode", function(request, response) { }); }, - error: function(myObject, error) { + function(myObject, error) { console.error("Error when setting phoneNumberVerified " + error.code + " : " + error.message); response.error("Error when setting phoneNumberVerified"); } - }); + ); } else { console.error("Invalid shortcode sent for " + request.params.userId + ". Expecting: " + serverShortCode + " Recieved: " + request.params.phoneShortCode); response.error("Invalid shortcode sent"); } }, - error: function(myObject, error) { + function(myObject, error) { console.error("Unable to find user to verify " + error.code + " : " + error.message); response.error("Unable to find user to verify"); } - }); + ); }); Parse.Cloud.define("sendPhoneShortCode", function(request, response) { @@ -276,8 +276,8 @@ Parse.Cloud.define("sendPhoneShortCode", function(request, response) { var userPointer = new Parse.User({ id: request.params.userId }); - userPointer.fetch({ - success: function(user) { + userPointer.fetch().then( + function(user) { console.log("user: " + user); var phoneShortCode = Math.floor((Math.random() * 900000) + 100000); @@ -302,9 +302,9 @@ Parse.Cloud.define("sendPhoneShortCode", function(request, response) { }); }, - error: function(myObject, error) { + function(myObject, error) { console.error("Unable to find user to send shortcode " + error.code + " : " + error.message); response.error("Unable to find user to verify"); } - }); + ); }); From fadb5fb3f04ebbf21ee7f2106f79eddd6086271a Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Thu, 19 Jan 2017 15:57:44 -0800 Subject: [PATCH 11/44] Convert destroyAll method to promise format - refer to: http://parseplatform.github.io/docs/js/guide/#promises --- cloud/POFriendRequest.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cloud/POFriendRequest.js b/cloud/POFriendRequest.js index b80d609db0..15d3b945cc 100644 --- a/cloud/POFriendRequest.js +++ b/cloud/POFriendRequest.js @@ -100,12 +100,12 @@ Parse.Cloud.afterDelete("POFriendRequest", function(request) { queryInverseFriendRequest.find().then( function(results) { - Parse.Object.destroyAll(results, { - success: function() {}, - error: function(error) { + Parse.Object.destroyAll().then( + function() {}, + function(error) { console.error("Error deleting inverse friend relations " + error.code + ": " + error.message); } - }); + ); }, function(error) { console.error("Error finding inverse friend relations " + error.code + ": " + error.message); From 4453a5ee20232545cd46a0b3ac5aa0097d5c3e4e Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Thu, 19 Jan 2017 16:05:12 -0800 Subject: [PATCH 12/44] Convert Get method to promise format * refer to: http://parseplatform.github.io/docs/js/guide/#promises --- cloud/POTrip.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cloud/POTrip.js b/cloud/POTrip.js index e3c24399de..c900c4471a 100644 --- a/cloud/POTrip.js +++ b/cloud/POTrip.js @@ -33,8 +33,8 @@ Parse.Cloud.afterSave("POTrip", function(request) { }); var userQuery = new Parse.Query("User"); - userQuery.get(trip.get("userId"), { - success: function(user) { + userQuery.get(trip.get("userId")).then( + function(user) { var community = user.get("community"); if (community != null) { CommunityTotals.getAllTimeTotals(community, function(globalTotals) { @@ -48,10 +48,10 @@ Parse.Cloud.afterSave("POTrip", function(request) { }); } }, - error: function(object, error) { + function(object, error) { console.error("Error when retrieving user to update stats " + error.code + " : " + error.message); } - }); + ); } }); From 6b533f43af372d439ab9b0ab91f40fe373616f45 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Fri, 20 Jan 2017 15:22:54 -0800 Subject: [PATCH 13/44] FIREBASE CONFIG - added a field for Firebase Server Key - added a field for Firebase Sender ID --- index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.js b/index.js index 3e34f10935..4b2c571644 100644 --- a/index.js +++ b/index.js @@ -20,6 +20,12 @@ var api = new ParseServer({ serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed liveQuery: { classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions + }, + push: { + android: { + senderId: process.env.FIREBASE_SENDER_ID || '', // The Sender ID of GCM + apiKey: process.env.FIREBASE_SERVER_KEY || '' // The Server API Key of GCM + } } }); // Client-keys like the javascript key or the .NET key are not necessary with parse-server From 62ba1824c46ccdfae75fac55a5d4094d1972239d Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Fri, 20 Jan 2017 15:32:46 -0800 Subject: [PATCH 14/44] renabled push notifications in Driving.js (removed earlier for debugging) --- cloud/Driving.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cloud/Driving.js b/cloud/Driving.js index 9b95b34b91..2cd9be30d5 100644 --- a/cloud/Driving.js +++ b/cloud/Driving.js @@ -9,15 +9,15 @@ Parse.Cloud.define("startedDriving", function(request, response) { var friendChannel = "friend-" + request.user.id var data = { userId: request.user.id }; - // PushNotifications.sendAndroidPush([driveChannel], "ca.appcolony.distracteddriver.STARTED_DRIVING", data, pushCallbackCounter); + PushNotifications.sendAndroidPush([driveChannel], "ca.appcolony.distracteddriver.STARTED_DRIVING", data, pushCallbackCounter); var alert = { "loc-key": "notification-started-driving", "loc-args": [request.user.get("displayName")] }; - // PushNotifications.sendIOSPush([driveChannel], alert, true, "startedDriving", data, pushCallbackCounter); + PushNotifications.sendIOSPush([driveChannel], alert, true, "startedDriving", data, pushCallbackCounter); - // PushNotifications.sendIOSPush([friendChannel], null, true, "startedDriving", data, pushCallbackCounter); + PushNotifications.sendIOSPush([friendChannel], null, true, "startedDriving", data, pushCallbackCounter); }); Parse.Cloud.define("stoppedDriving", function(request, response) { @@ -29,8 +29,8 @@ Parse.Cloud.define("stoppedDriving", function(request, response) { var friendChannel = "friend-" + request.user.id var data = { userId: request.user.id }; - // PushNotifications.sendAndroidPush([driveChannel], "ca.appcolony.distracteddriver.STOPPED_DRIVING", data, pushCallbackCounter); - // PushNotifications.sendIOSPush([driveChannel, friendChannel], null, true, "stoppedDriving", data, pushCallbackCounter); + PushNotifications.sendAndroidPush([driveChannel], "ca.appcolony.distracteddriver.STOPPED_DRIVING", data, pushCallbackCounter); + PushNotifications.sendIOSPush([driveChannel, friendChannel], null, true, "stoppedDriving", data, pushCallbackCounter); }); Parse.Cloud.define("sendEmergencyPush", function(request, response) { From 6a47195a3764e66f9ef317345b4f31dcb6f68dc3 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Fri, 20 Jan 2017 16:38:12 -0800 Subject: [PATCH 15/44] Push notification method upgraded to include master key --- cloud/PushNotifications.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/cloud/PushNotifications.js b/cloud/PushNotifications.js index dc6c00dda7..4467a1f7b2 100644 --- a/cloud/PushNotifications.js +++ b/cloud/PushNotifications.js @@ -57,9 +57,5 @@ function sendPush(query, data, callbackCounter) { Parse.Push.send({ where: query, data: data - }, - { - success: success, - error: error - }); + }, { useMasterKey: true }).then(success, error); } From e90fbd2b8dda33658e7bf007164b75ec3853ee53 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Fri, 20 Jan 2017 17:07:56 -0800 Subject: [PATCH 16/44] Commented out iOS push notif for friends request, pushCallbackCounter to 1 --- cloud/POFriendRequest.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cloud/POFriendRequest.js b/cloud/POFriendRequest.js index 15d3b945cc..7b2e00318c 100644 --- a/cloud/POFriendRequest.js +++ b/cloud/POFriendRequest.js @@ -115,7 +115,7 @@ Parse.Cloud.afterDelete("POFriendRequest", function(request) { Parse.Cloud.define("requestedFriend", function(request, response) { - var pushCallbackCounter = new NetworkUtil.CallbackCounter(2, response); + var pushCallbackCounter = new NetworkUtil.CallbackCounter(1, response); var channels = ["user-" + request.params.requested_user]; @@ -125,12 +125,12 @@ Parse.Cloud.define("requestedFriend", function(request, response) { }; PushNotifications.sendAndroidPush(channels, "ca.appcolony.distracteddriver.FRIEND_REQUEST", androidPushData, pushCallbackCounter); - var alert = { - "loc-key": "notification-friend-request", - "loc-args": [request.user.get("displayName")] - }; - var iOSData = { - userId: request.user.id - }; - PushNotifications.sendIOSPush(channels, alert, true, "friendRequest", iOSData, pushCallbackCounter); + // var alert = { + // "loc-key": "notification-friend-request", + // "loc-args": [request.user.get("displayName")] + // }; + // var iOSData = { + // userId: request.user.id + // }; + // PushNotifications.sendIOSPush(channels, alert, true, "friendRequest", iOSData, pushCallbackCounter); }); From 810273b998d412933a4941e2258040ac7201cd57 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Mon, 23 Jan 2017 09:39:29 -0800 Subject: [PATCH 17/44] Replaced two remaining instances of Parse.Cloud.useMasterKey with new format --- cloud/POFriendRequest.js | 1 - cloud/User.js | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/cloud/POFriendRequest.js b/cloud/POFriendRequest.js index 7b2e00318c..e69ad39475 100644 --- a/cloud/POFriendRequest.js +++ b/cloud/POFriendRequest.js @@ -78,7 +78,6 @@ Parse.Cloud.afterSave("POFriendRequest", function(request) { roleQuery.equalTo("name", "user-" + request.user.id); roleQuery.first({ useMasterKey: true }).then( function(role) { - Parse.Cloud.useMasterKey(); role.relation("users").add(request.object.get("requestedUser")); role.save(); }, diff --git a/cloud/User.js b/cloud/User.js index 4e48a72ad7..824416c325 100644 --- a/cloud/User.js +++ b/cloud/User.js @@ -270,13 +270,11 @@ Parse.Cloud.define("verifyPhoneShortCode", function(request, response) { }); Parse.Cloud.define("sendPhoneShortCode", function(request, response) { - Parse.Cloud.useMasterKey(); - console.log("user id: " + request.params.userId); var userPointer = new Parse.User({ id: request.params.userId }); - userPointer.fetch().then( + userPointer.fetch({ useMasterKey: true }).then( function(user) { console.log("user: " + user); From 7664b95656a8f3ada5aee98ef4e45c6437763ed4 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Mon, 23 Jan 2017 09:54:47 -0800 Subject: [PATCH 18/44] tiny push to force bcrypt update --- cloud/User.js | 1 - 1 file changed, 1 deletion(-) diff --git a/cloud/User.js b/cloud/User.js index 824416c325..e095c0bf92 100644 --- a/cloud/User.js +++ b/cloud/User.js @@ -250,7 +250,6 @@ Parse.Cloud.define("verifyPhoneShortCode", function(request, response) { response.error("Error saving phone number"); }); - }, function(myObject, error) { console.error("Error when setting phoneNumberVerified " + error.code + " : " + error.message); From 5dba733c53081b71157337f3644b2d2e78a5fc10 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Mon, 23 Jan 2017 10:47:57 -0800 Subject: [PATCH 19/44] Added masterKey to friend request save(..) method call --- cloud/POFriendRequest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud/POFriendRequest.js b/cloud/POFriendRequest.js index e69ad39475..c7b89dc615 100644 --- a/cloud/POFriendRequest.js +++ b/cloud/POFriendRequest.js @@ -79,7 +79,7 @@ Parse.Cloud.afterSave("POFriendRequest", function(request) { roleQuery.first({ useMasterKey: true }).then( function(role) { role.relation("users").add(request.object.get("requestedUser")); - role.save(); + role.save({ useMasterKey: true }); }, function(error) { console.log("Failed to save role for friend request with error " + error.code + " : " + error.message); From d4824683fb743503863c103cc9f9b5aefddbed3d Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Mon, 23 Jan 2017 11:19:27 -0800 Subject: [PATCH 20/44] output Role in afterSave for friend request --- cloud/POFriendRequest.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cloud/POFriendRequest.js b/cloud/POFriendRequest.js index c7b89dc615..89e28d2a1a 100644 --- a/cloud/POFriendRequest.js +++ b/cloud/POFriendRequest.js @@ -51,14 +51,14 @@ Parse.Cloud.beforeSave("POFriendRequest", function(request, response) { } }, function(error) { - console.log("error when checking for existing relations, allowing to continute"); + console.log("error when checking for existing relations, allowing to continue"); response.success(); } ); } }, function(error) { - console.log("error when checking for existing relations, allowing to continute"); + console.log("error when checking for existing relations, allowing to continue"); response.success(); } ); @@ -78,6 +78,10 @@ Parse.Cloud.afterSave("POFriendRequest", function(request) { roleQuery.equalTo("name", "user-" + request.user.id); roleQuery.first({ useMasterKey: true }).then( function(role) { + console.log("\n\n%%%%%%%%%%%%%%%%%%%%%%%%\n\n"); + console.log("Inspect Role: \n\n"); + console.log(role); + console.log("\n\n%%%%%%%%%%%%%%%%%%%%%%%%\n\n"); role.relation("users").add(request.object.get("requestedUser")); role.save({ useMasterKey: true }); }, From 5664fd014fa72e2daf405fda6edb2670e5407e95 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Mon, 23 Jan 2017 11:28:13 -0800 Subject: [PATCH 21/44] Inspect Requested User in friend request --- cloud/POFriendRequest.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cloud/POFriendRequest.js b/cloud/POFriendRequest.js index 89e28d2a1a..320a656ca2 100644 --- a/cloud/POFriendRequest.js +++ b/cloud/POFriendRequest.js @@ -82,6 +82,9 @@ Parse.Cloud.afterSave("POFriendRequest", function(request) { console.log("Inspect Role: \n\n"); console.log(role); console.log("\n\n%%%%%%%%%%%%%%%%%%%%%%%%\n\n"); + console.log("Requested User: \n\n"); + console.log(request.object.get("requestedUser")); + console.log("\n\n%%%%%%%%%%%%%%%%%%%%%%%%\n\n"); role.relation("users").add(request.object.get("requestedUser")); role.save({ useMasterKey: true }); }, From c58a72f8b1f6faddff030e3a36d5722c68982d2f Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Mon, 23 Jan 2017 11:32:59 -0800 Subject: [PATCH 22/44] Missing first param in save method call --- cloud/POFriendRequest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud/POFriendRequest.js b/cloud/POFriendRequest.js index 320a656ca2..b46d8bda63 100644 --- a/cloud/POFriendRequest.js +++ b/cloud/POFriendRequest.js @@ -86,7 +86,7 @@ Parse.Cloud.afterSave("POFriendRequest", function(request) { console.log(request.object.get("requestedUser")); console.log("\n\n%%%%%%%%%%%%%%%%%%%%%%%%\n\n"); role.relation("users").add(request.object.get("requestedUser")); - role.save({ useMasterKey: true }); + role.save({},{ useMasterKey: true }); }, function(error) { console.log("Failed to save role for friend request with error " + error.code + " : " + error.message); From 2a398186709e649091e594bb683853292581c387 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Mon, 23 Jan 2017 11:54:38 -0800 Subject: [PATCH 23/44] Updated any save(..) method calls to use the masterKey * note, first input arg for the save method should be null or empty obj: ex: save( {},{ useMasterKey: true } ) --- cloud/Community.js | 6 +++--- cloud/CommunityTotals.js | 8 ++++---- cloud/POFriendRelation.js | 6 +++--- cloud/POFriendRequest.js | 7 ------- cloud/POTrip.js | 8 ++++---- cloud/Promotion.js | 2 +- cloud/Totals.js | 8 ++++---- cloud/User.js | 14 +++++++------- 8 files changed, 26 insertions(+), 33 deletions(-) diff --git a/cloud/Community.js b/cloud/Community.js index 10fb03842c..276d73cd04 100644 --- a/cloud/Community.js +++ b/cloud/Community.js @@ -55,21 +55,21 @@ function incrementCommunityTotalsForKey(community, key, response) { CommunityTotals.getAllTimeTotals(community, function(allTimeTotals) { allTimeTotals.increment(key); - allTimeTotals.save(); + allTimeTotals.save({},{ useMasterKey: true }); if (--queryCount == 0) { response.success(); } }); CommunityTotals.getDailyTotals(community, currDate, function(dailyTotals) { dailyTotals.increment(key); - dailyTotals.save(); + dailyTotals.save({},{ useMasterKey: true }); if (--queryCount == 0) { response.success(); } }); CommunityTotals.getMonthlyTotals(community, currDate, function(monthlyTotals) { monthlyTotals.increment(key); - monthlyTotals.save(); + monthlyTotals.save({},{ useMasterKey: true }); if (--queryCount == 0) { response.success(); } diff --git a/cloud/CommunityTotals.js b/cloud/CommunityTotals.js index beb6cf8dee..d3601f0327 100644 --- a/cloud/CommunityTotals.js +++ b/cloud/CommunityTotals.js @@ -20,7 +20,7 @@ exports.getAllTimeTotals = function(community, callback) { allTimeTotals.set("missedCallCount", 0); allTimeTotals.set("missedOtherCount", 0); allTimeTotals.set("community", community); - allTimeTotals.save(); + allTimeTotals.save({},{ useMasterKey: true }); } callback(allTimeTotals); }, @@ -54,7 +54,7 @@ exports.getDailyTotals = function(community, date, callback, failCallback) { dailyTotals.set("missedCallCount", 0); dailyTotals.set("missedOtherCount", 0); dailyTotals.set("community", community); - dailyTotals.save(); + dailyTotals.save({},{ useMasterKey: true }); } callback(dailyTotals); }, @@ -93,7 +93,7 @@ exports.getMonthlyTotals = function(community, date, callback, failCallback) { monthlyTotals.set("missedCallCount", 0); monthlyTotals.set("missedOtherCount", 0); monthlyTotals.set("community", community); - monthlyTotals.save(); + monthlyTotals.save({},{ useMasterKey: true }); } callback(monthlyTotals); }, @@ -136,6 +136,6 @@ exports.updateTotals = function(trip, totals) { if (missedOtherCount) { totals.increment("missedOtherCount", missedOtherCount); } - totals.save(); + totals.save({},{ useMasterKey: true }); } } diff --git a/cloud/POFriendRelation.js b/cloud/POFriendRelation.js index 7d1f22e453..e0be4a66b1 100644 --- a/cloud/POFriendRelation.js +++ b/cloud/POFriendRelation.js @@ -17,7 +17,7 @@ Parse.Cloud.beforeSave("POFriendRelation", function(request, response) { function addAndRemoveChannels(addedChannel, removedChannel) { request.user.remove("channels", removedChannel); - request.user.save().then( + request.user.save({},{ useMasterKey: true }).then( function(user) { request.user.addUnique("channels", addedChannel); request.user.save(null, saveOptions); @@ -52,7 +52,7 @@ Parse.Cloud.beforeSave("POFriendRelation", function(request, response) { roleQuery.first({ useMasterKey: true }).then( function(role) { role.relation("users").add(friendUser); - role.save().then( + role.save({},{ useMasterKey: true }).then( function(user) { updateChannelsIfNeeded(); }, @@ -127,7 +127,7 @@ Parse.Cloud.afterDelete("POFriendRelation", function(request) { roleQuery.first({ useMasterKey: true }).then( function(role) { role.relation("users").remove(friendUserPointer); - role.save(); + role.save({},{ useMasterKey: true }); }, function(error) { console.log("Failed to remove role for friend relation with error " + error.code + " : " + error.message); diff --git a/cloud/POFriendRequest.js b/cloud/POFriendRequest.js index b46d8bda63..3b1bb9c14f 100644 --- a/cloud/POFriendRequest.js +++ b/cloud/POFriendRequest.js @@ -78,13 +78,6 @@ Parse.Cloud.afterSave("POFriendRequest", function(request) { roleQuery.equalTo("name", "user-" + request.user.id); roleQuery.first({ useMasterKey: true }).then( function(role) { - console.log("\n\n%%%%%%%%%%%%%%%%%%%%%%%%\n\n"); - console.log("Inspect Role: \n\n"); - console.log(role); - console.log("\n\n%%%%%%%%%%%%%%%%%%%%%%%%\n\n"); - console.log("Requested User: \n\n"); - console.log(request.object.get("requestedUser")); - console.log("\n\n%%%%%%%%%%%%%%%%%%%%%%%%\n\n"); role.relation("users").add(request.object.get("requestedUser")); role.save({},{ useMasterKey: true }); }, diff --git a/cloud/POTrip.js b/cloud/POTrip.js index c900c4471a..688c37259d 100644 --- a/cloud/POTrip.js +++ b/cloud/POTrip.js @@ -16,20 +16,20 @@ Parse.Cloud.afterSave("POTrip", function(request) { if (!trip.existed()) { Totals.getGlobalTotals(function(globalTotals) { Totals.updateTotals(trip, globalTotals); - globalTotals.save(); + globalTotals.save({},{ useMasterKey: true }); }); Totals.getDailyTotals(trip.get("startTime"), function(dailyTotals) { Totals.updateTotals(trip, dailyTotals); - dailyTotals.save(); + dailyTotals.save({},{ useMasterKey: true }); }); Totals.getMonthlyTotals(trip.get("startTime"), function(monthlyTotals) { Totals.updateTotals(trip, monthlyTotals); - monthlyTotals.save(); + monthlyTotals.save({},{ useMasterKey: true }); }); Totals.getUserTotals(trip.get("userId"), function(userTotals) { Totals.updateUserTotals(trip, userTotals); - userTotals.save(); + userTotals.save({},{ useMasterKey: true }); }); var userQuery = new Parse.Query("User"); diff --git a/cloud/Promotion.js b/cloud/Promotion.js index 043aa78ce0..f9cf5ce02f 100644 --- a/cloud/Promotion.js +++ b/cloud/Promotion.js @@ -19,7 +19,7 @@ Parse.Cloud.define("getPromotion", function(request, response) { function(promotion) { if (promotion) { promotion.relation("viewedUsers").add(user); - promotion.save(); + promotion.save({},{ useMasterKey: true }); var promotionJSON = {"url" : promotion.get("url")}; response.success(promotionJSON); } else { diff --git a/cloud/Totals.js b/cloud/Totals.js index 38d15517a6..a14a165f6a 100644 --- a/cloud/Totals.js +++ b/cloud/Totals.js @@ -17,7 +17,7 @@ exports.getGlobalTotals = function(callback) { globalTotals.set("missedSMSCount", 0); globalTotals.set("missedCallCount", 0); globalTotals.set("missedOtherCount", 0); - globalTotals.save(); + globalTotals.save({},{ useMasterKey: true }); } callback(globalTotals); }, @@ -48,7 +48,7 @@ exports.getDailyTotals = function(date, callback, failCallback) { dailyTotals.set("missedSMSCount", 0); dailyTotals.set("missedCallCount", 0); dailyTotals.set("missedOtherCount", 0); - dailyTotals.save(); + dailyTotals.save({},{ useMasterKey: true }); } callback(dailyTotals); }, @@ -84,7 +84,7 @@ exports.getMonthlyTotals = function(date, callback, failCallback) { monthlyTotals.set("missedSMSCount", 0); monthlyTotals.set("missedCallCount", 0); monthlyTotals.set("missedOtherCount", 0); - monthlyTotals.save(); + monthlyTotals.save({},{ useMasterKey: true }); } callback(monthlyTotals); }, @@ -132,7 +132,7 @@ exports.getUserTotals = function(userId, callback, failCallback) { userTotals.set("distanceTravelled", 0); userTotals.set("minutesTravelled", 0); userTotals.set("user", user); - userTotals.save(); + userTotals.save({},{ useMasterKey: true }); // console.log("UserTotals creating:"+JSON.stringify(userTotals)); diff --git a/cloud/User.js b/cloud/User.js index e095c0bf92..1efd32dfd3 100644 --- a/cloud/User.js +++ b/cloud/User.js @@ -77,30 +77,30 @@ Parse.Cloud.afterSave(Parse.User, function(request) { console.log("added new user"); Totals.getDailyTotals(new Date(), function(dailyTotals) { dailyTotals.increment("users"); - dailyTotals.save(); + dailyTotals.save({},{ useMasterKey: true }); }); Totals.getMonthlyTotals(new Date(), function(monthlyTotals) { monthlyTotals.increment("users"); - monthlyTotals.save(); + monthlyTotals.save({},{ useMasterKey: true }); }); Totals.getGlobalTotals(function(globalTotals) { globalTotals.increment("users"); - globalTotals.save(); + globalTotals.save({},{ useMasterKey: true }); }); //https://www.parse.com/questions/errors-when-trying-to-set-acls-in-user-beforesave var roleACL = new Parse.ACL(); roleACL.setPublicReadAccess(true); var role = new Parse.Role("user-" + user.id, roleACL); - role.save(); + role.save({},{ useMasterKey: true }); var userACL = new Parse.ACL(user); userACL.setRoleReadAccess("user-" + user.id, true); user.setACL(userACL); user.addUnique("channels", "user-" + user.id); - user.save(); + user.save({},{ useMasterKey: true }); } var dirtyKeys = request.object.get("dirtyKeys"); @@ -180,7 +180,7 @@ Parse.Cloud.define("verifyPhoneShortCode", function(request, response) { if (serverShortCode == request.params.phoneShortCode) { user.set("phoneNumberVerified", true); - user.save().then( + user.save({},{ useMasterKey: true }).then( function() { //load sha256 library @@ -279,7 +279,7 @@ Parse.Cloud.define("sendPhoneShortCode", function(request, response) { var phoneShortCode = Math.floor((Math.random() * 900000) + 100000); user.set("phoneShortCode", phoneShortCode); - user.save(); + user.save({},{ useMasterKey: true }); var formattedPhoneShortCode = phoneShortCode.toString() formattedPhoneShortCode = formattedPhoneShortCode.slice(0, 3) + " " + formattedPhoneShortCode.slice(3); From e2d1706eef358e266b0a5212d98f272de249b9ee Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Mon, 23 Jan 2017 14:11:44 -0800 Subject: [PATCH 24/44] Enabled VERBOSE logging, commented out Morgon (for now) --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 4b2c571644..0ff6080fff 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ // compatible API routes. var express = require('express'); -var morgan = require('morgan'); +// var morgan = require('morgan'); var ParseServer = require('parse-server').ParseServer; var path = require('path'); @@ -16,6 +16,7 @@ var api = new ParseServer({ databaseURI: databaseUri || 'mongodb://localhost:27017/dev', cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js', appId: process.env.APP_ID || 'myAppId', + verbose: process.env.VERBOSE || false, masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret! serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed liveQuery: { @@ -33,7 +34,7 @@ var api = new ParseServer({ // javascriptKey, restAPIKey, dotNetKey, clientKey var app = express(); -app.use(morgan('combined')); +// app.use(morgan('combined')); // Serve static assets from the /public folder app.use('/public', express.static(path.join(__dirname, '/public'))); From 001abfab41eacbea872ea06d9b177075b1ba8737 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Mon, 23 Jan 2017 14:48:15 -0800 Subject: [PATCH 25/44] Update to sendPush method; includes some debug calls --- cloud/PushNotifications.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/cloud/PushNotifications.js b/cloud/PushNotifications.js index 4467a1f7b2..61aff4641a 100644 --- a/cloud/PushNotifications.js +++ b/cloud/PushNotifications.js @@ -46,16 +46,22 @@ exports.sendIOSPush = function(channels, alert, contentAvailable, category, data } function sendPush(query, data, callbackCounter) { - var success = function() { - callbackCounter.success(); - } - - var error = function(error) { - callbackCounter.error(error); - } + console.log("\n\n %%%%%%%%%%%%%%%%%%%%%%%%%% \n\n "); + console.log("Query"); + console.log(query); + console.log("\n\n %%%%%%%%%%%%%%%%%%%%%%%%%% \n\n "); + console.log("Data"); + console.log(data); + console.log("\n\n %%%%%%%%%%%%%%%%%%%%%%%%%% \n\n "); Parse.Push.send({ where: query, data: data - }, { useMasterKey: true }).then(success, error); + }, { useMasterKey: true }).then( + function(){ + console.log('Push sent!'); + }, function(error) { // error + console.error("Got an error " + error.code + " : " + error.message); + } + ); } From 37ee1c4b3080c17cd08a21f3aebe2cff6c962ecd Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Mon, 23 Jan 2017 14:59:00 -0800 Subject: [PATCH 26/44] Removed debug comments --- cloud/PushNotifications.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/cloud/PushNotifications.js b/cloud/PushNotifications.js index 61aff4641a..e5e5b70e6d 100644 --- a/cloud/PushNotifications.js +++ b/cloud/PushNotifications.js @@ -46,14 +46,6 @@ exports.sendIOSPush = function(channels, alert, contentAvailable, category, data } function sendPush(query, data, callbackCounter) { - console.log("\n\n %%%%%%%%%%%%%%%%%%%%%%%%%% \n\n "); - console.log("Query"); - console.log(query); - console.log("\n\n %%%%%%%%%%%%%%%%%%%%%%%%%% \n\n "); - console.log("Data"); - console.log(data); - console.log("\n\n %%%%%%%%%%%%%%%%%%%%%%%%%% \n\n "); - Parse.Push.send({ where: query, data: data From f28ad882f72460af3c3fd23483dc542c48187f79 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Mon, 23 Jan 2017 15:09:31 -0800 Subject: [PATCH 27/44] Comment out push notif success logging --- cloud/PushNotifications.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud/PushNotifications.js b/cloud/PushNotifications.js index e5e5b70e6d..8b9d117194 100644 --- a/cloud/PushNotifications.js +++ b/cloud/PushNotifications.js @@ -51,7 +51,7 @@ function sendPush(query, data, callbackCounter) { data: data }, { useMasterKey: true }).then( function(){ - console.log('Push sent!'); + // console.log('Push sent!'); }, function(error) { // error console.error("Got an error " + error.code + " : " + error.message); } From f4dc9c31b590577dfc88841a34043821d42818b6 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Mon, 23 Jan 2017 15:20:59 -0800 Subject: [PATCH 28/44] multiple friend request debugging --- cloud/POFriendRequest.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cloud/POFriendRequest.js b/cloud/POFriendRequest.js index 3b1bb9c14f..811d12a0a0 100644 --- a/cloud/POFriendRequest.js +++ b/cloud/POFriendRequest.js @@ -40,6 +40,10 @@ Parse.Cloud.beforeSave("POFriendRequest", function(request, response) { var query = Parse.Query.or(queryFriendRequest, queryInverseFriendRequest); query.find().then( function(results) { + console.log("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n"); + console.log("Results"+ " (length: " + results.length + "):\n"); + console.log(results); + console.log("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n"); if (results.length > 0) { console.log("Friend request already exists."); response.error(JSON.stringify({ From 31ddb412f421bcab5f2a19dcba0dc77a8917caab Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Mon, 23 Jan 2017 16:14:07 -0800 Subject: [PATCH 29/44] MasterKey in returned query call --- cloud/User.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud/User.js b/cloud/User.js index 1efd32dfd3..a75d120e76 100644 --- a/cloud/User.js +++ b/cloud/User.js @@ -227,7 +227,7 @@ Parse.Cloud.define("verifyPhoneShortCode", function(request, response) { //find the current public user var query = new Parse.Query(POPublicUser); query.equalTo("user", userPointer); - return query.first(); + return query.first({useMasterKey:true}); }).then(function(object) { From 8acb7466a84efb8fdabc755d898fadee34e4dc22 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Mon, 23 Jan 2017 16:37:44 -0800 Subject: [PATCH 30/44] Update to verifyPhoneShortCode method: useMasterKey flag --- cloud/User.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cloud/User.js b/cloud/User.js index a75d120e76..354c7e9f53 100644 --- a/cloud/User.js +++ b/cloud/User.js @@ -173,7 +173,7 @@ Parse.Cloud.define("verifyPhoneShortCode", function(request, response) { }); console.log("Saw " + request.params.userId + ". ShortCode: " + request.params.phoneShortCode); - userPointer.fetch().then( + userPointer.fetch({useMasterKey:true}).then( function(user) { var serverShortCode = user.get("phoneShortCode"); @@ -197,7 +197,7 @@ Parse.Cloud.define("verifyPhoneShortCode", function(request, response) { var queryPublicUsersWithPhone = new Parse.Query(POPublicUser); queryPublicUsersWithPhone.equalTo("phoneNumberHashed", hashedPhoneNumber); - queryPublicUsersWithPhone.find(function(publicUsers) { + queryPublicUsersWithPhone.find({useMasterKey:true}).then(function(publicUsers) { //null out any existing users with this phone number for (var i = 0; i < publicUsers.length; i++) { @@ -238,7 +238,7 @@ Parse.Cloud.define("verifyPhoneShortCode", function(request, response) { publicUser.set("user", userPointer); } publicUser.set("phoneNumberHashed", hashedPhoneNumber); - return publicUser.save(null, {useMasterKey:true}); + return publicUser.save({}, {useMasterKey:true}); }).then(function() { From b42d9496909fdf58950617aa93d6eeef6ffd067c Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Mon, 23 Jan 2017 16:52:53 -0800 Subject: [PATCH 31/44] POFriendRequest: added masterKey to inner query --- cloud/POFriendRequest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud/POFriendRequest.js b/cloud/POFriendRequest.js index 811d12a0a0..87ddb04633 100644 --- a/cloud/POFriendRequest.js +++ b/cloud/POFriendRequest.js @@ -38,7 +38,7 @@ Parse.Cloud.beforeSave("POFriendRequest", function(request, response) { } var query = Parse.Query.or(queryFriendRequest, queryInverseFriendRequest); - query.find().then( + query.find({ useMasterKey: true }).then( function(results) { console.log("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n"); console.log("Results"+ " (length: " + results.length + "):\n"); From 5c969bd5df2a5463bfc0173c2beffc6f2a988089 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Mon, 23 Jan 2017 17:18:03 -0800 Subject: [PATCH 32/44] MasterKey updates, renamed result => res to avoid conflicts --- scripts/parse_rest/cloudcode/cloud/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/parse_rest/cloudcode/cloud/main.js b/scripts/parse_rest/cloudcode/cloud/main.js index 255f3b1161..878383e294 100644 --- a/scripts/parse_rest/cloudcode/cloud/main.js +++ b/scripts/parse_rest/cloudcode/cloud/main.js @@ -9,7 +9,7 @@ Parse.Cloud.define("hello", function(request, response) { Parse.Cloud.define("averageStars", function(request, response) { var query = new Parse.Query("Review"); query.equalTo("movie", request.params.movie); - query.find().then( + query.find({ useMasterKey: true }).then( function(results) { var sum = 0; for (var i = 0; i < results.length; ++i) { From b192f962f97928ff3ce2d5336333701e7478bc68 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Tue, 24 Jan 2017 09:36:10 -0800 Subject: [PATCH 33/44] serverShortCode debug code --- cloud/POFriendRelation.js | 4 ++-- cloud/POFriendRequest.js | 12 ++++++------ cloud/POPublicUser.js | 2 +- cloud/Stats.js | 2 +- cloud/User.js | 6 +++++- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/cloud/POFriendRelation.js b/cloud/POFriendRelation.js index e0be4a66b1..cd4642d725 100644 --- a/cloud/POFriendRelation.js +++ b/cloud/POFriendRelation.js @@ -83,7 +83,7 @@ Parse.Cloud.afterSave("POFriendRelation", function(request) { var query = new Parse.Query("POFriendRequest"); query.equalTo("requestingUser", user); query.equalTo("requestedUser", friendUser); - query.find().then( + query.find({ useMasterKey: true }).then( function(results) { if (results.length > 0) { for (var i = 0; i < results.length; i++) { @@ -94,7 +94,7 @@ Parse.Cloud.afterSave("POFriendRelation", function(request) { var friendQuery = new Parse.Query("POFriendRequest"); friendQuery.equalTo("requestingUser", friendUser); friendQuery.equalTo("requestedUser", user); - friendQuery.find().then( + friendQuery.find({ useMasterKey: true }).then( function(results) { if (results.length > 0) { for (var i = 0; i < results.length; i++) { diff --git a/cloud/POFriendRequest.js b/cloud/POFriendRequest.js index 87ddb04633..5d31d6e8fe 100644 --- a/cloud/POFriendRequest.js +++ b/cloud/POFriendRequest.js @@ -14,7 +14,7 @@ Parse.Cloud.beforeSave("POFriendRequest", function(request, response) { var query = new Parse.Query("POFriendRelation"); query.equalTo("friendUserId", requestingUser); query.equalTo("userId", requestedUser); - query.find().then( + query.find({ useMasterKey: true }).then( function(results) { if (results.length > 0) { console.log("Not allowed to create a friend request when already friends."); @@ -39,12 +39,12 @@ Parse.Cloud.beforeSave("POFriendRequest", function(request, response) { var query = Parse.Query.or(queryFriendRequest, queryInverseFriendRequest); query.find({ useMasterKey: true }).then( - function(results) { + function(res) { console.log("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n"); - console.log("Results"+ " (length: " + results.length + "):\n"); - console.log(results); + console.log("Results"+ " (length: " + res.length + "):\n"); + console.log(res); console.log("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n"); - if (results.length > 0) { + if (res.length > 0) { console.log("Friend request already exists."); response.error(JSON.stringify({ code: 1, @@ -101,7 +101,7 @@ Parse.Cloud.afterDelete("POFriendRequest", function(request) { queryInverseFriendRequest.equalTo("requestingUser", requestedUser); queryInverseFriendRequest.equalTo("requestedUser", requestingUser); - queryInverseFriendRequest.find().then( + queryInverseFriendRequest.find({ useMasterKey: true }).then( function(results) { Parse.Object.destroyAll().then( function() {}, diff --git a/cloud/POPublicUser.js b/cloud/POPublicUser.js index b1c523442b..3cc40cfad1 100644 --- a/cloud/POPublicUser.js +++ b/cloud/POPublicUser.js @@ -26,7 +26,7 @@ Parse.Cloud.afterSave("POPublicUser", function(request) { if (facebookId) { var query = new Parse.Query(POPublicUser); query.equalTo("facebookIdHashed", facebookId); - query.find().then( + query.find({ useMasterKey: true }).then( function(results) { if (results.length > 0) { for (var i = 0; i < results.length; i++) { diff --git a/cloud/Stats.js b/cloud/Stats.js index 80c9fd2ba2..e3ce459c37 100644 --- a/cloud/Stats.js +++ b/cloud/Stats.js @@ -104,7 +104,7 @@ Parse.Cloud.define("stats", function(request, response) { var userTotalsQuery = new Parse.Query("UserTotals"); userTotalsQuery.containedIn("user", friends); - userTotalsQuery.find().then( + userTotalsQuery.find({ useMasterKey: true }).then( function(userTotals) { //success responseObj.friends = friendsStatsFromUserTotals(userTotals, dayIntervals, monthIntervals); if (--queryCount == 0 && !failureFlag) { diff --git a/cloud/User.js b/cloud/User.js index 354c7e9f53..a83bcb44eb 100644 --- a/cloud/User.js +++ b/cloud/User.js @@ -150,7 +150,7 @@ Parse.Cloud.afterSave(Parse.User, function(request) { //find the current public user var query = new Parse.Query(POPublicUser); query.equalTo("user", request.object); - query.first().then(function(object) { + query.first({ useMasterKey: true }).then(function(object) { //save public user with hashed phone number for search var publicUser = object; @@ -176,6 +176,10 @@ Parse.Cloud.define("verifyPhoneShortCode", function(request, response) { userPointer.fetch({useMasterKey:true}).then( function(user) { var serverShortCode = user.get("phoneShortCode"); + console.log("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n"); + console.log("serverShortCode:\n"); + console.log(serverShortCode); + console.log("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n"); if (serverShortCode == request.params.phoneShortCode) { From 834570915ea4a16e9d02b2b3cc7cc12e04906733 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Tue, 24 Jan 2017 12:50:53 -0800 Subject: [PATCH 34/44] sendPhoneShortCode testing --- cloud/POFriendRequest.js | 4 ---- cloud/Stats.js | 6 +++--- cloud/User.js | 31 +++++++++++++++---------------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/cloud/POFriendRequest.js b/cloud/POFriendRequest.js index 5d31d6e8fe..cb20e11594 100644 --- a/cloud/POFriendRequest.js +++ b/cloud/POFriendRequest.js @@ -40,10 +40,6 @@ Parse.Cloud.beforeSave("POFriendRequest", function(request, response) { var query = Parse.Query.or(queryFriendRequest, queryInverseFriendRequest); query.find({ useMasterKey: true }).then( function(res) { - console.log("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n"); - console.log("Results"+ " (length: " + res.length + "):\n"); - console.log(res); - console.log("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n"); if (res.length > 0) { console.log("Friend request already exists."); response.error(JSON.stringify({ diff --git a/cloud/Stats.js b/cloud/Stats.js index e3ce459c37..adff2fe883 100644 --- a/cloud/Stats.js +++ b/cloud/Stats.js @@ -413,7 +413,7 @@ Parse.Cloud.define("communityStats", function(request, response) { dailyQuery.lessThan("date",new Date()); dailyQuery.addDescending("date"); dailyQuery.limit(dayIntervals.length); //last 7 days of data - dailyQuery.find().then( + dailyQuery.find({ useMasterKey: true }).then( function(dailyResults) { responseObj.minutesDrivenDays = []; responseObj.kmDrivenDays = []; @@ -458,7 +458,7 @@ Parse.Cloud.define("communityStats", function(request, response) { var allTimeQuery = new Parse.Query("CommunityAllTimeTotals"); allTimeQuery.equalTo("community", community); - allTimeQuery.first().then( + allTimeQuery.first({ useMasterKey: true }).then( function(results) { responseObj.missedMessages = results.get("missedSMSCount"); responseObj.missedCalls = results.get("missedCallCount"); @@ -485,7 +485,7 @@ Parse.Cloud.job("statForwardJob", function(request, status) { // add rows for community totals and normal totals var communityQuery = new Parse.Query("Community"); - communityQuery.find().then( + communityQuery.find({ useMasterKey: true }).then( function(results) { var callCount = 2; callCount += results.length * 3; diff --git a/cloud/User.js b/cloud/User.js index a83bcb44eb..c0933fb7d7 100644 --- a/cloud/User.js +++ b/cloud/User.js @@ -176,10 +176,6 @@ Parse.Cloud.define("verifyPhoneShortCode", function(request, response) { userPointer.fetch({useMasterKey:true}).then( function(user) { var serverShortCode = user.get("phoneShortCode"); - console.log("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n"); - console.log("serverShortCode:\n"); - console.log(serverShortCode); - console.log("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n"); if (serverShortCode == request.params.phoneShortCode) { @@ -288,19 +284,22 @@ Parse.Cloud.define("sendPhoneShortCode", function(request, response) { var formattedPhoneShortCode = phoneShortCode.toString() formattedPhoneShortCode = formattedPhoneShortCode.slice(0, 3) + " " + formattedPhoneShortCode.slice(3); + console.log('\n\n%%%%%%%%%\n\n'); + console.log('TWilio'); + console.log('\n\n%%%%%%%%%\n\n'); //TODO send shortcode from twilio - twilio.sendSMS({ - From: "+15873170710", - To: user.get("phoneNumber"), - Body: "Thanks for using OneTap! Your code is " + formattedPhoneShortCode - }, { - success: function(httpResponse) { - response.success(); - }, - error: function(httpResponse) { - response.error("unable to send shortcode from twilio: " + httpResponse); - } - }); + // twilio.sendSMS({ + // From: "+15873170710", + // To: user.get("phoneNumber"), + // Body: "Thanks for using OneTap! Your code is " + formattedPhoneShortCode + // }, { + // success: function(httpResponse) { + // response.success(); + // }, + // error: function(httpResponse) { + // response.error("unable to send shortcode from twilio: " + httpResponse); + // } + // }); }, function(myObject, error) { From 6389981047b253b07390946c2d44939af753e672 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Tue, 24 Jan 2017 12:54:10 -0800 Subject: [PATCH 35/44] sendPhoneShortCode testing --- cloud/User.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/cloud/User.js b/cloud/User.js index c0933fb7d7..05101e3944 100644 --- a/cloud/User.js +++ b/cloud/User.js @@ -285,21 +285,22 @@ Parse.Cloud.define("sendPhoneShortCode", function(request, response) { formattedPhoneShortCode = formattedPhoneShortCode.slice(0, 3) + " " + formattedPhoneShortCode.slice(3); console.log('\n\n%%%%%%%%%\n\n'); - console.log('TWilio'); - console.log('\n\n%%%%%%%%%\n\n'); + console.log('TWilio \n'); + //TODO send shortcode from twilio - // twilio.sendSMS({ - // From: "+15873170710", - // To: user.get("phoneNumber"), - // Body: "Thanks for using OneTap! Your code is " + formattedPhoneShortCode - // }, { - // success: function(httpResponse) { - // response.success(); - // }, - // error: function(httpResponse) { - // response.error("unable to send shortcode from twilio: " + httpResponse); - // } - // }); + twilio.sendSMS({ + From: "+15873170710", + To: user.get("phoneNumber"), + Body: "Thanks for using OneTap! Your code is " + formattedPhoneShortCode + }).then( + function(httpResponse) { + response.success(); + }, + function(httpResponse) { + response.error("unable to send shortcode from twilio: " + httpResponse); + } + ); + console.log('\n\n%%%%%%%%%\n\n'); }, function(myObject, error) { From 2277032a2a30b5b2b016d60de517b7e9b8804542 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Tue, 24 Jan 2017 13:43:56 -0800 Subject: [PATCH 36/44] Twilio sendSMS => sendMessage --- cloud/User.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/cloud/User.js b/cloud/User.js index 05101e3944..f139e12d1e 100644 --- a/cloud/User.js +++ b/cloud/User.js @@ -285,22 +285,21 @@ Parse.Cloud.define("sendPhoneShortCode", function(request, response) { formattedPhoneShortCode = formattedPhoneShortCode.slice(0, 3) + " " + formattedPhoneShortCode.slice(3); console.log('\n\n%%%%%%%%%\n\n'); - console.log('TWilio \n'); - + console.log('TWilio'); + console.log('\n\n%%%%%%%%%\n\n'); //TODO send shortcode from twilio - twilio.sendSMS({ + twilio.sendMessage({ From: "+15873170710", To: user.get("phoneNumber"), Body: "Thanks for using OneTap! Your code is " + formattedPhoneShortCode - }).then( - function(httpResponse) { + }, { + success: function(httpResponse) { response.success(); }, - function(httpResponse) { + error: function(httpResponse) { response.error("unable to send shortcode from twilio: " + httpResponse); } - ); - console.log('\n\n%%%%%%%%%\n\n'); + }); }, function(myObject, error) { From da01dac67b848a1258b3531875abb707d404d9d2 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Tue, 24 Jan 2017 14:11:33 -0800 Subject: [PATCH 37/44] Twilio promise format --- cloud/User.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cloud/User.js b/cloud/User.js index f139e12d1e..f97ab2f617 100644 --- a/cloud/User.js +++ b/cloud/User.js @@ -292,14 +292,14 @@ Parse.Cloud.define("sendPhoneShortCode", function(request, response) { From: "+15873170710", To: user.get("phoneNumber"), Body: "Thanks for using OneTap! Your code is " + formattedPhoneShortCode - }, { - success: function(httpResponse) { + }).then( + function(httpResponse) { response.success(); }, - error: function(httpResponse) { + function(httpResponse) { response.error("unable to send shortcode from twilio: " + httpResponse); } - }); + ); }, function(myObject, error) { From 1005c272c41c67793e549421aba325e01eeacecb Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Wed, 25 Jan 2017 10:14:06 -0800 Subject: [PATCH 38/44] Updated Save method call in POFriendRelation; removed some debug comments --- cloud/POFriendRelation.js | 18 ++++++++---------- cloud/User.js | 4 ---- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/cloud/POFriendRelation.js b/cloud/POFriendRelation.js index cd4642d725..9276a6f93b 100644 --- a/cloud/POFriendRelation.js +++ b/cloud/POFriendRelation.js @@ -6,21 +6,19 @@ Parse.Cloud.beforeSave("POFriendRelation", function(request, response) { var friendUser = request.object.get("friendUser"); - var saveOptions = { - success: function(user) { - response.success(); - }, - error: function(user, error) { - response.error("Unable to save the user"); - } - } - function addAndRemoveChannels(addedChannel, removedChannel) { request.user.remove("channels", removedChannel); request.user.save({},{ useMasterKey: true }).then( function(user) { request.user.addUnique("channels", addedChannel); - request.user.save(null, saveOptions); + request.user.save(null, { useMasterKey: true }).then( + function(user) { + response.success(); + }, + function(user, error) { + response.error("Unable to save the user"); + } + ); }, function(user, error) { response.error("Unable to save the user"); diff --git a/cloud/User.js b/cloud/User.js index f97ab2f617..76b24fe19f 100644 --- a/cloud/User.js +++ b/cloud/User.js @@ -284,10 +284,6 @@ Parse.Cloud.define("sendPhoneShortCode", function(request, response) { var formattedPhoneShortCode = phoneShortCode.toString() formattedPhoneShortCode = formattedPhoneShortCode.slice(0, 3) + " " + formattedPhoneShortCode.slice(3); - console.log('\n\n%%%%%%%%%\n\n'); - console.log('TWilio'); - console.log('\n\n%%%%%%%%%\n\n'); - //TODO send shortcode from twilio twilio.sendMessage({ From: "+15873170710", To: user.get("phoneNumber"), From e13ff23c29b538c06be1edb36f07d3ae8835fe4f Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Wed, 25 Jan 2017 10:20:10 -0800 Subject: [PATCH 39/44] masterKey on destroy method calls for Friend Requests and for Friend Relations --- cloud/POFriendRelation.js | 4 ++-- cloud/POFriendRequest.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cloud/POFriendRelation.js b/cloud/POFriendRelation.js index 9276a6f93b..68b84a5d4b 100644 --- a/cloud/POFriendRelation.js +++ b/cloud/POFriendRelation.js @@ -85,7 +85,7 @@ Parse.Cloud.afterSave("POFriendRelation", function(request) { function(results) { if (results.length > 0) { for (var i = 0; i < results.length; i++) { - results[i].destroy(); + results[i].destroy({ useMasterKey: true }); } } @@ -96,7 +96,7 @@ Parse.Cloud.afterSave("POFriendRelation", function(request) { function(results) { if (results.length > 0) { for (var i = 0; i < results.length; i++) { - results[i].destroy(); + results[i].destroy({ useMasterKey: true }); } } }, diff --git a/cloud/POFriendRequest.js b/cloud/POFriendRequest.js index cb20e11594..cf2b2ec8e7 100644 --- a/cloud/POFriendRequest.js +++ b/cloud/POFriendRequest.js @@ -99,7 +99,7 @@ Parse.Cloud.afterDelete("POFriendRequest", function(request) { queryInverseFriendRequest.find({ useMasterKey: true }).then( function(results) { - Parse.Object.destroyAll().then( + Parse.Object.destroyAll({ useMasterKey: true }).then( function() {}, function(error) { console.error("Error deleting inverse friend relations " + error.code + ": " + error.message); From 2d4552f96535331849e1ff8a1e8a87e26dd82b99 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Wed, 25 Jan 2017 10:56:46 -0800 Subject: [PATCH 40/44] added a success reponse to sendPush method --- cloud/PushNotifications.js | 1 + 1 file changed, 1 insertion(+) diff --git a/cloud/PushNotifications.js b/cloud/PushNotifications.js index 8b9d117194..0c41c8e264 100644 --- a/cloud/PushNotifications.js +++ b/cloud/PushNotifications.js @@ -52,6 +52,7 @@ function sendPush(query, data, callbackCounter) { }, { useMasterKey: true }).then( function(){ // console.log('Push sent!'); + response.success(); }, function(error) { // error console.error("Got an error " + error.code + " : " + error.message); } From 5b800fef3dce80b9d477ab8516cc2b9e3b30728e Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Wed, 25 Jan 2017 11:20:39 -0800 Subject: [PATCH 41/44] debugging for multi push notifications --- cloud/POFriendRequest.js | 3 ++- cloud/PushNotifications.js | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cloud/POFriendRequest.js b/cloud/POFriendRequest.js index cf2b2ec8e7..efb717db53 100644 --- a/cloud/POFriendRequest.js +++ b/cloud/POFriendRequest.js @@ -122,8 +122,9 @@ Parse.Cloud.define("requestedFriend", function(request, response) { userId: request.user.id, userName: request.user.get("displayName") }; + console.log('\n\n %%%%%%%%%%% SEND FRIEND PUSH NOTIF %%%%%%%%%%%% \n\n'); PushNotifications.sendAndroidPush(channels, "ca.appcolony.distracteddriver.FRIEND_REQUEST", androidPushData, pushCallbackCounter); - + console.log('\n\n %%%%%%%%%%% git %%%%%%%%%%%% \n\n'); // var alert = { // "loc-key": "notification-friend-request", // "loc-args": [request.user.get("displayName")] diff --git a/cloud/PushNotifications.js b/cloud/PushNotifications.js index 0c41c8e264..6fd4cf3f16 100644 --- a/cloud/PushNotifications.js +++ b/cloud/PushNotifications.js @@ -10,8 +10,9 @@ exports.sendAndroidPush = function(channels, action, data, callbackCounter) { pushData[key] = data[key]; }; } - + console.log('\n\n %%%%%%%%%%% SEND ANDROID PUSH NOTIF %%%%%%%%%%%% \n\n'); sendPush(installationQuery, pushData, callbackCounter); + console.log('\n\n %%%%%%%%%%% %%%%%%%%%%%% \n\n'); } exports.sendIOSPush = function(channels, alert, contentAvailable, category, data, callbackCounter) { @@ -51,7 +52,9 @@ function sendPush(query, data, callbackCounter) { data: data }, { useMasterKey: true }).then( function(){ - // console.log('Push sent!'); + console.log('\n\n %%%%%%%%%%% SEND PUSH NOTIF %%%%%%%%%%%% \n\n'); + console.log('Push sent!'); + console.log('\n\n %%%%%%%%%%% %%%%%%%%%%%% \n\n'); response.success(); }, function(error) { // error console.error("Got an error " + error.code + " : " + error.message); From e77cc18d813d2b0179dff0204bde768265833457 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Wed, 25 Jan 2017 11:52:01 -0800 Subject: [PATCH 42/44] Push notif callbackCounter readded --- cloud/PushNotifications.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cloud/PushNotifications.js b/cloud/PushNotifications.js index 6fd4cf3f16..c882f690da 100644 --- a/cloud/PushNotifications.js +++ b/cloud/PushNotifications.js @@ -52,12 +52,9 @@ function sendPush(query, data, callbackCounter) { data: data }, { useMasterKey: true }).then( function(){ - console.log('\n\n %%%%%%%%%%% SEND PUSH NOTIF %%%%%%%%%%%% \n\n'); - console.log('Push sent!'); - console.log('\n\n %%%%%%%%%%% %%%%%%%%%%%% \n\n'); - response.success(); + callbackCounter.success(); }, function(error) { // error - console.error("Got an error " + error.code + " : " + error.message); + callbackCounter.error(error); } ); } From 277b46863a0119adce5b6f0c53ac2b3e508dcf84 Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Wed, 25 Jan 2017 12:23:18 -0800 Subject: [PATCH 43/44] Added MasterKey to userTotals find() method call; removed debug comments --- cloud/POFriendRequest.js | 4 ++-- cloud/PushNotifications.js | 2 -- cloud/Totals.js | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/cloud/POFriendRequest.js b/cloud/POFriendRequest.js index efb717db53..e37df37f7a 100644 --- a/cloud/POFriendRequest.js +++ b/cloud/POFriendRequest.js @@ -122,9 +122,9 @@ Parse.Cloud.define("requestedFriend", function(request, response) { userId: request.user.id, userName: request.user.get("displayName") }; - console.log('\n\n %%%%%%%%%%% SEND FRIEND PUSH NOTIF %%%%%%%%%%%% \n\n'); + PushNotifications.sendAndroidPush(channels, "ca.appcolony.distracteddriver.FRIEND_REQUEST", androidPushData, pushCallbackCounter); - console.log('\n\n %%%%%%%%%%% git %%%%%%%%%%%% \n\n'); + // var alert = { // "loc-key": "notification-friend-request", // "loc-args": [request.user.get("displayName")] diff --git a/cloud/PushNotifications.js b/cloud/PushNotifications.js index c882f690da..3265a8707f 100644 --- a/cloud/PushNotifications.js +++ b/cloud/PushNotifications.js @@ -10,9 +10,7 @@ exports.sendAndroidPush = function(channels, action, data, callbackCounter) { pushData[key] = data[key]; }; } - console.log('\n\n %%%%%%%%%%% SEND ANDROID PUSH NOTIF %%%%%%%%%%%% \n\n'); sendPush(installationQuery, pushData, callbackCounter); - console.log('\n\n %%%%%%%%%%% %%%%%%%%%%%% \n\n'); } exports.sendIOSPush = function(channels, alert, contentAvailable, category, data, callbackCounter) { diff --git a/cloud/Totals.js b/cloud/Totals.js index a14a165f6a..1758aa9573 100644 --- a/cloud/Totals.js +++ b/cloud/Totals.js @@ -106,7 +106,7 @@ exports.getUserTotals = function(userId, callback, failCallback) { id: userId }); totalQuery.equalTo("user", user); - totalQuery.first().then( + totalQuery.first({ useMasterKey: true }).then( function(object) { var userTotals = object; if (!userTotals) { From a3a64c29255e0b2b31461cb33c06150a2b44ea6b Mon Sep 17 00:00:00 2001 From: Nathan Willson Date: Wed, 25 Jan 2017 14:55:29 -0800 Subject: [PATCH 44/44] Mailgun Adapter config --- index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/index.js b/index.js index 0ff6080fff..d6f1ca2898 100644 --- a/index.js +++ b/index.js @@ -27,6 +27,14 @@ var api = new ParseServer({ senderId: process.env.FIREBASE_SENDER_ID || '', // The Sender ID of GCM apiKey: process.env.FIREBASE_SERVER_KEY || '' // The Server API Key of GCM } + }, + emailAdapter: { + module: 'parse-server-simple-mailgun-adapter', + options: { + fromAddress: process.env.MAILGUN_FROM_ADDRESS || '', // The address that your emails come from + domain: process.env.MAILGUN_DOMAIN || '',// Your domain from mailgun.com + apiKey: process.env.MAILGUN_API_KEY || '' // Your API key from mailgun.com + } } }); // Client-keys like the javascript key or the .NET key are not necessary with parse-server