mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
delete groups and users from firebase when deleted on habitica
This commit is contained in:
@@ -16,6 +16,7 @@ var logging = require('./../logging');
|
||||
var acceptablePUTPaths;
|
||||
var api = module.exports;
|
||||
var qs = require('qs');
|
||||
var firebase = require('../libs/firebase');
|
||||
var webhook = require('../webhook');
|
||||
|
||||
// api.purchase // Shared.ops
|
||||
@@ -386,6 +387,8 @@ api['delete'] = function(req, res, next) {
|
||||
|
||||
user.remove(function(err){
|
||||
if(err) return next(err);
|
||||
|
||||
firebase.deleteUser(user._id);
|
||||
res.send(200);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,7 +18,6 @@ var api = module.exports = {};
|
||||
|
||||
api.addUserToGroup = function(groupId, userId){
|
||||
if(!isProd) return;
|
||||
|
||||
// TODO is throw ok? we don't have callbacks
|
||||
if(!userId || !groupId) throw new Error('groupId, userId are required.');
|
||||
|
||||
@@ -31,7 +30,6 @@ api.addUserToGroup = function(groupId, userId){
|
||||
|
||||
api.removeUserFromGroup = function(groupId, userId){
|
||||
if(!isProd) return;
|
||||
|
||||
if(!userId || !groupId) throw new Error('groupId, userId are required.');
|
||||
|
||||
firebaseRef.child('members/' + groupId + '/' + userId)
|
||||
@@ -41,4 +39,20 @@ api.removeUserFromGroup = function(groupId, userId){
|
||||
.remove();
|
||||
};
|
||||
|
||||
api.deleteGroup = function(groupId){
|
||||
if(!isProd) return;
|
||||
if(!groupId) throw new Error('groupId is required.');
|
||||
|
||||
firebaseRef.child('members/' + groupId)
|
||||
.remove();
|
||||
};
|
||||
|
||||
api.deleteUser = function(userId){
|
||||
if(!isProd) return;
|
||||
if(!userId) throw new Error('userId is required.');
|
||||
|
||||
firebaseRef.child('users/' + userId)
|
||||
.remove();
|
||||
};
|
||||
|
||||
api.userLeaves
|
||||
@@ -358,6 +358,7 @@ GroupSchema.methods.leave = function(user, keep, mainCb){
|
||||
if(typeof keep !== 'string') keep = 'keep-all'; // can be also 'remove-all'
|
||||
|
||||
var group = this;
|
||||
var groupWasRemoved = false;
|
||||
|
||||
async.parallel([
|
||||
// Remove active quest from user if they're leaving the party
|
||||
@@ -411,6 +412,7 @@ GroupSchema.methods.leave = function(user, keep, mainCb){
|
||||
(group.type === 'guild' && group.privacy === 'private')
|
||||
)){
|
||||
// TODO remove invitations to this group
|
||||
groupWasRemoved = true;
|
||||
Group.remove({
|
||||
_id: group._id
|
||||
}, cb);
|
||||
@@ -449,6 +451,7 @@ GroupSchema.methods.leave = function(user, keep, mainCb){
|
||||
if(err) return mainCb(err);
|
||||
|
||||
firebase.removeUserFromGroup(group._id, user._id);
|
||||
if(groupWasRemoved) firebase.deleteGroup(group._id);
|
||||
return mainCb();
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user