summaryrefslogtreecommitdiff
path: root/plugins/kolab_addressbook
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2015-03-11 18:54:27 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2015-03-11 18:54:27 (GMT)
commitfbb71376ab75ecce80fd1c6c69a7cedc61c96057 (patch)
tree43540dfda8139a779aa4796a5da2c6f7c11a1ab4 /plugins/kolab_addressbook
parent54b47dc75308bd04332b04d055572fd32e4840c6 (diff)
downloadroundcubemail-plugins-kolab-fbb71376ab75ecce80fd1c6c69a7cedc61c96057.tar.gz
Use IMAP permissions to control address book interactions (#3025)
Diffstat (limited to 'plugins/kolab_addressbook')
-rw-r--r--plugins/kolab_addressbook/kolab_addressbook.js43
-rw-r--r--plugins/kolab_addressbook/kolab_addressbook.php17
-rw-r--r--plugins/kolab_addressbook/lib/rcube_kolab_contacts.php13
3 files changed, 55 insertions, 18 deletions
diff --git a/plugins/kolab_addressbook/kolab_addressbook.js b/plugins/kolab_addressbook/kolab_addressbook.js
index c837030..b940250 100644
--- a/plugins/kolab_addressbook/kolab_addressbook.js
+++ b/plugins/kolab_addressbook/kolab_addressbook.js
@@ -131,6 +131,19 @@ if (window.rcmail) {
rcmail.addEventListener('listupdate', function() {
rcmail.set_book_actions();
});
+
+ // wait until rcmail.contact_list is ready and subscribe to 'select' events
+ setTimeout(function() {
+ rcmail.contact_list && rcmail.contact_list.addEventListener('select', function(list) {
+ var selected = list.selection.length,
+ source = rcmail.env.source ? rcmail.env.address_sources[rcmail.env.source] : null;
+
+ if (selected && source.kolab) {
+ console.log('select', source.rights)
+ rcmail.enable_command('delete', 'move', selected && source.rights.indexOf('t') >= 0);
+ }
+ });
+ }, 100);
}
// (De-)activates address book management commands
@@ -139,10 +152,12 @@ rcube_webmail.prototype.set_book_actions = function()
var source = !this.env.group ? this.env.source : null,
sources = this.env.address_sources;
+ var props = source && sources[source] && sources[source].kolab ? sources[source] : { removable: false, rights: '' }
this.enable_command('book-create', true);
- this.enable_command('book-edit', 'book-delete', source && sources[source] && sources[source].kolab && sources[source].editable);
- this.enable_command('book-remove', source && sources[source] && sources[source].kolab && sources[source].removable);
- this.enable_command('book-showurl', source && sources[source] && sources[source].carddavurl);
+ this.enable_command('book-edit', props.rights.indexOf('a') >= 0);
+ this.enable_command('book-delete', props.rights.indexOf('x') >= 0 || props.rights.indexOf('a') >= 0);
+ this.enable_command('book-remove', props.removable);
+ this.enable_command('book-showurl', !!props.carddavurl);
};
rcube_webmail.prototype.book_create = function()
@@ -359,26 +374,36 @@ function kolab_addressbook_contextmenu()
}, {
'activate': function(p) {
var source = !rcmail.env.group ? rcmail.env.source : null,
- sources = rcmail.env.address_sources;
+ sources = rcmail.env.address_sources,
+ props = source && sources[source] && sources[source].kolab ?
+ sources[source] : { readonly: true, removable: false, rights: '' };
if (p.command == 'book-create') {
return true;
}
- if (p.command == 'book-edit' || p.command == 'book-delete' || p.command == 'group-create') {
- return !!(source && sources[source] && sources[source].kolab && sources[source].editable);
+ if (p.command == 'book-edit') {
+ return props.rights.indexOf('a') >= 0;
+ }
+
+ if (p.command == 'book-delete') {
+ return props.rights.indexOf('a') >= 0 || props.rights.indexOf('x') >= 0;
+ }
+
+ if (p.command == 'group-create') {
+ return !props.readonly;
}
if (p.command == 'book-remove') {
- return !!(source && sources[source] && sources[source].kolab && sources[source].removable);
+ return props.removable;
}
if (p.command == 'book-showurl') {
- return !!(source && sources[source] && sources[source].carddavurl);
+ return !!(props.carddavurl);
}
if (p.command == 'group-rename' || p.command == 'group-delete') {
- return !!(rcmail.env.group && sources[rcmail.env.source] && sources[rcmail.env.source].editable);
+ return !!(rcmail.env.group && sources[rcmail.env.source] && !sources[rcmail.env.source].readonly);
}
return false;
diff --git a/plugins/kolab_addressbook/kolab_addressbook.php b/plugins/kolab_addressbook/kolab_addressbook.php
index 26c2bca..a8046b3 100644
--- a/plugins/kolab_addressbook/kolab_addressbook.php
+++ b/plugins/kolab_addressbook/kolab_addressbook.php
@@ -113,6 +113,11 @@ class kolab_addressbook extends rcube_plugin
foreach ($this->_list_sources() as $abook_id => $abook) {
// register this address source
$sources[$abook_id] = $this->abook_prop($abook_id, $abook);
+
+ // flag folders with 'i' right as writeable
+ if ($this->rc->action == 'add' && strpos($abook->rights, 'i') !== false) {
+ $sources[$abook_id]['readonly'] = false;
+ }
}
// Add personal address sources to the list
@@ -145,7 +150,7 @@ class kolab_addressbook extends rcube_plugin
'listname' => $abook->get_foldername(),
'group' => $abook instanceof kolab_storage_folder_user ? 'user' : $abook->get_namespace(),
'readonly' => true,
- 'editable' => false,
+ 'rights' => 'l',
'kolab' => true,
'virtual' => true,
);
@@ -156,7 +161,7 @@ class kolab_addressbook extends rcube_plugin
'name' => $abook->get_name(),
'listname' => $abook->get_foldername(),
'readonly' => $abook->readonly,
- 'editable' => $abook->editable,
+ 'rights' => $abook->rights,
'groups' => $abook->groups,
'undelete' => $abook->undelete && $this->rc->config->get('undo_timeout'),
'realname' => rcube_charset::convert($abook->get_realname(), 'UTF7-IMAP'), // IMAP folder name
@@ -387,6 +392,14 @@ class kolab_addressbook extends rcube_plugin
if ($folder && $folder->type == 'contact') {
$p['instance'] = new rcube_kolab_contacts($folder->name);
+
+ // flag source as writeable if 'i' right is given
+ if ($p['writeable'] && $this->rc->action == 'save' && strpos($p['instance']->rights, 'i') !== false) {
+ $p['instance']->readonly = false;
+ }
+ else if ($this->rc->action == 'delete' && strpos($p['instance']->rights, 't') !== false) {
+ $p['instance']->readonly = false;
+ }
}
}
diff --git a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php
index c618b10..9f117e4 100644
--- a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php
+++ b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php
@@ -29,8 +29,8 @@
class rcube_kolab_contacts extends rcube_addressbook
{
public $primary_key = 'ID';
+ public $rights = 'lrs';
public $readonly = true;
- public $editable = false;
public $undelete = true;
public $groups = true;
public $coltypes = array(
@@ -122,19 +122,18 @@ class rcube_kolab_contacts extends rcube_addressbook
$this->storagefolder = kolab_storage::get_folder($this->imap_folder);
$this->ready = $this->storagefolder && !PEAR::isError($this->storagefolder);
- // Set readonly and editable flags according to folder permissions
+ // Set readonly and rights flags according to folder permissions
if ($this->ready) {
if ($this->storagefolder->get_owner() == $_SESSION['username']) {
- $this->editable = true;
$this->readonly = false;
+ $this->rights = 'lrswikxtea';
}
else {
$rights = $this->storagefolder->get_myrights();
- if (!PEAR::isError($rights)) {
- if (strpos($rights, 'i') !== false)
+ if ($rights && !PEAR::isError($rights)) {
+ $this->rights = $rights;
+ if (strpos($rights, 'i') !== false && strpos($rights, 't') !== false)
$this->readonly = false;
- if (strpos($rights, 'a') !== false || strpos($rights, 'x') !== false)
- $this->editable = true;
}
}
}