Admin - add ACL export

This commit is contained in:
nathangray 2017-09-18 14:48:02 -06:00
parent 5f2d541063
commit e456f7800c
4 changed files with 391 additions and 1 deletions

View File

@ -0,0 +1,162 @@
<?php
/**
* EGroupware - Admin - importexport
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package admin
* @subpackage importexport
* @link http://www.egroupware.org
* @author Nathan Gray
* @copyright Nathan Gray 2011
* @version $Id$
*/
use EGroupware\Api;
/**
* class admin_egw_acl_record
* Record class needed for export
*/
class admin_egw_acl_record implements importexport_iface_egw_record
{
private $identifier = '';
private $record = array();
// Used in conversions
static $types = array(
'select' => array('acl_appname'),
'select-account' => array('acl_account', 'acl_location'),
'select-bool' => array('acl1', 'acl2','acl4','acl8','acl16','acl64','acl128','acl256'),
);
/**
* constructor
* reads record from backend if identifier is given.
*
* @param string $_identifier
*/
public function __construct( $_identifier='' ) {
if(is_array($_identifier)) {
$this->identifier = $_identifier['id'];
$this->set_record($_identifier);
} else {
$this->identifier = $_identifier;
//$GLOBALS['egw']->acl->read($this->identifier);
}
}
/**
* magic method to set attributes of record
*
* @param string $_attribute_name
*/
public function __get($_attribute_name) {
return $this->record[$_attribute_name];
}
/**
* magig method to set attributes of record
*
* @param string $_attribute_name
* @param data $data
*/
public function __set($_attribute_name, $data) {
$this->record[$_attribute_name] = $data;
}
/**
* converts this object to array.
* @abstract We need such a function cause PHP5
* dosn't allow objects do define it's own casts :-(
* once PHP can deal with object casts we will change to them!
*
* @return array complete record as associative array
*/
public function get_record_array() {
return $this->record;
}
/**
* gets title of record
*
*@return string title
*/
public function get_title() {
return Api\Accounts::username($this->identifier);
}
/**
* sets complete record from associative array
*
* @todo add some checks
* @return void
*/
public function set_record(array $_record) {
$this->record = $_record;
}
/**
* gets identifier of this record
*
* @return string identifier of current record
*/
public function get_identifier() {
return $this->identifier;
}
/**
* Gets the URL icon representitive of the record
* This could be as general as the application icon, or as specific as a contact photo
*
* @return string Full URL of an icon, or appname/icon_name
*/
public function get_icon() {
return 'access';
}
/**
* saves record into backend
*
* @return string identifier
*/
public function save ( $_dst_identifier ) {
unset($_dst_identifier); // not used, but require by function signature
}
/**
* copies current record to record identified by $_dst_identifier
*
* @param string $_dst_identifier
* @return string dst_identifier
*/
public function copy ( $_dst_identifier ) {
unset($_dst_identifier); // not used, but require by function signature
}
/**
* moves current record to record identified by $_dst_identifier
* $this will become moved record
*
* @param string $_dst_identifier
* @return string dst_identifier
*/
public function move ( $_dst_identifier ) {
unset($_dst_identifier); // not used, but require by function signature
}
/**
* delets current record from backend
*
*/
public function delete () {
}
/**
* destructor
*
*/
public function __destruct() {
unset ($this->record);
}
}

View File

