Skip to content

Commit

Permalink
Merge branch 'master' into release-1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
johndoh committed Aug 31, 2014
2 parents 06c23bc + 3f33c30 commit e94d4af
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Roundcube Webmail GlobalAddressbook
===================================

Version 1.9 (2014-08-31, rc-1.0)
=================================================
* Replace globaladdressbook_readonly option with globaladdressbook_perms
* Add option to disable "move" operation for contacts

Version 1.8 (2013-12-01, rc-1.0)
=================================================
* Call email2user conversion for usernames with @ in (incase of username post processing)
Expand Down
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,21 @@ follows:
* %d is replaced with the domain part of the logged in user's username
* %h is replaced with the imap host (from the session info)

**'readonly'**
**'perms'**

Make address book read only, users will not be able to edit the contents of the
address book or add new contacts
Restrict the actions that can be performed by users in the global address book
* 0 - global address book is read only
* 1 - users can add, edit and delete contacts (full permissions)
* 2 - users can add but not edit or delete contacts
* 3 - users can add and edit but not delete contacts

**NB:** The globaladdressbook_readonly option was deprecated in version 1.9,
replaced by globaladdressbook_perms.

**'force_copy'**

Always copy a contact from the global address book to another one, for example
when using drag 'n drop. Default behaviour is to move the contact.

**'groups'**

Expand All @@ -68,4 +79,10 @@ if the address book is set to read only. The follow options are available:

Show contacts from this book in the auto complete menu when composing an email

**'check_safe'**

Use addresses in the global address book to identify known senders before
displaying remote inline images in HTML messages (in addition to other
configured address books).

[gpl]: http://www.gnu.org/licenses/gpl.html
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"homepage": "http://github.com/JohnDoh/Roundcube-Plugin-Global-Address-Book/",
"license": "GPL-3.0",
"type": "roundcube-plugin",
"version": "1.8",
"version": "1.9",
"authors": [
{
"name": "Philip Weir",
Expand Down
11 changes: 9 additions & 2 deletions config.inc.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@
// eg. to create one global address book per domain: global_addressbook@%d
$config['globaladdressbook_user'] = '[global_addressbook_user]';

// make global address book read only
$config['globaladdressbook_readonly'] = true;
// default user permissions
// 0 - global address book is read only
// 1 - users can add, edit and delete contacts (full permissions)
// 2 - users can add but not edit or delete contacts
// 3 - users can add and edit but not delete contacts
$config['globaladdressbook_perms'] = 0;

// always copy contacts from the global address book to another address book, never move
$config['globaladdressbook_force_copy'] = true;

// allow groups in global address book
$config['globaladdressbook_groups'] = false;
Expand Down
56 changes: 45 additions & 11 deletions globaladdressbook.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class globaladdressbook extends rcube_plugin
{
public $task = 'mail|addressbook|settings|dummy';
private $abook_id = 'global';
private $readonly;
private $readonly = true;
private $groups;
private $name;
private $user_id;
Expand All @@ -28,9 +28,9 @@ public function init()
$this->user_name = $rcmail->config->get('globaladdressbook_user');
$this->user_name = str_replace('%d', $rcmail->user->get_username('domain'), $this->user_name);
$this->user_name = str_replace('%h', $_SESSION['storage_host'], $this->user_name);
$this->readonly = $this->_is_readonly();
$this->groups = $rcmail->config->get('globaladdressbook_groups', false);
$this->name = $this->gettext('globaladdressbook');
$this->_set_permissions();

// email2user hook can be used by other plugins to do post processing on usernames, not just virtual user lookup
// matches process of user lookup and creation in the core
Expand Down Expand Up @@ -102,27 +102,61 @@ public function check_known_senders($args)
return $args;
}

private function _is_readonly()
private function _set_permissions()
{
$rcmail = rcube::get_instance();
$isAdmin = false;

if (!$rcmail->config->get('globaladdressbook_readonly'))
return false;
// fix deprecated globaladdressbook_readonly option removed 20140525
if ($rcmail->config->get('globaladdressbook_perms') === null) {
$rcmail->config->set('globaladdressbook_perms', $rcmail->config->get('globaladdressbook_readonly') ? 0 : 1);
}

// check for full permissions
$perms = $rcmail->config->get('globaladdressbook_perms');
if (in_array($perms, array(1, 2, 3))) {
$this->readonly = false;
}

// check if the user is an admin
if ($admin = $rcmail->config->get('globaladdressbook_admin')) {
if (!is_array($admin)) $admin = array($admin);
if (!is_array($admin)) {
$admin = array($admin);
}

foreach ($admin as $user) {
if (strpos($user, '/') == 0 && substr($user, -1) == '/') {
if (preg_match($user, $_SESSION['username']))
return false;
if (preg_match($user, $_SESSION['username'])) {
$this->readonly = false;
$isAdmin = true;
}
}
elseif ($user == $_SESSION['username']) {
$this->readonly = false;
$isAdmin = true;
}
elseif ($user == $_SESSION['username'])
return false;
}
}

return true;
// check for task specific permissions
if ($rcmail->task == 'addressbook' && rcube_utils::get_input_value('_source', rcube_utils::INPUT_GPC) == $this->abook_id) {
if ($rcmail->action == 'move' && $rcmail->config->get('globaladdressbook_force_copy')) {
$rcmail->overwrite_action('copy');
$this->api->output->command('list_contacts');
}

// do not override permissions for admins
if (!$isAdmin && !$this->readonly) {
if (in_array($rcmail->action, array('show', 'edit')) && in_array($perms, array(2))) {
$this->readonly = true;
}
elseif ($rcmail->action == 'delete' && in_array($perms, array(2, 3))) {
$this->api->output->command('display_message', $this->gettext('errornoperm'), 'info');
$this->api->output->command('list_contacts');
$this->api->output->send();
}
}
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions localization/pt_BR.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/* Author: Guilherme Calabria */

$labels = array();
$labels['globaladdressbook'] = 'Contatos Globais';

$messages = array();

?>

0 comments on commit e94d4af

Please sign in to comment.