From 8abae60dcaf7faf237a36085cdc0440e81a02d76 Mon Sep 17 00:00:00 2001 From: alec Date: Wed, 25 May 2011 13:05:46 +0000 Subject: - Add support for anyone/anonymous ACL git-svn-id: https://svn.roundcube.net/trunk@4809 208e9e7b-5314-0410-a742-e7e81cd9613c --- plugins/acl/acl.js | 59 +++++++++++++------ plugins/acl/acl.php | 80 ++++++++++++++++++++++++-- plugins/acl/config.inc.php | 10 ---- plugins/acl/localization/en_US.inc | 5 +- plugins/acl/localization/pl_PL.inc | 5 +- plugins/acl/skins/default/acl.css | 2 +- plugins/acl/skins/default/templates/table.html | 4 +- 7 files changed, 129 insertions(+), 36 deletions(-) delete mode 100644 plugins/acl/config.inc.php diff --git a/plugins/acl/acl.js b/plugins/acl/acl.js index 0bf194804..4efe55f14 100644 --- a/plugins/acl/acl.js +++ b/plugins/acl/acl.js @@ -1,7 +1,7 @@ /** * ACL plugin script * - * @version 0.1 + * @version 0.2 * @author Aleksander Machniak */ @@ -45,13 +45,18 @@ rcube_webmail.prototype.acl_delete = function() // Save ACL data rcube_webmail.prototype.acl_save = function() { - var user = $('#acluser').val(), rights = ''; + var user = $('#acluser').val(), rights = '', type; $(':checkbox', this.env.acl_advanced ? $('#advancedrights') : sim_ul = $('#simplerights')).map(function() { if (this.checked) rights += this.value; }); + if (type = $('input:checked[name=usertype]').val()) { + if (type != 'user') + user = type; + } + if (!user) { alert(this.get_label('acl.nouser')); return; @@ -148,10 +153,15 @@ rcube_webmail.prototype.acl_get_usernames = function() selection = list.get_selection(); for (n=0, len=selection.length; n= 0) { + users.push(selection[n]); + } + else { + row = list.rows[selection[n]].obj; + cell = $('td.user', row); + if (cell.length == 1) + users.push(cell.text()); + } } return users; @@ -169,7 +179,7 @@ rcube_webmail.prototype.acl_remove_row = function(id) // Adds ACL table row rcube_webmail.prototype.acl_add_row = function(o, sel) { - var n, len, ids = [], id = o.id, list = this.acl_list, + var n, len, ids = [], spec = [], id = o.id, list = this.acl_list, items = this.env.acl_advanced ? [] : this.env.acl_items, table = this.gui_objects.acltable, row = $('thead > tr', table).clone(); @@ -193,10 +203,17 @@ rcube_webmail.prototype.acl_add_row = function(o, sel) this.env.acl[id] = o.acl; // sorting... (create an array of user identifiers, then sort it) - for (n in this.env.acl) - if (this.env.acl[n]) - ids.push(n); + for (n in this.env.acl) { + if (this.env.acl[n]) { + if (this.env.acl_specials.length && $.inArray(n, this.env.acl_specials) >= 0) + spec.push(n); + else + ids.push(n); + } + } ids.sort(); + // specials on the top + ids = spec.concat(ids); // find current id for (n=0, len=ids.length; n * * @@ -30,6 +30,7 @@ class acl extends rcube_plugin private $rc; private $supported = null; private $mbox; + private $specials = array('anyone', 'anonymous'); /** * Plugin initialization @@ -129,6 +130,7 @@ class acl extends rcube_plugin $this->rc->output->set_env('mailbox', $mbox_imap); $this->rc->output->add_handlers(array( 'acltable' => array($this, 'templ_table'), + 'acluser' => array($this, 'templ_user'), 'aclrights' => array($this, 'templ_rights'), )); @@ -160,7 +162,7 @@ class acl extends rcube_plugin } /** - * Creates ACL rights form + * Creates ACL rights form (rights list part) * * @param array $attrib Template object attributes * @@ -217,6 +219,52 @@ class acl extends rcube_plugin return $out; } + /** + * Creates ACL rights form (user part) + * + * @param array $attrib Template object attributes + * + * @return string HTML Content + */ + function templ_user($attrib) + { + // Create username input + $attrib['name'] = 'acluser'; + + $textfield = new html_inputfield($attrib); + + $fields['user'] = html::label(array('for' => 'iduser'), $this->gettext('username')) + . ' ' . $textfield->show(); + + // Add special entries + if (!empty($this->specials)) { + foreach ($this->specials as $key) { + $fields[$key] = html::label(array('for' => 'id'.$key), $this->gettext($key)); + } + } + + $this->rc->output->set_env('acl_specials', $this->specials); + + // Create list with radio buttons + if (count($fields) > 1) { + $ul = ''; + $radio = new html_radiobutton(array('name' => 'usertype')); + foreach ($fields as $key => $val) { + $ul .= html::tag('li', null, $radio->show($key == 'user' ? 'user' : '', + array('value' => $key, 'id' => 'id'.$key)) + . $val); + } + + $out = html::tag('ul', array('id' => 'usertype'), $ul, html::$common_attrib); + } + // Display text input alone + else { + $out = $fields['user']; + } + + return $out; + } + /** * Creates ACL rights table * @@ -233,9 +281,23 @@ class acl extends rcube_plugin $acl = array(); } + // Keep special entries (anyone/anonymous) on top of the list + if (!empty($this->specials) && !empty($acl)) { + foreach ($this->specials as $key) { + if (isset($acl[$key])) { + $acl_special[$key] = $acl[$key]; + unset($acl[$key]); + } + } + } + // Sort the list by username uksort($acl, 'strnatcasecmp'); + if (!empty($acl_special)) { + $acl = array_merge($acl_special, $acl); + } + // Get supported rights and build column names $supported = $this->rights_supported(); @@ -265,7 +327,7 @@ class acl extends rcube_plugin $table = new html_table($attrib); // Create table header - $table->add_header('user', $this->gettext('username')); + $table->add_header('user', $this->gettext('identifier')); foreach (array_keys($items) as $key) { $table->add_header('acl'.$key, $this->gettext('shortacl'.$key)); } @@ -281,6 +343,10 @@ class acl extends rcube_plugin $userrights = array_intersect($rights, $supported); $userid = html_identifier($user); + if (!empty($this->specials) && in_array($user, $this->specials)) { + $user = $this->gettext($user); + } + $table->add_row(array('id' => 'rcmrow'.$userid)); $table->add('user', Q($user)); @@ -312,15 +378,19 @@ class acl extends rcube_plugin $acl = array_intersect(str_split($acl), $this->rights_supported()); - if (!strpos($user, '@') && ($realm = $this->get_realm())) { + if (!empty($this->specials) && in_array($user, $this->specials)) { + $username = $this->gettext($user); + } + else if (!strpos($user, '@') && ($realm = $this->get_realm())) { $user .= '@' . rcube_idn_to_ascii(preg_replace('/^@/', '', $realm)); + $username = $user; } if ($acl && $user && strlen($mbox) && $this->rc->imap->set_acl($mbox, $user, $acl) ) { $ret = array('id' => html_identifier($user), - 'username' => $user, 'acl' => implode($acl), 'old' => $oldid); + 'username' => $username, 'acl' => implode($acl), 'old' => $oldid); $this->rc->output->command('acl_update', $ret); $this->rc->output->show_message($oldid ? 'acl.updatesuccess' : 'acl.createsuccess', 'confirmation'); } diff --git a/plugins/acl/config.inc.php b/plugins/acl/config.inc.php deleted file mode 100644 index c634c1af1..000000000 --- a/plugins/acl/config.inc.php +++ /dev/null @@ -1,10 +0,0 @@ - diff --git a/plugins/acl/localization/en_US.inc b/plugins/acl/localization/en_US.inc index 7f1655f40..1666377b5 100644 --- a/plugins/acl/localization/en_US.inc +++ b/plugins/acl/localization/en_US.inc @@ -2,10 +2,13 @@ $labels['sharing'] = 'Sharing'; $labels['myrights'] = 'Access Rights'; -$labels['username'] = 'Username'; +$labels['username'] = 'User:'; $labels['advanced'] = 'advanced mode'; $labels['newuser'] = 'Add entry'; $labels['actions'] = 'Access right actions...'; +$labels['anyone'] = 'All users (anyone)'; +$labels['anonymous'] = 'Guests (anonymous)'; +$labels['identifier'] = 'Identifier'; $labels['acll'] = 'Lookup'; $labels['aclr'] = 'Read messages'; diff --git a/plugins/acl/localization/pl_PL.inc b/plugins/acl/localization/pl_PL.inc index cba12d927..608dc4f04 100644 --- a/plugins/acl/localization/pl_PL.inc +++ b/plugins/acl/localization/pl_PL.inc @@ -2,10 +2,13 @@ $labels['sharing'] = 'Udostępnianie'; $labels['myrights'] = 'Prawa dostępu'; -$labels['username'] = 'Nazwa użytkownika'; +$labels['username'] = 'Użytkownik:'; $labels['advanced'] = 'tryb zaawansowany'; $labels['newuser'] = 'Dodaj rekord'; $labels['actions'] = 'Akcje na prawach...'; +$labels['anyone'] = 'Wszyscy (anyone)'; +$labels['anonymous'] = 'Goście (anonymous)'; +$labels['identifier'] = 'Identyfikator'; $labels['acll'] = 'Podgląd (Lookup)'; $labels['aclr'] = 'Odczyt (Read)'; diff --git a/plugins/acl/skins/default/acl.css b/plugins/acl/skins/default/acl.css index 8731a6503..bee94ac61 100644 --- a/plugins/acl/skins/default/acl.css +++ b/plugins/acl/skins/default/acl.css @@ -77,7 +77,7 @@ #aclform { top: 100px; - width: 400px; + width: 480px; padding: 10px; } diff --git a/plugins/acl/skins/default/templates/table.html b/plugins/acl/skins/default/templates/table.html index 8caafe7dc..2365ef757 100644 --- a/plugins/acl/skins/default/templates/table.html +++ b/plugins/acl/skins/default/templates/table.html @@ -29,8 +29,8 @@
-
- +
+
-- cgit v1.2.3