* Addressbook/Mail: allow to use groups as (readonly) distribution lists

This commit is contained in:
Ralf Becker 2017-01-23 11:16:24 +01:00
parent 29aa1048fe
commit bb7fb1abf8
5 changed files with 104 additions and 18 deletions

View File

@ -1508,8 +1508,8 @@ window.egw_LAB.wait(function() {
{ {
$query['col_filter']['account_id'] = null; $query['col_filter']['account_id'] = null;
} }
// enable/disable distribution lists depending on backend // all backends allow now at least to use groups as distribution lists
$query['no_filter2'] = !$this->lists_available($query['filter']); $query['no_filter2'] = false;
if (isset($this->org_views[(string) $query['org_view']]) && !$query['col_filter']['parent_id']) // we have an org view if (isset($this->org_views[(string) $query['org_view']]) && !$query['col_filter']['parent_id']) // we have an org view
{ {

View File

@ -223,4 +223,20 @@ class Ads extends Ldap
parent::sanitize_update($ldapContact); parent::sanitize_update($ldapContact);
} }
/**
* Return a LDAP filter by group membership
*
* @param int $gid gidNumber (< 0 as used in EGroupware!)
* @return string filter or '' if $gid not < 0
*/
function membershipFilter($gid)
{
$filter = '';
if ($gid < 0 && ($dn = $GLOBALS['egw']->accounts->id2name($gid, 'account_dn')))
{
$filter .= '(memberOf='.$dn.')';
}
return $filter;
}
} }

View File

@ -973,6 +973,10 @@ class Ldap
$filters .= $this->ids_filter($value); $filters .= $this->ids_filter($value);
break; break;
case 'list':
$filter .= $this->membershipFilter($value);
break;
default: default:
$matches = null; $matches = null;
if (!is_int($key)) if (!is_int($key))
@ -1009,6 +1013,28 @@ class Ldap
return $filters; return $filters;
} }
/**
* Return a LDAP filter by group membership
*
* @param int $gid gidNumber (< 0 as used in EGroupware!)
* @return string filter or '' if $gid not < 0
*/
function membershipFilter($gid)
{
$filter = '';
if ($gid < 0)
{
$filter .= '(|';
// unfortunately we have no group-membership attribute in LDAP, like in AD
foreach($GLOBALS['egw']->accounts->members($gid, true) as $account_id)
{
$filter .= '(uidNumber='.(int)$account_id.')';
}
$filter .= ')';
}
return $filter;
}
/** /**
* Perform the actual ldap-search, retrieve and convert all entries * Perform the actual ldap-search, retrieve and convert all entries
* *

View File

@ -346,8 +346,16 @@ class Sql extends Api\Storage
} }
if (isset($filter['list'])) if (isset($filter['list']))
{ {
$join .= " JOIN $this->ab2list_table ON $this->table_name.contact_id=$this->ab2list_table.contact_id AND ". if ($filter['list'] < 0)
$this->db->expression($this->ab2list_table, array('list_id' => $filter['list'])); {
$join .= " JOIN egw_acl ON $this->table_name.account_id=acl_account AND acl_appname='phpgw_group' AND ".
$this->db->expression('egw_acl', array('acl_location' => $filter['list']));
}
else
{
$join .= " JOIN $this->ab2list_table ON $this->table_name.contact_id=$this->ab2list_table.contact_id AND ".
$this->db->expression($this->ab2list_table, array('list_id' => $filter['list']));
}
unset($filter['list']); unset($filter['list']);
} }
// add join to show only active accounts (only if accounts are shown and in sql and we not already join the accounts table, eg. used by admin) // add join to show only active accounts (only if accounts are shown and in sql and we not already join the accounts table, eg. used by admin)
@ -551,6 +559,28 @@ class Sql extends Api\Storage
$lists[$row['list_id']]['members'][] = $row[$member_attr]; $lists[$row['list_id']]['members'][] = $row[$member_attr];
} }
} }
/* groups as list are implemented currently in Contacts\Storage::get_lists() for all backends
if ($uid_column == 'list_owner' && in_array(0, (array)$uids) && (!$limit_in_ab || in_array(0, (array)$limit_in_ab)))
{
foreach($GLOBALS['egw']->accounts->search(array(
'type' => 'groups'
)) as $account_id => $group)
{
$list = array(
'list_id' => $account_id,
'list_name' => Api\Accounts::format_username($group['account_lid'], '', '', $account_id),
'list_owner' => 0,
'list_uid' => 'group'.$account_id,
'list_carddav_name' => 'group'.$account_id.'.vcf',
'list_etag' => md5(json_encode($GLOBALS['egw']->accounts->members($account_id, true)))
);
if ($member_attr)
{
$list['members'] = array(); // ToDo
}
$lists[(string)$account_id] = $list;
}
}*/
//error_log(__METHOD__.'('.array2string($uids).", '$uid_column', '$member_attr') returning ".array2string($lists)); //error_log(__METHOD__.'('.array2string($uids).", '$uid_column', '$member_attr') returning ".array2string($lists));
return $lists; return $lists;
} }

View File

@ -1012,26 +1012,40 @@ class Storage
*/ */
function get_lists($required=Api\Acl::READ,$extra_labels=null) function get_lists($required=Api\Acl::READ,$extra_labels=null)
{ {
if (!method_exists($this->somain,'get_lists')) return false;
$uids = array();
foreach($this->grants as $uid => $rights)
{
if (($rights & $required) == $required)
{
$uids[] = $uid;
}
}
$lists = is_array($extra_labels) ? $extra_labels : array(); $lists = is_array($extra_labels) ? $extra_labels : array();
foreach($this->somain->get_lists($uids) as $list_id => $data) if (method_exists($this->somain,'get_lists'))
{ {
$lists[$list_id] = $data['list_name']; $uids = array();
if ($data['list_owner'] != $this->user) foreach($this->grants as $uid => $rights)
{ {
$lists[$list_id] .= ' ('.Api\Accounts::username($data['list_owner']).')'; // only requests groups / list in accounts addressbook for read
if (!$uid && $required != Api\Acl::READ) continue;
if (($rights & $required) == $required)
{
$uids[] = $uid;
}
}
foreach($this->somain->get_lists($uids) as $list_id => $data)
{
$lists[$list_id] = $data['list_name'];
if ($data['list_owner'] != $this->user)
{
$lists[$list_id] .= ' ('.Api\Accounts::username($data['list_owner']).')';
}
} }
} }
// add groups for all backends
foreach($GLOBALS['egw']->accounts->search(array(
'type' => 'groups'
)) as $account_id => $group)
{
$lists[(string)$account_id] = Api\Accounts::format_username($group['account_lid'], '', '', $account_id);
}
return $lists; return $lists;
} }