* 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 0479408cfb
commit 523106c008
5 changed files with 104 additions and 18 deletions

View File

@ -1504,8 +1504,8 @@ window.egw_LAB.wait(function() {
{
$query['col_filter']['account_id'] = null;
}
// enable/disable distribution lists depending on backend
$query['no_filter2'] = !$this->lists_available($query['filter']);
// all backends allow now at least to use groups as distribution lists
$query['no_filter2'] = false;
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);
}
/**
* 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);
break;
case 'list':
$filter .= $this->membershipFilter($value);
break;
default:
$matches = null;
if (!is_int($key))
@ -1009,6 +1013,28 @@ class Ldap
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
*

View File

@ -345,9 +345,17 @@ class Sql extends Api\Storage
}
}
if (isset($filter['list']))
{
if ($filter['list'] < 0)
{
$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']);
}
// 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];
}
}
/* 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));
return $lists;
}

View File

@ -1012,17 +1012,21 @@ class Storage
*/
function get_lists($required=Api\Acl::READ,$extra_labels=null)
{
if (!method_exists($this->somain,'get_lists')) return false;
$lists = is_array($extra_labels) ? $extra_labels : array();
if (method_exists($this->somain,'get_lists'))
{
$uids = array();
foreach($this->grants as $uid => $rights)
{
// only requests groups / list in accounts addressbook for read
if (!$uid && $required != Api\Acl::READ) continue;
if (($rights & $required) == $required)
{
$uids[] = $uid;
}
}
$lists = is_array($extra_labels) ? $extra_labels : array();
foreach($this->somain->get_lists($uids) as $list_id => $data)
{
@ -1032,6 +1036,16 @@ class Storage
$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;
}