Skip to content

Commit 0e444e7

Browse files
committed
Consent fixes
1 parent 188a7c2 commit 0e444e7

File tree

2 files changed

+15
-37
lines changed

2 files changed

+15
-37
lines changed

plugins/compliance-hub/api/api.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ const FEATURE_NAME = 'compliance_hub';
1616

1717
plugins.internalDrillEvents.push("[CLY]_consent");
1818

19+
plugins.register("/master", function() {
20+
common.db.collection('consent_history').ensureIndex({app_id: 1, device_id: 1}, function() {});
21+
common.db.collection('consent_history').ensureIndex({app_id: 1, uid: 1}, function() {});
22+
common.db.collection('consent_history').ensureIndex({app_id: 1, type: 1}, function() {});
23+
common.db.collection('consent_history').ensureIndex({app_id: 1, ts: 1}, function() {});
24+
});
25+
1926
//write api call
2027
plugins.register("/sdk/user_properties", function(ob) {
2128
var params = ob.params;
@@ -142,7 +149,7 @@ const FEATURE_NAME = 'compliance_hub';
142149
}
143150
}
144151
common.db.collection("app_users" + params.qstring.app_id).findOne(query, function(err, res) {
145-
common.returnOutput(params, res.consent || {});
152+
common.returnOutput(params, res?.consent || {});
146153
});
147154
});
148155
break;
@@ -162,7 +169,8 @@ const FEATURE_NAME = 'compliance_hub';
162169
query = {};
163170
}
164171
}
165-
common.db.collection("consent_history").count(query, function(err, total) {
172+
query.app_id = params.app_id.toString();
173+
common.db.collection("consent_history").countDocuments(query, function(err, total) {
166174
if (err) {
167175
common.returnMessage(params, 400, err);
168176
}
@@ -338,7 +346,7 @@ const FEATURE_NAME = 'compliance_hub';
338346
var newUid = ob.newUser.uid;
339347
if (oldUid !== newUid) {
340348
return new Promise(function(resolve, reject) {
341-
common.db.collection('consent_history').update({uid: oldUid}, {'$set': {uid: newUid}}, {multi: true}, function(err) {
349+
common.db.collection('consent_history').update({uid: oldUid}, {'$set': {app_id: ob.app_id, uid: newUid}}, {multi: true}, function(err) {
342350
if (err) {
343351
reject(err);
344352
return;
@@ -364,7 +372,7 @@ const FEATURE_NAME = 'compliance_hub';
364372
plugins.register("/i/apps/delete", function(ob) {
365373
var appId = ob.appId;
366374
common.db.collection('consents').remove({'_id': {$regex: appId + ".*"}}, function() {});
367-
common.db.collection('consent_history').drop(function() {});
375+
common.db.collection('consent_history').deleteMany({app_id: appId}, function() {});
368376
if (common.drillDb) {
369377
common.drillDb.collection("drill_events" + crypto.createHash('sha1').update("[CLY]_consent" + appId).digest('hex')).drop(function() {});
370378
}
@@ -373,7 +381,7 @@ const FEATURE_NAME = 'compliance_hub';
373381
plugins.register("/i/apps/reset", function(ob) {
374382
var appId = ob.appId;
375383
common.db.collection('consents').remove({'_id': {$regex: appId + ".*"}}, function() {});
376-
common.db.collection('consent_history').drop(function() {});
384+
common.db.collection('consent_history').deleteMany({app_id: appId}, function() {});
377385
if (common.drillDb) {
378386
common.drillDb.collection("drill_events" + crypto.createHash('sha1').update("[CLY]_consent" + appId).digest('hex')).drop(function() {});
379387
}
@@ -382,6 +390,7 @@ const FEATURE_NAME = 'compliance_hub';
382390
plugins.register("/i/apps/clear_all", function(ob) {
383391
var appId = ob.appId;
384392
common.db.collection('consents').remove({'_id': {$regex: appId + ".*"}}, function() {});
393+
common.db.collection('consent_history').deleteMany({app_id: appId}, function() {});
385394
if (common.drillDb) {
386395
common.drillDb.collection("drill_events" + crypto.createHash('sha1').update("[CLY]_consent" + appId).digest('hex')).drop(function() {});
387396
}
@@ -391,6 +400,7 @@ const FEATURE_NAME = 'compliance_hub';
391400
var appId = ob.appId;
392401
var ids = ob.ids;
393402
common.db.collection('consents').remove({$and: [{'_id': {$regex: appId + ".*"}}, {'_id': {$nin: ids}}]}, function() {});
403+
common.db.collection('consent_history').deleteMany({app_id: appId, ts: {$lt: ob.moment.valueOf()}}, function() {});
394404
if (common.drillDb) {
395405
common.drillDb.collection("drill_events" + crypto.createHash('sha1').update("[CLY]_consent" + appId).digest('hex')).remove({ts: {$lt: ob.moment.valueOf()}}, function() {});
396406
}

plugins/compliance-hub/install.js

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +0,0 @@
1-
var pluginManager = require('../pluginManager.js'),
2-
async = require('async');
3-
4-
console.log("Installing compliance-hub plugin");
5-
pluginManager.dbConnection().then((countlyDb) => {
6-
countlyDb.collection('apps').find({}).toArray(function(err, apps) {
7-
8-
if (!apps || err) {
9-
console.log("No apps to upgrade");
10-
countlyDb.close();
11-
return;
12-
}
13-
function upgrade(app, done) {
14-
console.log("Adding compliance-hub indexes to " + app.name);
15-
var cnt = 0;
16-
function cb() {
17-
cnt++;
18-
if (cnt == 4) {
19-
done();
20-
}
21-
}
22-
countlyDb.collection('consent_history').ensureIndex({device_id: 1}, cb);
23-
countlyDb.collection('consent_history').ensureIndex({uid: 1}, cb);
24-
countlyDb.collection('consent_history').ensureIndex({type: 1}, cb);
25-
countlyDb.collection('consent_history').ensureIndex({ts: 1}, cb);
26-
}
27-
async.forEach(apps, upgrade, function() {
28-
console.log("Compliance hub plugin installation finished");
29-
countlyDb.close();
30-
});
31-
});
32-
});

0 commit comments

Comments
 (0)