[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] api/class.acl_mgr.php, 1.1.2.9
From: |
nomail |
Subject: |
[Phpgroupware-cvs] api/class.acl_mgr.php, 1.1.2.9 |
Date: |
Tue, 6 Jul 2004 09:23:58 +0200 |
Update of /api
Modified Files:
Branch: proposal-branch
class.acl_mgr.php
date: 2004/07/06 07:23:58; author: jengo; state: Exp; lines: +202 -5
Log Message:
Initial work to ACL, more info is in the wiki journal
=====================================================================
Index: api/class.acl_mgr.php
diff -u api/class.acl_mgr.php:1.1.2.8 api/class.acl_mgr.php:1.1.2.9
--- api/class.acl_mgr.php:1.1.2.8 Sat May 8 07:43:24 2004
+++ api/class.acl_mgr.php Tue Jul 6 07:23:58 2004
@@ -25,25 +25,29 @@
/* $Source$ */
$functions = array();
- $functions['api_acl_mgr'] = array(
+ $functions['api_acl_mgr'] = array
+ (
'type' => 'public',
'abstract' => 'ACL manager',
'discussion' => 'ACL manager'
);
- $functions['account'] = array(
+ $functions['account'] = array
+ (
'type' => 'public',
'title' => 'Account ACL manager',
'abstract' => 'ACL manager for accounts'
);
- $functions['record'] = array(
+ $functions['record'] = array
+ (
'type' => 'public',
'title' => 'Record ACL manager',
'abstract' => 'ACL manager for records'
);
- $GLOBALS['docs']['api']['classes']['api_acl_mgr'] = array(
+ $GLOBALS['docs']['api']['classes']['api_acl_mgr'] = array
+ (
'abstract' => 'ACL management',
'functions' => $functions
);
@@ -55,6 +59,199 @@
$GLOBALS['phpgw']->add_xsl('api.acl_mgr');
}
+ function __acl_total($acl_args)
+ {
+ $total = 0;
+ foreach ($acl_args as $acl)
+ {
+ $total += $acl;
+ }
+
+ return $total;
+ }
+
+ function __create_text($total)
+ {
+ // safeargs has a problem with sending arrays, they get
casted to a string
+ // Until thats fixed, no safeargs is used here
+
+ //$args = new safe_args();
+ //$args->set('acl_args',REQUIRED,'array');
+ //extract($args->get(func_get_args()));
+
+ // FIXME: This needs to handle ALL the ACL types, the
basics are added for now
+ if ($total & PHPGW_ACL_READ)
+ {
+ $text[] = lang('Read');
+ }
+
+ if ($total & PHPGW_ACL_EDIT)
+ {
+ $text[] = lang('Edit');
+ }
+
+ if ($total & PHPGW_ACL_DELETE)
+ {
+ $text[] = lang('Delete');
+ }
+
+ return $text;
+ }
+
+ // This function is only to help developers cheat with safeargs.
+ // Instead of specifying each parameter needed for ACL
management
+ // Just call this one and it will do the rest.
+ // example:
+ // $args = new safe_args();
+ // ...
+ // ...
+ // $acl_mgr = createObject('api_acl_mgr');
+ // $acl_mgr->handle_safe_args(&$args);
+ // $args->set('subject',NOTSET,'any',60);
+ // $args = $args->get(func_get_args());
+ function _handle_safe_args(&$args)
+ {
+ $args->set('acl_add',NOTSET,'any');
+ $args->set('acl_remove',NOTSET,'any');
+ $args->set('acl_add_user_id',0,'number');
+ $args->set('acl_allow',array(),'any');
+ $args->set('acl_deny',array(),'any');
+ }
+
+ function _handle_request()
+ {
+ $args = new safe_args();
+ $args->set('location',REQUIRED,'alphanumeric');
+ $args->set('args',REQUIRED,'array');
+ $args->set('result',REQUIRED,'array');
+ extract($args->get(func_get_args()));
+
+ $result['acl_list'] =
$_SESSION['phpgw_session']['phpgw_data']['statecache'][$location . ':acl'];
+ $result['acl_accounts'] =
$GLOBALS['phpgw']->accounts->list_repository(array('list_current_user' =>
false));
+ $result['acl_location'] = $args['location'];
+
+ if ($args['acl_add'])
+ {
+ $allow_total = 0;
+ $deny_total = 0;
+
+ $allow_total =
$this->__acl_total($args['acl_allow']);
+ $deny_total =
$this->__acl_total($args['acl_deny']);
+
+ //html_print_r($args['acl_allow']);
+ //trigger_error("Allow total: " .
$allow_total,E_USER_NOTICE);
+
+ $allow_text =
$this->__create_text($allow_total);
+ $deny_text =
$this->__create_text($deny_total);
+
+ // If you have edit or delete, you need to have
read
+ // FIXME: This needs to handle ALL the ACL
types, the basics are added for now
+ /*
+ if ($allow_total & PHPGW_ACL_EDIT ||
$allow_total & PHPGW_ACL_DELETE && $allow_total ^ PHPGW_ACL_READ)
+ {
+ $allow_total += PHPGW_ACL_READ;
+ $allow_text[] = lang('Read');
+
+ $deny_total -= PHPGW_ACL_READ;
+ $i =
array_search(lang('Read'),$deny_text);
+ array_splice($deny_text,$i,1);
+ }*/
+
+ // TODO: Test for duplicates and remove
+
+ // XMLtool will crap out if you use the user_id
as the index
+ $result['acl_list'][] = array
+ (
+ 'acl_user_id' =>
$args['acl_add_user_id'],
+ 'acl_user' =>
execMethod('api.prefs._display_account_fullname',$args['acl_add_user_id']),
+ 'allow' => @implode(',
',$allow_text),
+ 'deny' => @implode(',
',$deny_text),
+ 'allow_values' => $args['acl_allow'],
+ 'deny_values' => $args['acl_deny'],
+ 'allow_total' => $allow_total,
+ 'deny_total' => $deny_total
+ );
+
+
$_SESSION['phpgw_session']['phpgw_data']['statecache'][$location . ':acl'] =
$result['acl_list'];
+ }
+ else if ($args['acl_remove'])
+ {
+
array_splice($_SESSION['phpgw_session']['phpgw_data']['statecache'][$location .
':acl'],$args['acl_remove'] - 1,1);
+
array_merge($_SESSION['phpgw_session']['phpgw_data']['statecache'][$location .
':acl']);
+
+ $result['acl_list'] =
$_SESSION['phpgw_session']['phpgw_data']['statecache'][$location . ':acl'];
+ }
+
+ return $result;
+ }
+
+ // safeargs is presently pretty broke when passing arrays
(jengo)
+ function _handle_view($location,$result)
+ {
+ //$args = new safe_args();
+ //$args->set('location',REQUIRED,'alphanumeric');
+ //$args->set('result',REQUIRED,'any');
+ //extract($args->get(func_get_args()));
+
+ $acl_items =
$GLOBALS['phpgw']->acl->_get_location($location);
+
+ if (is_array($acl_items))
+ {
+ foreach ($acl_items as $i => $acl_item)
+ {
+ $result['acl_list'][] = array
+ (
+ 'acl_id' =>
$acl_item['acl_id'],
+ 'acl_user_id' =>
$acl_item['acl_account'],
+ 'acl_user' =>
execMethod('api.prefs._display_account_fullname',$acl_item['acl_account']),
+ 'acl_rights' =>
$acl_item['acl_rights'],
+ 'allow' => @implode(',
',$this->__create_text($acl_item['acl_rights']))
+ //'deny' => @implode(',
',$this->__create_text($acl_item['acl_rights'])),
+ );
+ }
+ }
+
+ return $result;
+ }
+
+ function _clear_cache()
+ {
+ $args = new safe_args();
+ $args->set('location',REQUIRED,'alphanumeric');
+ extract($args->get(func_get_args()));
+
+
unset($_SESSION['phpgw_session']['phpgw_data']['statecache'][$location .
':acl']);
+ }
+
+ // The location parameter is the location its stored in cache
+ // For example: tasks.base.create ... it will convert that to
tasks.base.4
+ function _set()
+ {
+ $args = new safe_args();
+ $args->set('location',REQUIRED,'alphanumeric');
+ $args->set('id',REQUIRED,'integer');
+ extract($args->get(func_get_args()));
+
+ // Convert location parameter
+ list($app,$class,$method) = explode('.',$location);
+ $acl_location =
sprintf('%s.%s.%s',$app,$class,$id);
+
+ $acl_id = $GLOBALS['phpgw']->db->genid('phpgw_acl_id');
+ if
(is_array($_SESSION['phpgw_session']['phpgw_data']['statecache'][$location .
':acl']))
+ {
+ foreach
($_SESSION['phpgw_session']['phpgw_data']['statecache'][$location . ':acl'] as
$acl)
+ {
+
$GLOBALS['phpgw']->acl->add($acl_location,$acl['allow_total'],0,1,NULL,$acl_id,$acl['acl_user_id']);
+ }
+
+ return $acl_id;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+
function account()
{
/*
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] api/class.acl_mgr.php, 1.1.2.9,
nomail <=