- Hide expert options until they get worked out

- Add caching function has_definitions() to see if there are any definitions for the user
- Fix permissions check
This commit is contained in:
Nathan Gray 2011-01-28 19:44:24 +00:00
parent 87e96aa122
commit bd28fed482
3 changed files with 50 additions and 15 deletions

View File

@ -83,18 +83,12 @@ class importexport_definitions_bo {
* @return bool
*/
static public function is_permitted($_definition) {
$allowed_user = explode(',',$_definition['allowed_users']);
$this_user_id = $GLOBALS['egw_info']['user']['userid'];
$this_membership = $GLOBALS['egw']->accounts->membership($this_user_id);
$this_membership[] = array('account_id' => $this_user_id);
//echo $this_user_id;
//echo ' '.$this_membership;
foreach ((array)$this_membership as $account)
{
$this_membership_array[] = $account['account_id'];
}
$alluser = array_intersect($allowed_user,$this_membership_array);
return in_array($this_user_id,$alluser) ? true : false;
$allowed_user = is_array($_definition['allowed_users']) ? $_definition['allowed_users'] : explode(',',$_definition['allowed_users']);
$this_user_id = $GLOBALS['egw_info']['user']['account_id'];
$this_membership = $GLOBALS['egw']->accounts->memberships($this_user_id, true);
$this_membership[] = $this_user_id;
$alluser = array_intersect($allowed_user,$this_membership);
return count($alluser) > 0 ? true : false;
}
/**

View File

@ -80,7 +80,7 @@ class importexport_export_ui {
$content['definition'] = end($sel_options['definition']);
}
unset($definitions);
$sel_options['definition']['expert'] = lang('Expert options');
//$sel_options['definition']['expert'] = lang('Expert options');
if(isset($_definition) && array_key_exists($_definition,$sel_options['definition'])) {
$content['definition'] = $_definition;

View File

@ -316,8 +316,8 @@ class importexport_helper_functions {
$appnames = $_appname == 'all' ? array_keys($GLOBALS['egw_info']['apps']) : (array)$_appname;
$types = $_type == 'all' ? array('import','export') : (array)$_type;
foreach($plugins as $appname => $types) {
if(!in_array($appname, $appnames)) unset($plugins['appname']);
foreach($plugins as $appname => $_types) {
if(!in_array($appname, $appnames)) unset($plugins[$appname]);
}
foreach($plugins as $appname => $types) {
$plugins[$appname] = array_intersect_key($plugins[$appname], $types);
@ -378,4 +378,45 @@ class importexport_helper_functions {
public static function guess_filetype( $_file ) {
}
/**
* returns if the given app has importexport definitions for the current user
*
* @param string $_appname {<appname> | all}
* @param string $_type {import | export | all}
* @return boolean
*/
public static function has_definitions( $_appname = 'all', $_type = 'all' ) {
$definitions = egw_cache::getSession(
__CLASS__,
'has_definitions',
array('importexport_helper_functions','_has_definitions'),
array(array_keys($GLOBALS['egw_info']['apps']), array('import', 'export')),
self::CACHE_EXPIRATION
);
$appnames = $_appname == 'all' ? array_keys($GLOBALS['egw_info']['apps']) : (array)$_appname;
$types = $_type == 'all' ? array('import','export') : (array)$_type;
foreach($definitions as $appname => $_types) {
if(!in_array($appname, $appnames)) unset($definitions[$appname]);
}
foreach($definitions as $appname => $_types) {
$definitions[$appname] = array_intersect_key($definitions[$appname], array_flip($types));
}
return count($definitions[$appname]) > 0;
}
// egw_cache needs this public
public static function _has_definitions(Array $appnames, Array $types) {
$def = new importexport_definitions_bo(array('application'=>$appnames, 'type' => $types));
$list = array();
foreach($def->get_definitions() as $id) {
$definition = new importexport_definition($id);
if($def->is_permitted($definition->get_record_array())) {
$list[$definition->application][$definition->type] = $id;
}
$definition = null;
}
return $list;
}
} // end of importexport_helper_functions