mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-08-05 03:52:14 +00:00
Revert "Added Conditional Semantics to group member query to always include the user."
This commit is contained in:
parent
ecaa1d31ac
commit
e9baafcbc8
1 changed files with 7 additions and 10 deletions
|
|
@ -30,16 +30,13 @@ 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
|
* limited fields - and only a sampling of the members, beacuse they can be in the thousands
|
||||||
* @param type: 'party' or otherwise
|
* @param type: 'party' or otherwise
|
||||||
* @param q: the Mongoose query we're building up
|
* @param q: the Mongoose query we're building up
|
||||||
* @param additionalFields: if we want to populate some additional field not fetched normally
|
* @param additionalFields: if we want to populate some additional field not fetched normally
|
||||||
* pass it as a string, parties only
|
* pass it as a string, parties only
|
||||||
*/
|
*/
|
||||||
var populateQuery = function(type, q, additionalFields, user){
|
var populateQuery = function(type, q, additionalFields){
|
||||||
if (type == 'party')
|
if (type == 'party')
|
||||||
q.populate('members', partyFields + (additionalFields ? (' ' + additionalFields) : ''));
|
q.populate('members', partyFields + (additionalFields ? (' ' + additionalFields) : ''));
|
||||||
else
|
else
|
||||||
if ( user )
|
|
||||||
//Use Conditional Semantics to always include the user
|
|
||||||
guildPopulate.match = {"_id": { "$ne" : null, "$in": [user._id] } };
|
|
||||||
q.populate(guildPopulate);
|
q.populate(guildPopulate);
|
||||||
q.populate('invites', nameFields);
|
q.populate('invites', nameFields);
|
||||||
q.populate({
|
q.populate({
|
||||||
|
|
@ -135,7 +132,7 @@ api.get = function(req, res, next) {
|
||||||
{_id:gid, privacy:'public'},
|
{_id:gid, privacy:'public'},
|
||||||
{_id:gid, privacy:'private', members: {$in:[user._id]}} // if the group is private, only return if they have access
|
{_id:gid, privacy:'private', members: {$in:[user._id]}} // if the group is private, only return if they have access
|
||||||
]});
|
]});
|
||||||
populateQuery(gid, q, null, user);
|
populateQuery(gid, q);
|
||||||
q.exec(function(err, group){
|
q.exec(function(err, group){
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
if (!group && gid!=='party') return res.json(404,{err: "Group not found or you don't have access."});
|
if (!group && gid!=='party') return res.json(404,{err: "Group not found or you don't have access."});
|
||||||
|
|
@ -308,7 +305,7 @@ api.flagChatMessage = function(req, res, next){
|
||||||
group.save(function(err,_saved){
|
group.save(function(err,_saved){
|
||||||
if(err) return next(err);
|
if(err) return next(err);
|
||||||
var addressesToSendTo = JSON.parse(nconf.get('FLAG_REPORT_EMAIL'));
|
var addressesToSendTo = JSON.parse(nconf.get('FLAG_REPORT_EMAIL'));
|
||||||
|
|
||||||
if(Array.isArray(addressesToSendTo)){
|
if(Array.isArray(addressesToSendTo)){
|
||||||
addressesToSendTo = addressesToSendTo.map(function(email){
|
addressesToSendTo = addressesToSendTo.map(function(email){
|
||||||
return {email: email, canSend: true}
|
return {email: email, canSend: true}
|
||||||
|
|
@ -361,7 +358,7 @@ api.clearFlagCount = function(req, res, next){
|
||||||
}else{
|
}else{
|
||||||
return res.json(401, {err: "Only an admin can clear the flag count!"})
|
return res.json(401, {err: "Only an admin can clear the flag count!"})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
api.seenMessage = function(req,res,next){
|
api.seenMessage = function(req,res,next){
|
||||||
|
|
@ -580,7 +577,7 @@ var inviteByUUIDs = function(uuids, group, req, res, next){
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, function(err){
|
}, function(err){
|
||||||
if(err) return err.code ? res.json(err.code, {err: err.err}) : next(err);
|
if(err) return err.code ? res.json(err.code, {err: err.err}) : next(err);
|
||||||
|
|
||||||
|
|
@ -641,7 +638,7 @@ var inviteByEmails = function(invites, group, req, res, next){
|
||||||
inviteByUUIDs(usersAlreadyRegistered, group, req, res, next);
|
inviteByUUIDs(usersAlreadyRegistered, group, req, res, next);
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
// Send only status code down the line because it doesn't need
|
// Send only status code down the line because it doesn't need
|
||||||
// info on invited users since they are not yet registered
|
// info on invited users since they are not yet registered
|
||||||
res.send(200);
|
res.send(200);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue