Unverified Commit 3a4e116c authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:tractor: feat(acl) Move ACL edition HTML to the template

First step of cleaning ACL edition rendering code.
Next steps:
- Move styling to CSS
- Move some computing back to PHP to simplify the template

Then it will be easier to tweak ACL rendering to remove unused ACLs like
 archive:r and such.

issue #6119
Showing with 133 additions and 195 deletions
+133 -195
<h1>{$headline|escape}</h1>
{$aclEdition}
{if $dialogState eq 'create'}
{$aclEdition}
<p class="plugbottom">
<input type="submit" name="add_finish" value="{msgPool type=applyButton}"/>
<input type="submit" formnovalidate="formnovalidate" name="add_cancel" value="{msgPool type=cancelButton}"/>
</p>
{/if}
{elseif $dialogState eq 'edit'}
{function makeCheckbox id='' label='' checked=false}
<input id="acl_{$id}" type="checkbox" name="acl_{$id}"{if $checked} checked="checked"{/if}/>
<label for="acl_{$id}">{$label}</label>
{/function}
<input type="hidden" name="acl_dummy_0_0_0" value="1"/>
<input style="width:100px;" type="button" name="toggle_all_create" onClick="acl_toggle_all('_0_c$');" value="Toggle C"/><input style="width:100px;" type="button" name="toggle_all_move" onClick="acl_toggle_all('_0_m$');" value="Toggle M"/><input style="width:100px;" type="button" name="toggle_all_remove" onClick="acl_toggle_all('_0_d$');" value="Toggle D"/>
-
<input style="width:100px;" type="button" name="toggle_all_read" onClick="acl_toggle_all('_0_r$');" value="Toggle R"/><input style="width:100px;" type="button" name="toggle_all_write" onClick="acl_toggle_all('_0_w$');" value="Toggle W"/>
-
<input style="width:100px;" type="button" name="toggle_all_sub_read" onClick="acl_toggle_all('[^0]_r$');" value="R+"/><input style="width:100px;" type="button" name="toggle_all_sub_write" onClick="acl_toggle_all('[^0]_w$');" value="W+"/>
<br/>
<input style="width:50px;" type="button" name="set_true_all_create" onClick="acl_set_all('_0_c$',true);" value="C+"/><input style="width:50px;" type="button" name="set_false_all_create" onClick="acl_set_all('_0_c$',false);" value="C-"/><input style="width:50px;" type="button" name="set_true_all_move" onClick="acl_set_all('_0_m$',true);" value="M+"/><input style="width:50px;" type="button" name="set_false_all_move" onClick="acl_set_all('_0_m$',false);" value="M-"/><input style="width:50px;" type="button" name="set_true_all_remove" onClick="acl_set_all('_0_d$',true);" value="D+"/><input style="width:50px;" type="button" name="set_false_all_remove" onClick="acl_set_all('_0_d$',false);" value="D-"/>
-
<input style="width:50px;" type="button" name="set_true_all_read" onClick="acl_set_all('_0_r$',true);" value="R+"/><input style="width:50px;" type="button" name="set_false_all_read" onClick="acl_set_all('_0_r$',false);" value="R-"/><input style="width:50px;" type="button" name="set_true_all_write" onClick="acl_set_all('_0_w$',true);" value="W+"/><input style="width:50px;" type="button" name="set_false_all_write" onClick="acl_set_all('_0_w$',false);" value="W-"/>
-
<input style="width:50px;" type="button" name="set_true_all_read" onClick="acl_set_all('[^0]_r$',true);" value="R+"/><input style="width:50px;" type="button" name="set_false_all_read" onClick="acl_set_all('[^0]_r$',false);" value="R-"/><input style="width:50px;" type="button" name="set_true_all_write" onClick="acl_set_all('[^0]_w$',true);" value="W+"/><input style="width:50px;" type="button" name="set_false_all_write" onClick="acl_set_all('[^0]_w$',false);" value="W-"/>
{foreach from=$aclObjects key=$key item=$name}
{$tname = preg_replace('/[^a-z0-9]/i', '_', $key)}
{$currentAcl = $aclContents.$key}
{$overall_acl = ''}
{if isset($currentAcl[0])}
{$overall_acl=$currentAcl[0]}
{/if}
{$expand=((count($currentAcl) > 1) || ($currentAcl[0] != ''))}
{if $expand}
{$back_color = '#C8C8FF'}
{else}
{$back_color = '#C8C8C8'}
{/if}
<table style="width:100%;border:1px solid #A0A0A0;border-spacing:0;border-collapse:collapse;">
<tr>
<td style="background-color:{$back_color};height:1.8em;" colspan="2">
<b>{t}Object{/t}: {$name}</b>
</td>
<td align="right" style="background-color:{$back_color};height:1.8em;">
<input id="show{$tname}" type="button" onclick="$('{$tname}').toggle();" value="{t}Show/hide advanced settings{/t}"/></td>
</tr>
<tr>
<td style="background-color:#E0E0E0" colspan="2">
{makeCheckbox id={$tname|cat:'_0_c'} label=_("Create objects") checked=preg_match('/c/', $overall_acl)}&nbsp;&nbsp;
{makeCheckbox id={$tname|cat:'_0_m'} label=_("Move objects") checked=preg_match('/m/', $overall_acl)}&nbsp;&nbsp;
{makeCheckbox id={$tname|cat:'_0_d'} label=_("Remove objects") checked=preg_match('/d/', $overall_acl)}&nbsp;&nbsp;
{if ($plist[preg_replace('%^.*/%', '', $key)]['plSelfModify'])}
{makeCheckbox id={$tname|cat:'_0_s'} label=_("Grant permission to owner") checked=preg_match('/s/', $overall_acl)}&nbsp;&nbsp;
{/if}
</td>
<td style="background-color:#D4D4D4">
&nbsp;{t}Complete object{/t}:
{makeCheckbox id={$tname|cat:'_0_r'} label=_("read") checked=preg_match('/r/', $overall_acl)}&nbsp;&nbsp;
{makeCheckbox id={$tname|cat:'_0_w'} label=_("write") checked=preg_match('/w/', $overall_acl)}
</td>
</tr>
<tr id="tr_{$tname}" style="vertical-align:top;height:0px;">
<td colspan="3">
<div id="{$tname}" style="overflow:hidden; display:none;vertical-align:top;width:100%;">
<table style="width:100%;border-collapse: collapse;" border="1">
{* Walk through the list of attributes *}
{$cnt = 1}
{$splist = $plist[preg_replace('%^.*/%', '', $key)]['plProvidedAcls']}
{foreach from=$splist key=$attr item=$dsc}
{* Skip pl* attributes, they are internal... *}
{if preg_match('/^pl[A-Z]+.*$/', $attr)}
continue;
{/if}
{* Open table row *}
{if ($cnt == 1)}
<tr>
{/if}
{* Collect list of attributes *}
{$state = ''}
{if isset($currentAcl[$attr])}
{$state = $currentAcl[$attr]}
{/if}
<td style="border:1px solid #A0A0A0;width:33%">
<b>{$dsc}</b> ({$attr})<br/>
{$rchecked = preg_match('/r/', $state)}
{$wchecked = preg_match('/w/', $state)}
<input id="acl_{$tname}_{$attr}_r" type="checkbox" name="acl_{$key}_{$attr}_r"{if $rchecked} checked="checked"{/if}/>
<label for="acl_{$tname}_{$attr}_r">{t}read{/t}</label>
<input id="acl_{$tname}_{$attr}_w" type="checkbox" name="acl_{$key}_{$attr}_w"{if $wchecked} checked="checked"{/if}/>
<label for="acl_{$tname}_{$attr}_w">{t}write{/t}</label>
</td>
{* Close table row *}
{if ($cnt == 3)}
{$cnt = 1}
</tr>
{else}
{$cnt = $cnt+1}
{/if}
{/foreach}
{* Fill missing td's if needed *}
{while (($cnt == 3) || ($cnt == 2))}
<td style="border:1px solid #A0A0A0;width:33%">&nbsp;</td>
{$cnt = $cnt+1}
{/while}
</table>
</div>
</td>
</tr>
</table><br/>
{/foreach}
{if $dialogState eq 'edit'}
<p class="plugbottom">
<input type="submit" name="submit_edit_acl" value="{msgPool type=applyButton}"/>
<input type="submit" formnovalidate="formnovalidate" name="cancel_edit_acl" value="{msgPool type=cancelButton}"/>
......
......@@ -225,13 +225,32 @@ class ACLEditionDialog implements FusionDirectoryDialog
continue;
}
$pInfos = pluglist::pluginInfos($class);
$aclObjects[$this->aclObject.'/'.$class] = $pInfos['plShortName'];
$key = $this->aclObject.'/'.$class;
$aclObjects[$key] = $pInfos['plShortName'];
/* Create sub acl if it does not exist */
if (!isset($this->aclContents[$key])) {
$this->aclContents[$key] = [];
}
if (!isset($this->aclContents[$key][0])) {
$this->aclContents[$key][0] = '';
}
}
if ($this->aclObject == 'all') {
$aclObjects['all'] = _('All objects in current subtree');
/* Create sub acl if it does not exist */
$key = 'all';
if (!isset($this->aclContents[$key])) {
$this->aclContents[$key] = [];
}
if (!isset($this->aclContents[$key][0])) {
$this->aclContents[$key][0] = '';
}
}
$smarty->assign('headline', sprintf(_('Edit ACL for "%s"'), $config->data['CATEGORIES'][$this->aclObject]['description']));
$smarty->assign('aclEdition', $this->buildAclSelector($aclObjects));
$smarty->assign('aclObjects', $aclObjects);
$smarty->assign('aclContents', $this->aclContents);
$tmp = session::get('plist');
$smarty->assign('plist', $tmp->info);
}
/* Show main page */
......@@ -239,194 +258,4 @@ class ACLEditionDialog implements FusionDirectoryDialog
return $smarty->fetch(get_template_path('acleditiondialog.tpl', dirname(__FILE__)));
}
/*!
* \brief Create a checkbox
*
* \param String $name Name of the acl checkbox
* \param String $text Label for the checkbox
* \param boolean $state
*
* \return String containing checkbox
*/
protected function mkchkbx ($name, $text, $state = FALSE)
{
$tname = preg_replace('/[^a-z0-9]/i', '_', $name);
return '<input id="acl_'.$tname.'" type="checkbox" name="acl_'.$name.'"'.($state ? ' checked="checked"' : '').'/>'."\n".
'<label for="acl_'.$tname.'">'.$text.'</label>'."\n";
}
/*!
* \brief Make a read and write box
*
* \param String $name Name of the box
* \param String $state
*
* \return String containing checkbox
*/
protected function mkrwbx ($name, $state = '')
{
$rstate = (preg_match('/r/', $state) ? ' checked="checked"' : '');
$wstate = (preg_match('/w/', $state) ? ' checked="checked"' : '');
$tname = preg_replace('/[^a-z0-9]/i', '_', $name);
return '<input id="acl_'.$tname.'_r" type="checkbox" name="acl_'.$name.'_r"'.$rstate.'/>'."\n".
'<label for="acl_'.$tname.'_r">'._('read').'</label>'."\n".
'<input id="acl_'.$tname.'_w" type="checkbox" name="acl_'.$name.'_w"'.$wstate.'/>'."\n".
'<label for="acl_'.$tname.'_w">'._('write').'</label>'."\n";
}
/*!
* \brief Build an acl selector form
*
* \param Array $list
*
* \return the acl selector form
*/
protected function buildAclSelector ($list)
{
$display = '<input type="hidden" name="acl_dummy_0_0_0" value="1"/>';
$cols = 3;
$tmp = session::get('plist');
$plist = $tmp->info;
/* Add select all/none buttons */
$style = 'style="width:100px;"';
$display .= '<input '.$style.' type="button" name="toggle_all_create" onClick="acl_toggle_all(\'_0_c$\');" value="Toggle C"/>';
$display .= '<input '.$style.' type="button" name="toggle_all_move" onClick="acl_toggle_all(\'_0_m$\');" value="Toggle M"/>';
$display .= '<input '.$style.' type="button" name="toggle_all_remove" onClick="acl_toggle_all(\'_0_d$\');" value="Toggle D"/> - ';
$display .= '<input '.$style.' type="button" name="toggle_all_read" onClick="acl_toggle_all(\'_0_r$\');" value="Toggle R"/>';
$display .= '<input '.$style.' type="button" name="toggle_all_write" onClick="acl_toggle_all(\'_0_w$\');" value="Toggle W"/> - ';
$display .= '<input '.$style.' type="button" name="toggle_all_sub_read" onClick="acl_toggle_all(\'[^0]_r$\');" value="R+"/>';
$display .= '<input '.$style.' type="button" name="toggle_all_sub_write" onClick="acl_toggle_all(\'[^0]_w$\');" value="W+"/>';
$display .= '<br/>';
$style = 'style="width:50px;"';
$display .= '<input '.$style.' type="button" name="set_true_all_create" onClick="acl_set_all(\'_0_c$\',true);" value="C+"/>';
$display .= '<input '.$style.' type="button" name="set_false_all_create" onClick="acl_set_all(\'_0_c$\',false);" value="C-"/>';
$display .= '<input '.$style.' type="button" name="set_true_all_move" onClick="acl_set_all(\'_0_m$\',true);" value="M+"/>';
$display .= '<input '.$style.' type="button" name="set_false_all_move" onClick="acl_set_all(\'_0_m$\',false);" value="M-"/>';
$display .= '<input '.$style.' type="button" name="set_true_all_remove" onClick="acl_set_all(\'_0_d$\',true);" value="D+"/>';
$display .= '<input '.$style.' type="button" name="set_false_all_remove" onClick="acl_set_all(\'_0_d$\',false);" value="D-"/> - ';
$display .= '<input '.$style.' type="button" name="set_true_all_read" onClick="acl_set_all(\'_0_r$\',true);" value="R+"/>';
$display .= '<input '.$style.' type="button" name="set_false_all_read" onClick="acl_set_all(\'_0_r$\',false);" value="R-"/>';
$display .= '<input '.$style.' type="button" name="set_true_all_write" onClick="acl_set_all(\'_0_w$\',true);" value="W+"/>';
$display .= '<input '.$style.' type="button" name="set_false_all_write" onClick="acl_set_all(\'_0_w$\',false);" value="W-"/> - ';
$display .= '<input '.$style.' type="button" name="set_true_all_read" onClick="acl_set_all(\'[^0]_r$\',true);" value="R+"/>';
$display .= '<input '.$style.' type="button" name="set_false_all_read" onClick="acl_set_all(\'[^0]_r$\',false);" value="R-"/>';
$display .= '<input '.$style.' type="button" name="set_true_all_write" onClick="acl_set_all(\'[^0]_w$\',true);" value="W+"/>';
$display .= '<input '.$style.' type="button" name="set_false_all_write" onClick="acl_set_all(\'[^0]_w$\',false);" value="W-"/>';
foreach ($list as $key => $name) {
/* Create sub acl if it does not exist */
if (!isset($this->aclContents[$key])) {
$this->aclContents[$key] = [];
}
if (!isset($this->aclContents[$key][0])) {
$this->aclContents[$key][0] = '';
}
$currentAcl = $this->aclContents[$key];
/* Get the overall plugin acls */
$overall_acl = '';
if (isset($currentAcl[0])) {
$overall_acl = $currentAcl[0];
}
// Detect configured plugins
$expand = ((count($currentAcl) > 1) || ($currentAcl[0] != ''));
/* Object header */
$tname = preg_replace('/[^a-z0-9]/i', '_', $key);
if ($expand) {
$back_color = '#C8C8FF';
} else {
$back_color = '#C8C8C8';
}
$display .= '<table style="width:100%;border:1px solid #A0A0A0;border-spacing:0;border-collapse:collapse;">'."\n".
' <tr>'."\n".
' <td style="background-color:'.$back_color.';height:1.8em;" colspan='.($cols - 1).'>'.
'<b>'._('Object').': '.$name.'</b>'.
'</td>'."\n".
' <td align="right" style="background-color:'.$back_color.';height:1.8em;">'."\n".
' <input id="show'.$tname.'" type="button" onclick="$(\''.$tname.'\').toggle();" value="'._('Show/hide advanced settings').'"/></td>'."\n".
' </tr>'."\n";
/* Generate options */
$spc = '&nbsp;&nbsp;';
$options = $this->mkchkbx($key.'_0_c', _('Create objects'), preg_match('/c/', $overall_acl)).$spc;
$options .= $this->mkchkbx($key.'_0_m', _('Move objects'), preg_match('/m/', $overall_acl)).$spc;
$options .= $this->mkchkbx($key.'_0_d', _('Remove objects'), preg_match('/d/', $overall_acl)).$spc;
if ($plist[preg_replace('%^.*/%', '', $key)]['plSelfModify']) {
$options .= $this->mkchkbx($key.'_0_s', _('Grant permission to owner'), preg_match('/s/', $overall_acl)).$spc;
}
/* Global options */
$more_options = $this->mkchkbx($key.'_0_r', _('read'), preg_match('/r/', $overall_acl)).$spc;
$more_options .= $this->mkchkbx($key.'_0_w', _('write'), preg_match('/w/', $overall_acl));
$display .= ' <tr>'."\n".
' <td style="background-color:#E0E0E0" colspan="'.($cols - 1).'">'.$options.'</td>'."\n".
' <td style="background-color:#D4D4D4">&nbsp;'._('Complete object').': '.$more_options.'</td>'."\n".
' </tr>'."\n";
/* Walk through the list of attributes */
$cnt = 1;
$splist = $plist[preg_replace('%^.*/%', '', $key)]['plProvidedAcls'];
$display .= ' <tr id="tr_'.$tname.'" style="vertical-align:top;height:0px;">'."\n".
' <td colspan="'.$cols.'">'."\n".
' <div id="'.$tname.'" style="overflow:hidden; display:none;vertical-align:top;width:100%;">'."\n".
' <table style="width:100%;border-collapse: collapse;" border="1">'."\n";
foreach ($splist as $attr => $dsc) {
/* Skip pl* attributes, they are internal... */
if (preg_match('/^pl[A-Z]+.*$/', $attr)) {
continue;
}
/* Open table row */
if ($cnt == 1) {
$display .= ' <tr>'."\n";
}
/* Close table row */
if ($cnt == $cols) {
$cnt = 1;
$end = ' </tr>'."\n";
} else {
$cnt++;
$end = '';
}
/* Collect list of attributes */
$state = '';
if (isset($currentAcl[$attr])) {
$state = $currentAcl[$attr];
}
$display .= ' <td style="border:1px solid #A0A0A0;width:'.(int)(100 / $cols).'%">'."\n".
' <b>'.$dsc.'</b> ('.$attr.')<br/>'.$this->mkrwbx($key.'_'.$attr, $state).'</td>'.$end."\n";
}
/* Fill missing td's if needed */
if ((--$cnt != $cols) && ($cnt != 0)) {
$display .= str_repeat(' <td style="border:1px solid #A0A0A0;width:'.(int)(100 / $cols).'%">&nbsp;</td>'."\n", $cols - $cnt);
}
$display .= ' </table>'."\n".
' </div>'."\n".
' </td>'."\n".
' </tr>'."\n";
$display .= '</table><br/>'."\n";
}
return $display;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment