Merge branch 'develop' of github.com:HabitRPG/habitrpg into common-convert
Conflicts: src/controllers/groups.js src/controllers/payments/index.js src/controllers/user.js src/models/user.js
This commit is contained in:
@@ -30,10 +30,12 @@ var guildPopulate = {path: 'members', select: nameFields, options: {limit: 15} }
|
||||
* limited fields - and only a sampling of the members, beacuse they can be in the thousands
|
||||
* @param type: 'party' or otherwise
|
||||
* @param q: the Mongoose query we're building up
|
||||
* @param additionalFields: if we want to populate some additional field not fetched normally
|
||||
* pass it as a string, parties only
|
||||
*/
|
||||
var populateQuery = function(type, q){
|
||||
var populateQuery = function(type, q, additionalFields){
|
||||
if (type == 'party')
|
||||
q.populate('members', partyFields);
|
||||
q.populate('members', partyFields + (additionalFields ? (' ' + additionalFields) : ''));
|
||||
else
|
||||
q.populate(guildPopulate);
|
||||
q.populate('invites', nameFields);
|
||||
@@ -700,7 +702,8 @@ questStart = function(req, res, next) {
|
||||
parallel.push(function(cb2){group.save(cb2)});
|
||||
|
||||
parallel.push(function(cb){
|
||||
populateQuery(group.type, Group.findById(group._id)).exec(cb);
|
||||
// Fetch user.auth to send email, then remove it from data sent to the client
|
||||
populateQuery(group.type, Group.findById(group._id), 'auth.facebook auth.local').exec(cb);
|
||||
});
|
||||
|
||||
async.parallel(parallel,function(err, results){
|
||||
@@ -711,7 +714,25 @@ questStart = function(req, res, next) {
|
||||
|
||||
groupClone.members = results[lastIndex].members;
|
||||
|
||||
// Send quest started email and remove auth information
|
||||
_.each(groupClone.members, function(user){
|
||||
|
||||
if(user.preferences.emailNotifications.questStarted !== false &&
|
||||
user._id !== res.locals.user._id &&
|
||||
group.quest.members[user._id] == true
|
||||
){
|
||||
utils.txnEmail(user, 'quest-started', [
|
||||
{name: 'PARTY_URL', content: nconf.get('BASE_URL') + '/#/options/groups/party'}
|
||||
]);
|
||||
}
|
||||
|
||||
// Remove sensitive data from what is sent to the public
|
||||
user.auth.facebook = undefined;
|
||||
user.auth.local = undefined;
|
||||
});
|
||||
|
||||
group = null;
|
||||
|
||||
return res.json(groupClone);
|
||||
});
|
||||
}
|
||||
@@ -743,12 +764,34 @@ api.questAccept = function(req, res, next) {
|
||||
}
|
||||
});
|
||||
|
||||
User.find({
|
||||
_id: {
|
||||
$in: _.without(group.members, user._id)
|
||||
}
|
||||
}, {auth: 1, preferences: 1, profile: 1}, function(err, members){
|
||||
if(err) return next(err);
|
||||
|
||||
var inviterName = utils.getUserInfo(user, ['name']).name;
|
||||
|
||||
_.each(members, function(member){
|
||||
if(member.preferences.emailNotifications.invitedQuest !== false){
|
||||
utils.txnEmail(member, ('invite-' + (quest.boss ? 'boss' : 'collection') + '-quest'), [
|
||||
{name: 'QUEST_NAME', content: quest.text()},
|
||||
{name: 'INVITER', content: inviterName},
|
||||
{name: 'PARTY_URL', content: nconf.get('BASE_URL') + '/#/options/groups/party'}
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
questStart(req,res,next);
|
||||
});
|
||||
|
||||
// Party member accepting the invitation
|
||||
} else {
|
||||
if (!group.quest.key) return res.json(400,{err:'No quest invitation has been sent out yet.'});
|
||||
group.quest.members[user._id] = true;
|
||||
questStart(req,res,next);
|
||||
}
|
||||
questStart(req,res,next);
|
||||
}
|
||||
|
||||
api.questReject = function(req, res, next) {
|
||||
|
||||
@@ -76,7 +76,7 @@ exports.createSubscription = function(data, cb) {
|
||||
if (data.gift){
|
||||
members.sendMessage(data.user, data.gift.member, data.gift);
|
||||
if(data.gift.member.preferences.emailNotifications.giftedSubscription !== false){
|
||||
utils.txnEmail(member, 'gifted-subscription', [
|
||||
utils.txnEmail(data.gift.member, 'gifted-subscription', [
|
||||
{name: 'GIFTER', content: utils.getUserInfo(data.user, ['name']).name},
|
||||
{name: 'X_MONTHS_SUBSCRIPTION', content: months}
|
||||
]);
|
||||
@@ -121,7 +121,7 @@ exports.buyGems = function(data, cb) {
|
||||
if (data.gift){
|
||||
members.sendMessage(data.user, data.gift.member, data.gift);
|
||||
if(data.gift.member.preferences.emailNotifications.giftedGems !== false){
|
||||
utils.txnEmail(member, 'gifted-gems', [
|
||||
utils.txnEmail(data.gift.member, 'gifted-gems', [
|
||||
{name: 'GIFTER', content: utils.getUserInfo(data.user, ['name']).name},
|
||||
{name: 'X_GEMS_GIFTED', content: data.gift.gems.amount || 20}
|
||||
]);
|
||||
|
||||
@@ -459,7 +459,11 @@ api.sessionPartyInvite = function(req,res,next){
|
||||
.select('invites members').exec(cb);
|
||||
},
|
||||
function(group, cb){
|
||||
if (!group) return cb("Inviter not in party");
|
||||
if (!group){
|
||||
// Don't send error as it will prevent users from using the site
|
||||
delete req.session.partyInvite;
|
||||
return cb();
|
||||
}
|
||||
inv.party = req.session.partyInvite;
|
||||
delete req.session.partyInvite;
|
||||
if (!~group.invites.indexOf(res.locals.user._id))
|
||||
|
||||
Reference in New Issue
Block a user