Use IMAP permissions to control address book interactions (#3025)

This commit is contained in:
Thomas Bruederli 2015-03-11 19:54:27 +01:00
parent 54b47dc753
commit fbb71376ab
3 changed files with 55 additions and 18 deletions

View file

@ -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;

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}