diff options
| -rw-r--r-- | plugins/acl/acl.js | 59 | ||||
| -rw-r--r-- | plugins/acl/acl.php | 80 | ||||
| -rw-r--r-- | plugins/acl/config.inc.php | 10 | ||||
| -rw-r--r-- | plugins/acl/localization/en_US.inc | 5 | ||||
| -rw-r--r-- | plugins/acl/localization/pl_PL.inc | 5 | ||||
| -rw-r--r-- | plugins/acl/skins/default/acl.css | 2 | ||||
| -rw-r--r-- | plugins/acl/skins/default/templates/table.html | 4 |
7 files changed, 129 insertions, 36 deletions
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 <alec@alec.pl> */ @@ -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<len; n++) { - row = list.rows[selection[n]].obj; - cell = $('td.user', row); - if (cell.length == 1) - users.push(cell.text()); + if (this.env.acl_specials.length && $.inArray(selection[n], this.env.acl_specials) >= 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<len; n++) @@ -219,10 +236,15 @@ rcube_webmail.prototype.acl_add_row = function(o, sel) // Initializes and shows ACL create/edit form rcube_webmail.prototype.acl_init_form = function(id) { - var ul, row, li_elements, body = $('body'), + var ul, row, val = '', type = 'user', li_elements, body = $('body'), adv_ul = $('#advancedrights'), sim_ul = $('#simplerights'), name_input = $('#acluser'); + if (!this.acl_form) { + var fn = function () { $('input[value=user]').prop('checked', true); }; + name_input.click(fn).keypress(fn); + } + this.acl_form = $('#aclform'); // Hide unused items @@ -248,12 +270,16 @@ rcube_webmail.prototype.acl_init_form = function(id) if (td && td.hasClass('enabled')) this.checked = true; }); - name_input.val($('td.user', row).text()); - } - else { - name_input.val(''); + + if (!this.env.acl_specials.length || $.inArray(id, this.env.acl_specials) < 0) + val = $('td.user', row).text(); + else + type = id; } + name_input.val(val); + $('input[value='+type+']').prop('checked', true); + this.acl_id = id; // position the form horizontally @@ -264,5 +290,6 @@ rcube_webmail.prototype.acl_init_form = function(id) // display it this.acl_form.show(); - name_input.focus(); + if (type == 'user') + name_input.focus(); } diff --git a/plugins/acl/acl.php b/plugins/acl/acl.php index 450af49ea..68d7ff887 100644 --- a/plugins/acl/acl.php +++ b/plugins/acl/acl.php @@ -3,7 +3,7 @@ /** * Folders Access Control Lists Management (RFC4314, RFC2086) * - * @version 0.1 + * @version 0.2 * @author Aleksander Machniak <alec@alec.pl> * * @@ -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 * @@ -218,6 +220,52 @@ class acl extends rcube_plugin } /** + * 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 * * @param array $attrib Template object attributes @@ -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 @@ -<?php - -// Sets default look of access rights table -// In advanced mode all access rights are displayed separately -// In simple mode access rights are grouped into four groups: read, write, delete, full -$rcmail_config['acl_advanced_mode'] = true; - -$rcmail_config['acl_username_realm'] = 'test90.kolabsys.com'; - -?> 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 @@ </div> <div id="aclform" class="popupmenu"> - <fieldset class="thinbordered"><legend><roundcube:label name="acl.username" /></legend> - <input type="text" name="acluser" value="" id="acluser" size="45" style="width: 95%" /> + <fieldset class="thinbordered"><legend><roundcube:label name="acl.identifier" /></legend> + <roundcube:object name="acluser" class="toolbarmenu" id="acluser" size="35" /> </fieldset> <fieldset class="thinbordered"><legend><roundcube:label name="acl.myrights" /></legend> <roundcube:object name="aclrights" class="toolbarmenu" /> |
