mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-26 16:48:49 +01:00
Filter push updates for CRM entries on all linked contacts, not just primary
This commit is contained in:
parent
e49529f271
commit
d6eade2f75
@ -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.
|
||||
|
@ -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,25 +172,52 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if it's for one of our contacts
|
||||
for(let field of this.push_contact_ids)
|
||||
{
|
||||
if(pushData.acl && pushData.acl[field])
|
||||
{
|
||||
let val = typeof pushData.acl[field] == "string" ? [pushData.acl[field]] : pushData.acl[field];
|
||||
if(val.filter(v => this.contact_ids.indexOf(v) >= 0).length > 0)
|
||||
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(entry && entry[field])
|
||||
{
|
||||
let val = typeof entry[field] == "string" ? [entry[field]] : entry[field];
|
||||
if(val.filter(v => this.contact_ids.indexOf(v) >= 0).length > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the list's push handler to do nothing, we'll call it if we want it.
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user