@ -0,0 +1,189 @@
<?php
/**
* EGroupware - Export plugin for ACL settings
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package admin
* @subpackage importexport
* @link http://www.egroupware.org
* @author Nathan Gray
* @copyright Nathan Gray 2017
* @version $Id$
*/
use EGroupware\Api\Hooks;
use EGroupware\Api\Etemplate\Widget\Select;
/**
* Export ACL plugin
*/
class admin_export_acl_csv implements importexport_iface_export_plugin
{
/**
* Exports records as defined in $_definition
*
* @param egw_record $_definition
*/
public function export( $_stream, importexport_definition $_definition)
{
$options = $_definition->plugin_options;
$selection = array();
$query = array(
'filter' => 'other',
'filter2' => $_definition->filter['acl_appname'] ? $_definition->filter['acl_appname'] : '',
'acl_rights' => Hooks::process(array(
'location' => 'acl_rights'
))
);
if($_definition->filter['acl_location'])
{
$query['col_filter']['acl_location'] = $_definition->filter['acl_location'];
}
// ACL queries only go by one account at a time, so we collect for all
if($_definition->filter['acl_account'])
{
$accounts = array_flip($_definition->filter['acl_account']);
}
else
{
$account_query = array(
'type' => 'both',
'active' => $_definition->filter['active']
);
$accounts = $GLOBALS['egw']->accounts->search($account_query);
}
foreach($accounts as $account_id => $account_data)
{
$query['account_id'] = $account_id;
$account_acl = array();
admin_acl::get_rows($query, $account_acl);
$selection = array_merge($selection, $account_acl);
}
$options['begin_with_fieldnames'] = true;
$export_object = new importexport_export_csv($_stream, (array)$options);
$export_object->set_mapping($options['mapping']);
$lookups = array(
'acl_appname' => Select::app_options('installed')
);
if($selection['sel_options'])
{
$lookups += $selection['sel_options'];
unset($selection['sel_options']);
}
$selection = array_map("unserialize", array_unique(array_map("serialize", $selection)));
// $_record is an array, that's what search() returns
foreach ($selection as $_record)
{
$record = new admin_egw_acl_record($_record);
// Add in field for all ACLs
$all_acls = array();
foreach($record->get_record_array() as $key => $value)
{
if(strpos($key, '_') === FALSE && !in_array($key, array('id')))
{
$all_acls[] = $value;
}
}
if($options['convert'])
{
importexport_export_csv::convert($record, admin_egw_acl_record::$types, 'admin', $lookups);
}
else
{
// Implode arrays, so they don't say 'Array'
foreach($record->get_record_array() as $key => $value)
{
if(is_array($value)) $record->$key = implode(',', $value);
}
}
$record->all_acls = implode(',', $all_acls);
$export_object->export_record($record);
unset($record);
}
return $export_object;
}
/**
* returns translated name of plugin
*
* @return string name
*/
public static function get_name()
{
return lang('ACL CSV export');
}
/**
* returns translated (user) description of plugin
*
* @return string descriprion
*/
public static function get_description()
{
return lang("Exports permission settings into a CSV File. ");
}
/**
* returns file suffix for exported file
*
* @return string suffix
*/
public static function get_filesuffix()
{
return 'csv';
}
public static function get_mimetype()
{
return 'text/csv';
}
/**
* return html for options.
* this way the plugin has all opportunities for options tab
*
* @return string html
*/
public function get_options_etpl()
{
return false;
}
/**
* returns slectors of this plugin via xajax
*
*/
public function get_selectors_etpl()
{
return array(
'name' => 'importexport.export_csv_selectors',
'content' => array(
'selection' => 'all',
'no_search' => true
),
'sel_options' => array(
'acl_appname' => Select::app_options('installed')
),
'readonlys' => array(
// 'search' => true
)
//'preserv' => array('no_error_for_all'),
);
}
/**
* Get the class name for the egw_record to use while exporting
*
* @return string;
*/
public static function get_egw_record_class()
{
return 'admin_egw_acl_record';
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* EGroupware - Wizard for Groups CSV export
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package admin
* @subpackage importexport
* @link http://www.egroupware.org
* @author Nathan Gray
* @version $Id$
*/
use EGroupware\Api;
class admin_wizard_export_acl_csv extends importexport_wizard_basic_export_csv
{
public function __construct() {
parent::__construct();
// Field mapping
$this->export_fields = array(
'acl_account' => lang('Account'),
'acl_appname' => lang('Application'),
'acl_location' => lang('Data from'),
'all_acls' => lang('All ACLs'),
'acl1' => lang('Read'),
'acl2' => lang('Add'),
'acl4' => lang('Edit'),
'acl8' => lang('Delete'),
'acl16' => lang('Private'),
'acl64' => lang('Custom') .' 1',
'acl128' => lang('Custom') .' 2',
'acl256' => lang('Custom') .' 3',
);
// Custom fields - not possible for ACL
unset($this->export_fields['customfields']);
}
}

View File

@ -11,7 +11,7 @@
<row> <row>
<radio label="Use all" id="selection" options="all"/> <radio label="Use all" id="selection" options="all"/>
</row> </row>
<row> <row disabled="@no_search">
<radio label="Use search results" id="selection" options="search"/> <radio label="Use search results" id="selection" options="search"/>
</row> </row>
<row disabled="@no_filter"> <row disabled="@no_filter">