From d6eade2f7528cecaa875971cf40bd2c6ea797a2f Mon Sep 17 00:00:00 2001 From: nathangray Date: Fri, 4 Sep 2020 09:37:07 -0600 Subject: [PATCH] Filter push updates for CRM entries on all linked contacts, not just primary --- addressbook/js/CRM.js | 36 ++++++++++++++++++----- addressbook/js/CRM.ts | 39 +++++++++++++++++++++---- infolog/inc/class.infolog_hooks.inc.php | 17 +++++++++-- 3 files changed, 77 insertions(+), 15 deletions(-) diff --git a/addressbook/js/CRM.js b/addressbook/js/CRM.js index f814dd6efc..3922e2f01f 100644 --- a/addressbook/js/CRM.js +++ b/addressbook/js/CRM.js @@ -30,6 +30,7 @@ require("jqueryui"); require("../jsapi/egw_global"); require("../etemplate/et2_types"); var egw_app_1 = require("../../api/js/jsapi/egw_app"); +var et2_extension_nextmatch_1 = require("../../api/js/etemplate/et2_extension_nextmatch"); /** * UI for Addressbook CRM view * @@ -51,7 +52,7 @@ var CRMView = /** @class */ (function (_super) { _this.contact_ids = []; // Private js for the list _this.app_obj = null; - // Push data key(s) to check for our contact ID + // Push data key(s) to check for our contact ID in the entry's ACL data _this.push_contact_ids = ["contact_id"]; return _this; } @@ -144,25 +145,46 @@ var CRMView = /** @class */ (function (_super) { * @param {number} pushData.account_id User that caused the notification */ CRMView.prototype.push = function (pushData) { - var _this = this; if (pushData.app !== this.app_obj.appname || !this.nm) return; // If we know about it and it's an update, just update. // This must be before all ACL checks, as contact might have changed and entry needs to be removed - // (server responds then with null / no entry causing the entry to disapear) + // (server responds then with null / no entry causing the entry to disappear) if (pushData.type !== "add" && this.egw.dataHasUID(this.uid(pushData))) { - return this.nm.refresh(pushData.id, pushData.type); + // Check to see if it's in OUR nextmatch + var uid_1 = this.uid(pushData); + var known = Object.values(this.nm.controller._indexMap).filter(function (row) { return row.uid == uid_1; }); + var type = pushData.type; + if (known && known.length > 0) { + if (!this.id_check(pushData.acl)) { + // Was ours, not anymore, and we know this now - no server needed. Just remove from nm. + type = et2_extension_nextmatch_1.et2_nextmatch.DELETE; + } + return this.nm.refresh(pushData.id, type); + } } + if (this.id_check(pushData.acl)) { + return this._app_obj_push(pushData); + } + }; + /** + * Check to see if the given entry is "ours" + * + * @param entry + */ + CRMView.prototype.id_check = function (entry) { + var _this = this; // Check if it's for one of our contacts for (var _i = 0, _a = this.push_contact_ids; _i < _a.length; _i++) { var field = _a[_i]; - if (pushData.acl && pushData.acl[field]) { - var val = typeof pushData.acl[field] == "string" ? [pushData.acl[field]] : pushData.acl[field]; + if (entry && entry[field]) { + var val = typeof entry[field] == "string" ? [entry[field]] : entry[field]; if (val.filter(function (v) { return _this.contact_ids.indexOf(v) >= 0; }).length > 0) { - return this._app_obj_push(pushData); + return true; } } } + return false; }; /** * Override the list's push handler to do nothing, we'll call it if we want it. diff --git a/addressbook/js/CRM.ts b/addressbook/js/CRM.ts index 95c002e9ac..45d90fb32e 100644 --- a/addressbook/js/CRM.ts +++ b/addressbook/js/CRM.ts @@ -39,7 +39,7 @@ export class CRMView extends EgwApp // Hold on to the original push handler private _app_obj_push: (pushData: PushData) => void; - // Push data key(s) to check for our contact ID + // Push data key(s) to check for our contact ID in the entry's ACL data private push_contact_ids = ["contact_id"]; /** @@ -172,24 +172,51 @@ export class CRMView extends EgwApp // If we know about it and it's an update, just update. // This must be before all ACL checks, as contact might have changed and entry needs to be removed - // (server responds then with null / no entry causing the entry to disapear) + // (server responds then with null / no entry causing the entry to disappear) if (pushData.type !== "add" && this.egw.dataHasUID(this.uid(pushData))) { - return this.nm.refresh(pushData.id, pushData.type); + // Check to see if it's in OUR nextmatch + let uid = this.uid(pushData); + let known = Object.values(this.nm.controller._indexMap).filter(function(row) {return row.uid ==uid;}); + let type = pushData.type; + if(known && known.length > 0) + { + if(!this.id_check(pushData.acl)) + { + // Was ours, not anymore, and we know this now - no server needed. Just remove from nm. + type = et2_nextmatch.DELETE; + } + return this.nm.refresh(pushData.id, type); + } } + if(this.id_check(pushData.acl)) + { + return this._app_obj_push(pushData); + } + + } + + /** + * Check to see if the given entry is "ours" + * + * @param entry + */ + id_check(entry) : boolean + { // Check if it's for one of our contacts for(let field of this.push_contact_ids) { - if(pushData.acl && pushData.acl[field]) + if(entry && entry[field]) { - let val = typeof pushData.acl[field] == "string" ? [pushData.acl[field]] : pushData.acl[field]; + let val = typeof entry[field] == "string" ? [entry[field]] : entry[field]; if(val.filter(v => this.contact_ids.indexOf(v) >= 0).length > 0) { - return this._app_obj_push(pushData); + return true; } } } + return false; } /** diff --git a/infolog/inc/class.infolog_hooks.inc.php b/infolog/inc/class.infolog_hooks.inc.php index cf9636f37d..02aa0c94ae 100644 --- a/infolog/inc/class.infolog_hooks.inc.php +++ b/infolog/inc/class.infolog_hooks.inc.php @@ -89,10 +89,23 @@ class infolog_hooks { $info = array_intersect_key($entry, array_flip(['info_type', 'info_owner','info_responsible', 'info_modified'])); - // Add in contact ID for CRM view + // Add in contact IDs for CRM view if($entry['info_contact'] && $entry['info_contact']['app'] == 'addressbook') { - $info['contact_id'] = $entry['info_contact']['id']; + $info['contact_id'] = [$entry['info_contact']['id']]; + } + foreach(Api\Link::get_links('infolog',$entry['info_id'],'addressbook') as $link) + { + if(!is_array($info['contact_id'])) + { + $info['contact_id'] = []; + } + // Skip if already there + if(in_array($link,$info['contact_id'])) + { + continue; + } + $info['contact_id'][] = $link; } return $info; }