Skip to content

Commit 3cca0bd

Browse files
authored
Merge pull request #7176 from Countly/release-2405-fixes-anna
[compliance-hub] Correctly merge user history on user merge
2 parents 074c302 + 770c4a6 commit 3cca0bd

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Version 24.05.XX
22
Fixes:
33
- [onboarding] Fix redirection to newsletter page
4+
- [compliance-hub] Correctly merge user history on user merge
45

56
Enterprise Fixes:
67
- [retention_segments] Adding null check for breakdown filtering

plugins/compliance-hub/api/api.js

Lines changed: 18 additions & 8 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;
@@ -129,7 +136,7 @@ const FEATURE_NAME = 'compliance_hub';
129136
case 'current': {
130137
if (!params.qstring.app_id) {
131138
common.returnMessage(params, 400, 'Missing parameter "app_id"');
132-
return false;
139+
return true;
133140
}
134141
validateRead(params, FEATURE_NAME, function() {
135142
var query = params.qstring.query || {};
@@ -142,15 +149,15 @@ 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;
149156
}
150157
case 'search': {
151158
if (!params.qstring.app_id) {
152159
common.returnMessage(params, 400, 'Missing parameter "app_id"');
153-
return false;
160+
return true;
154161
}
155162
validateRead(params, FEATURE_NAME, function() {
156163
var query = params.qstring.query || {};
@@ -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
}
@@ -271,7 +279,7 @@ const FEATURE_NAME = 'compliance_hub';
271279
case 'consents': {
272280
if (!params.qstring.app_id) {
273281
common.returnMessage(params, 400, 'Missing parameter "app_id"');
274-
return false;
282+
return true;
275283
}
276284
validateRead(params, FEATURE_NAME, function() {
277285
appUsers.count(params.qstring.app_id, {}, function(err, total) {
@@ -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({app_id: ob.app_id, uid: oldUid}, {'$set': { 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
}

0 commit comments

Comments
 (0)