Skip to content

Commit 6b66ab3

Browse files
authored
Merge pull request #6719 from Countly/deletion-manager
feat: [WIP] Integration deletion manager into plugins
2 parents 1da18c7 + e1df1bd commit 6b66ab3

File tree

6 files changed

+103
-98
lines changed

6 files changed

+103
-98
lines changed

api/jobs/deletionManagerJob.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ class DeletionManagerJob extends Job {
3131
};
3232
}
3333

34+
/**
35+
* Get concurrency for the job - do not allow run in parallel
36+
* @returns {number} Concurrency level
37+
*/
38+
getConcurrency() {
39+
return 1;
40+
}
41+
3442
/**
3543
* Run the job
3644
* @param {done} done callback

api/parts/mgmt/app_users.js

Lines changed: 46 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -289,60 +289,57 @@ usersApi.delete = function(app_id, query, params, callback) {
289289
}
290290

291291
//remove from drill_events
292+
plugins.dispatch("/core/delete_granular_data", {
293+
db: "drill",
294+
collection: "drill_events",
295+
query: { a: app_id + "", uid: { $in: res[0].uid } }
296+
});
292297

293-
common.drillDb.collection('drill_events').remove({"a": (app_id + ""), uid: {$in: res[0].uid}}, function(err1) {
294-
if (err1) {
295-
log.e("Failed to delete data from drill_events collection", err1);
296-
common.returnMessage(params, 500, { errorMessage: "User deletion failed. Failed to delete some data related to this user." });
297-
return;
298-
299-
}
300-
common.db.collection("app_users" + app_id).remove({uid: {$in: res[0].uid}}, function(err) {
301-
if (res[0].exported) {
302-
//delete exports if exist
303-
for (let i = 0;i < res[0].exported.length; i++) {
304-
let id = res[0].exported[i].split("/");
305-
id = id[id.length - 1]; //last one is filename
306-
id = id.substr(id.length - 7);
307-
308-
deleteMyExport(id).then(
309-
function() {},
310-
function(err5) {
311-
console.log(err5);
312-
}
313-
);
314-
}
315-
}
316-
//deleting userimages(if they exist);
317-
if (res[0].picture) {
318-
for (let i = 0;i < res[0].picture.length; i++) {
319-
//remove /userimages/
320-
let id = res[0].picture[i].substr(12, res[0].picture[i].length - 12);
321-
var pp = path.resolve(__dirname, './../../../frontend/express/public/userimages/' + id);
322-
countlyFs.deleteFile("userimages", pp, {id: id}, function(err6) {
323-
if (err6) {
324-
console.log(err6);
325-
}
326-
});
327-
}
298+
common.db.collection("app_users" + app_id).remove({uid: {$in: res[0].uid}}, function(err) {
299+
if (res[0].exported) {
300+
//delete exports if exist
301+
for (let i = 0;i < res[0].exported.length; i++) {
302+
let id = res[0].exported[i].split("/");
303+
id = id[id.length - 1]; //last one is filename
304+
id = id.substr(id.length - 7);
305+
306+
deleteMyExport(id).then(
307+
function() {},
308+
function(err5) {
309+
console.log(err5);
310+
}
311+
);
328312
}
329-
try {
330-
fs.appendFileSync(path.resolve(__dirname, './../../../log/deletedUsers' + app_id + '.txt'), res[0].uid.join("\n") + "\n", "utf-8");
313+
}
314+
//deleting userimages(if they exist);
315+
if (res[0].picture) {
316+
for (let i = 0;i < res[0].picture.length; i++) {
317+
//remove /userimages/
318+
let id = res[0].picture[i].substr(12, res[0].picture[i].length - 12);
319+
var pp = path.resolve(__dirname, './../../../frontend/express/public/userimages/' + id);
320+
countlyFs.deleteFile("userimages", pp, {id: id}, function(err6) {
321+
if (err6) {
322+
console.log(err6);
323+
}
324+
});
331325
}
332-
catch (err2) {
333-
console.log(err2);
326+
}
327+
try {
328+
fs.appendFileSync(path.resolve(__dirname, './../../../log/deletedUsers' + app_id + '.txt'), res[0].uid.join("\n") + "\n", "utf-8");
329+
}
330+
catch (err2) {
331+
console.log(err2);
332+
}
333+
plugins.dispatch("/systemlogs", {
334+
params: params,
335+
action: "app_user_deleted",
336+
data: {
337+
app_id: app_id,
338+
query: JSON.stringify(query),
339+
uids: res[0].uid,
334340
}
335-
plugins.dispatch("/systemlogs", {
336-
params: params,
337-
action: "app_user_deleted",
338-
data: {
339-
app_id: app_id,
340-
query: JSON.stringify(query),
341-
uids: res[0].uid,
342-
}
343-
});
344-
callback(err, res[0].uid);
345341
});
342+
callback(err, res[0].uid);
346343
});
347344
});
348345
});

plugins/compliance-hub/api/api.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
var plugin = {},
2-
crypto = require('crypto'),
32
common = require('../../../api/utils/common.js'),
43
countlyCommon = require('../../../api/lib/countly.common.js'),
54
appUsers = require('../../../api/parts/mgmt/app_users.js'),
@@ -368,35 +367,35 @@ const FEATURE_NAME = 'compliance_hub';
368367
var appId = ob.appId;
369368
common.db.collection('consents').remove({'_id': {$regex: appId + ".*"}}, function() {});
370369
common.db.collection('consent_history').drop(function() {});
371-
if (common.drillDb) {
370+
/*if (common.drillDb) {
372371
common.drillDb.collection("drill_events" + crypto.createHash('sha1').update("[CLY]_consent" + appId).digest('hex')).drop(function() {});
373-
}
372+
}*/
374373
});
375374

