Implement users autocompletion in kolab_files - use users from LDAP not from addressbook(s)
This commit is contained in:
parent
df5e84f052
commit
94eff6b1e7
5 changed files with 194 additions and 14 deletions
|
@ -15,4 +15,13 @@ $config['kolab_files_sort_order'] = 'asc';
|
|||
// Number of concurent requests for searching and collections listing. Default: 1
|
||||
$config['kolab_files_search_threads'] = 1;
|
||||
|
||||
?>
|
||||
// LDAP addressbook that would be searched for user names autocomplete.
|
||||
// That should be an array refering to the $config['ldap_public'] array key
|
||||
// or complete addressbook configuration array.
|
||||
$config['kolab_files_users_source'] = '';
|
||||
|
||||
// The LDAP attribute which will be used as ACL user identifier
|
||||
$config['kolab_files_users_field'] = 'mail';
|
||||
|
||||
// The LDAP search filter will be &'d with search queries
|
||||
$config['kolab_files_users_filter'] = '';
|
||||
|
|
|
@ -1192,7 +1192,7 @@ rcube_webmail.prototype.document_close = function()
|
|||
// document editors management dialog
|
||||
function kolab_files_editors_dialog(session)
|
||||
{
|
||||
var ac_props, items = [], buttons = {},
|
||||
var items = [], buttons = {},
|
||||
info = rcmail.env.file_data,
|
||||
dialog = $('#document-editors-dialog'),
|
||||
comment = $('#invitation-comment');
|
||||
|
@ -1224,16 +1224,7 @@ function kolab_files_editors_dialog(session)
|
|||
|
||||
if (!rcmail.env.editors_dialog) {
|
||||
rcmail.env.editors_dialog = dialog;
|
||||
|
||||
// init attendees autocompletion
|
||||
if (rcmail.env.autocomplete_threads > 0) {
|
||||
ac_props = {
|
||||
threads: rcmail.env.autocomplete_threads,
|
||||
sources: rcmail.env.autocomplete_sources
|
||||
};
|
||||
}
|
||||
|
||||
rcmail.init_address_input_events($('#invitation-editor-name'), ac_props);
|
||||
rcmail.init_address_input_events($('#invitation-editor-name'), {action: 'files/autocomplete'});
|
||||
|
||||
rcmail.addEventListener('autocomplete_insert', function(e) {
|
||||
var success = false;
|
||||
|
|
|
@ -50,6 +50,7 @@ class kolab_files extends rcube_plugin
|
|||
$this->register_action('prefs', array($this, 'actions'));
|
||||
$this->register_action('open', array($this, 'actions'));
|
||||
$this->register_action('edit', array($this, 'actions'));
|
||||
$this->register_action('autocomplete', array($this, 'autocomplete'));
|
||||
|
||||
// we use libkolab::http_request() from libkolab with its configuration
|
||||
$this->require_plugin('libkolab');
|
||||
|
@ -77,7 +78,7 @@ class kolab_files extends rcube_plugin
|
|||
return $this->engine = false;
|
||||
}
|
||||
|
||||
require_once $this->home . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'kolab_files_engine.php';
|
||||
require_once $this->home . '/lib/kolab_files_engine.php';
|
||||
|
||||
$this->engine = new kolab_files_engine($this, $url);
|
||||
}
|
||||
|
@ -132,4 +133,16 @@ class kolab_files extends rcube_plugin
|
|||
$engine->actions();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for user autocomplete request
|
||||
*/
|
||||
function autocomplete()
|
||||
{
|
||||
$this->load_config();
|
||||
|
||||
require_once $this->home . '/lib/kolab_files_autocomplete.php';
|
||||
|
||||
new kolab_files_autocomplete($this);
|
||||
}
|
||||
}
|
||||
|
|
168
plugins/kolab_files/lib/kolab_files_autocomplete.php
Normal file
168
plugins/kolab_files/lib/kolab_files_autocomplete.php
Normal file
|
@ -0,0 +1,168 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Kolab files collaborators autocompletion
|
||||
*
|
||||
* @author Aleksander Machniak <machniak@kolabsys.com>
|
||||
*
|
||||
* Copyright (C) 2013-2015, Kolab Systems AG <contact@kolabsys.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
class kolab_files_autocomplete
|
||||
{
|
||||
private $plugin;
|
||||
private $rc;
|
||||
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*/
|
||||
public function __construct($plugin)
|
||||
{
|
||||
$this->plugin = $plugin;
|
||||
$this->rc = rcube::get_instance();
|
||||
|
||||
$search = rcube_utils::get_input_value('_search', rcube_utils::INPUT_GPC, true);
|
||||
$reqid = rcube_utils::get_input_value('_reqid', rcube_utils::INPUT_GPC);
|
||||
$users = array();
|
||||
$keys = array();
|
||||
|
||||
if ($this->init_ldap()) {
|
||||
$max = (int) $this->rc->config->get('autocomplete_max', 15);
|
||||
$mode = (int) $this->rc->config->get('addressbook_search_mode');
|
||||
$me = $this->rc->get_user_name();
|
||||
|
||||
$this->ldap->set_pagesize($max);
|
||||
$result = $this->ldap->search('*', $search, $mode);
|
||||
|
||||
foreach ($result->records as $record) {
|
||||
$user = $record['uid'];
|
||||
|
||||
if (is_array($user)) {
|
||||
$user = array_filter($user);
|
||||
$user = $user[0];
|
||||
}
|
||||
|
||||
if (in_array($me, rcube_addressbook::get_col_values('email', $record, true))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($user) {
|
||||
$display = rcube_addressbook::compose_search_name($record);
|
||||
$user = array('name' => $user, 'display' => $display);
|
||||
$users[] = $user;
|
||||
$keys[] = $display ?: $user['name'];
|
||||
}
|
||||
}
|
||||
/*
|
||||
if ($this->rc->config->get('kolab_files_groups')) {
|
||||
$prefix = $this->rc->config->get('kolab_files_group_prefix');
|
||||
$group_field = $this->rc->config->get('kolab_files_group_field', 'name');
|
||||
$result = $this->ldap->list_groups($search, $mode);
|
||||
|
||||
foreach ($result as $record) {
|
||||
$group = $record['name'];
|
||||
$group_id = is_array($record[$group_field]) ? $record[$group_field][0] : $record[$group_field];
|
||||
|
||||
if ($group) {
|
||||
$users[] = array('name' => ($prefix ? $prefix : '') . $group_id, 'display' => $group, 'type' => 'group');
|
||||
$keys[] = $group;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
if (count($users)) {
|
||||
// sort users index
|
||||
asort($keys, SORT_LOCALE_STRING);
|
||||
// re-sort users according to index
|
||||
foreach ($keys as $idx => $val) {
|
||||
$keys[$idx] = $users[$idx];
|
||||
}
|
||||
$users = array_values($keys);
|
||||
}
|
||||
|
||||
$this->rc->output->command('ksearch_query_results', $users, $search, $reqid);
|
||||
$this->rc->output->send();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes autocomplete LDAP backend
|
||||
*/
|
||||
private function init_ldap()
|
||||
{
|
||||
if ($this->ldap) {
|
||||
return $this->ldap->ready;
|
||||
}
|
||||
|
||||
// get LDAP config
|
||||
$config = $this->rc->config->get('kolab_files_users_source');
|
||||
|
||||
if (empty($config)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// not an array, use configured ldap_public source
|
||||
if (!is_array($config)) {
|
||||
$ldap_config = (array) $this->rc->config->get('ldap_public');
|
||||
$config = $ldap_config[$config];
|
||||
}
|
||||
|
||||
$uid_field = $this->rc->config->get('kolab_files_users_field', 'mail');
|
||||
$filter = $this->rc->config->get('kolab_files_users_filter');
|
||||
$debug = $this->rc->config->get('ldap_debug');
|
||||
$domain = $this->rc->config->mail_domain($_SESSION['imap_host']);
|
||||
|
||||
if (empty($uid_field) || empty($config)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// get name attribute
|
||||
if (!empty($config['fieldmap'])) {
|
||||
$name_field = $config['fieldmap']['name'];
|
||||
}
|
||||
// ... no fieldmap, use the old method
|
||||
if (empty($name_field)) {
|
||||
$name_field = $config['name_field'];
|
||||
}
|
||||
|
||||
// add UID field to fieldmap, so it will be returned in a record with name
|
||||
$config['fieldmap']['name'] = $name_field;
|
||||
$config['fieldmap']['uid'] = $uid_field;
|
||||
|
||||
// search in UID and name fields
|
||||
// $name_field can be in a form of <field>:<modifier> (#1490591)
|
||||
$name_field = preg_replace('/:.*$/', '', $name_field);
|
||||
$search = array_unique(array($name_field, $uid_field));
|
||||
|
||||
$config['search_fields'] = $search;
|
||||
$config['required_fields'] = array($uid_field);
|
||||
|
||||
// set search filter
|
||||
if ($filter) {
|
||||
$config['filter'] = $filter;
|
||||
}
|
||||
|
||||
// disable vlv
|
||||
$config['vlv'] = false;
|
||||
|
||||
// Initialize LDAP connection
|
||||
$this->ldap = new rcube_ldap($config, $debug, $domain);
|
||||
|
||||
return $this->ldap->ready;
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@
|
|||
/**
|
||||
* Kolab files storage engine
|
||||
*
|
||||
* @version @package_version@
|
||||
* @author Aleksander Machniak <machniak@kolabsys.com>
|
||||
*
|
||||
* Copyright (C) 2013, Kolab Systems AG <contact@kolabsys.com>
|
||||
|
|
Loading…
Add table
Reference in a new issue