376375
plugins.register("/i/apps/reset", function(ob) {
377376
var appId = ob.appId;
378377
common.db.collection('consents').remove({'_id': {$regex: appId + ".*"}}, function() {});
379378
common.db.collection('consent_history').drop(function() {});
380-
if (common.drillDb) {
379+
/*if (common.drillDb) {
381380
common.drillDb.collection("drill_events" + crypto.createHash('sha1').update("[CLY]_consent" + appId).digest('hex')).drop(function() {});
382-
}
381+
}*/
383382
});
384383

385384
plugins.register("/i/apps/clear_all", function(ob) {
386385
var appId = ob.appId;
387386
common.db.collection('consents').remove({'_id': {$regex: appId + ".*"}}, function() {});
388-
if (common.drillDb) {
387+
/*if (common.drillDb) {
389388
common.drillDb.collection("drill_events" + crypto.createHash('sha1').update("[CLY]_consent" + appId).digest('hex')).drop(function() {});
390-
}
389+
}*/
391390
});
392391

393392
plugins.register("/i/apps/clear", function(ob) {
394393
var appId = ob.appId;
395394
var ids = ob.ids;
396395
common.db.collection('consents').remove({$and: [{'_id': {$regex: appId + ".*"}}, {'_id': {$nin: ids}}]}, function() {});
397-
if (common.drillDb) {
396+
/*if (common.drillDb) {
398397
common.drillDb.collection("drill_events" + crypto.createHash('sha1').update("[CLY]_consent" + appId).digest('hex')).remove({ts: {$lt: ob.moment.valueOf()}}, function() {});
399-
}
398+
}*/
400399
});
401400
}(plugin));
402401

plugins/crashes/api/api.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,11 @@ plugins.setConfigs("crashes", {
16531653
common.db.collection('app_crashgroups' + params.qstring.app_id).remove({'_id': group._id }, function() {
16541654
if (common.drillDb) {
16551655
common.drillDb.collection("drill_events" + crypto.createHash('sha1').update("[CLY]_crash" + params.qstring.app_id).digest('hex')).remove({"sg.crash": group._id}, function() {});
1656-
common.drillDb.collection("drill_events").remove({"a": params.qstring.app_id + "", e: "[CLY]_crash", "sg.crash": group._id}, function() {});
1656+
plugins.dispatch("/core/delete_granular_data", {
1657+
db: "drill",
1658+
collection: "drill_events",
1659+
query: { a: params.qstring.app_id + "", e: "[CLY]_crash", "n": group._id + "" }
1660+
});
16571661
plugins.dispatch("/crash/delete", {appId: params.qstring.app_id, crash: group._id + ""});
16581662
}
16591663
var id = common.crypto.createHash('sha1').update(params.qstring.app_id + group._id + "").digest('hex');
@@ -1806,21 +1810,21 @@ plugins.setConfigs("crashes", {
18061810
common.db.collection('app_crashes' + appId).drop(function() {});
18071811
common.db.collection('crash_share').remove({'app_id': appId }, function() {});
18081812
common.db.collection('crashdata').remove({'_id': {$regex: appId + ".*"}}, function() {});
1809-
if (common.drillDb) {
1813+
/*if (common.drillDb) {
18101814
common.drillDb.collection("drill_events" + crypto.createHash('sha1').update("[CLY]_crash" + appId).digest('hex')).drop(function() {});
18111815
common.drillDb.collection("drill_events").remove({"a": appId + "", e: "[CLY]_crash"}, function() {});
1812-
}
1816+
}*/
18131817
});
18141818

18151819
plugins.register("/i/apps/clear", function(ob) {
18161820
var appId = ob.appId;
18171821
var ids = ob.ids;
18181822
common.db.collection('crashdata').remove({$and: [{'_id': {$regex: appId + ".*"}}, {'_id': {$nin: ids}}]}, function() {});
18191823
common.db.collection('app_crashes' + appId).remove({ts: {$lt: ob.moment.unix()}}, function() {});
1820-
if (common.drillDb) {
1824+
/*if (common.drillDb) {
18211825
common.drillDb.collection("drill_events" + crypto.createHash('sha1').update("[CLY]_crash" + appId).digest('hex')).remove({ts: {$lt: ob.moment.valueOf()}}, function() {});
18221826
common.drillDb.collection("drill_events").remove({a: appId + "", e: "[CLY]_crash", ts: {$lt: ob.moment.valueOf()}}, function() {});
1823-
}
1827+
}*/
18241828
});
18251829

18261830
plugins.register("/i/apps/clear_all", function(ob) {
@@ -1850,10 +1854,10 @@ plugins.setConfigs("crashes", {
18501854
});
18511855
common.db.collection('crash_share').remove({'app_id': appId }, function() {});
18521856
common.db.collection('crashdata').remove({'_id': {$regex: appId + ".*"}}, function() {});
1853-
if (common.drillDb) {
1857+
/*if (common.drillDb) {
18541858
common.drillDb.collection("drill_events" + crypto.createHash('sha1').update("[CLY]_crash" + appId).digest('hex')).drop(function() {});
18551859
common.drillDb.collection("drill_events").remove({"a": appId + "", e: "[CLY]_crash"}, function() {});
1856-
}
1860+
}*/
18571861
});
18581862

18591863
plugins.register("/i/apps/reset", function(ob) {
@@ -1883,10 +1887,10 @@ plugins.setConfigs("crashes", {
18831887
});
18841888
common.db.collection('crash_share').remove({'app_id': appId }, function() {});
18851889
common.db.collection('crashdata').remove({'_id': {$regex: appId + ".*"}}, function() {});
1886-
if (common.drillDb) {
1887-
common.drillDb.collection("drill_events" + crypto.createHash('sha1').update("[CLY]_crash" + appId).digest('hex')).drop(function() {});
1888-
common.drillDb.collection("drill_events").remove({"a": appId + "", e: "[CLY]_crash"}, function() {});
1889-
}
1890+
/*if (common.drillDb) {
1891+
common.drillDb.collection("drill_events" + crypto.createHash('sha1').update("[CLY]_crash" + appId).digest('hex')).drop(function() {});
1892+
common.drillDb.collection("drill_events").remove({"a": appId + "", e: "[CLY]_crash"}, function() {});
1893+
}*/
18901894
});
18911895
}(plugin));
18921896

plugins/star-rating/api/api.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,9 +1656,9 @@ function uploadFile(myfile, id, callback) {
16561656
});
16571657
common.db.collection('feedback' + appId).drop(function() {});
16581658
common.db.collection("events" + crypto.createHash('sha1').update("[CLY]_star_rating" + appId).digest('hex')).drop(function() {});
1659-
if (common.drillDb) {
1659+
/*if (common.drillDb) {
16601660
common.drillDb.collection("drill_events" + crypto.createHash('sha1').update("[CLY]_star_rating" + appId).digest('hex')).drop(function() {});
1661-
}
1661+
}*/
16621662
});
16631663
plugins.register("/i/apps/clear", function(ob) {
16641664
var appId = ob.appId;
@@ -1672,13 +1672,13 @@ function uploadFile(myfile, id, callback) {
16721672
$lt: ob.moment.unix()
16731673
}
16741674
}, function() {});
1675-
if (common.drillDb) {
1675+
/*if (common.drillDb) {
16761676
common.drillDb.collection("drill_events" + crypto.createHash('sha1').update("[CLY]_star_rating" + appId).digest('hex')).remove({
16771677
ts: {
16781678
$lt: ob.moment.unix()
16791679
}
16801680
}, function() {});
1681-
}
1681+
}*/
16821682
});
16831683
plugins.register("/i/apps/clear_all", function(ob) {
16841684
var appId = ob.appId;
@@ -1694,9 +1694,9 @@ function uploadFile(myfile, id, callback) {
16941694
}, () => {});
16951695
});
16961696
common.db.collection("events" + crypto.createHash('sha1').update("[CLY]_star_rating" + appId).digest('hex')).drop(function() {});
1697-
if (common.drillDb) {
1697+
/*if (common.drillDb) {
16981698
common.drillDb.collection("drill_events" + crypto.createHash('sha1').update("[CLY]_star_rating" + appId).digest('hex')).drop(function() {});
1699-
}
1699+
}*/
17001700
});
17011701
plugins.register("/i/apps/reset", function(ob) {
17021702
var appId = ob.appId;
@@ -1716,9 +1716,9 @@ function uploadFile(myfile, id, callback) {
17161716
}, () => {});
17171717
});
17181718
common.db.collection("events" + crypto.createHash('sha1').update("[CLY]_star_rating" + appId).digest('hex')).drop(function() {});
1719-
if (common.drillDb) {
1719+
/*if (common.drillDb) {
17201720
common.drillDb.collection("drill_events" + crypto.createHash('sha1').update("[CLY]_star_rating" + appId).digest('hex')).drop(function() {});
1721-
}
1721+
}*/
17221722
});
17231723
plugins.register("/i/device_id", function(ob) {
17241724
var appId = ob.app_id;

0 commit comments

Comments
 (0)