2013-08-26 20:25:43 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2013-09-02 11:19:49 +02:00
|
|
|
* EGroupware: Admin ACL
|
2013-08-26 20:25:43 +02:00
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <rb@stylite.de>
|
|
|
|
* @package admin
|
2016-02-25 09:42:33 +01:00
|
|
|
* @copyright (c) 2013-16 by Ralf Becker <rb@stylite.de>
|
2013-08-26 20:25:43 +02:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2016-04-27 21:12:20 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
use EGroupware\Api\Framework;
|
|
|
|
use EGroupware\Api\Acl;
|
|
|
|
use EGroupware\Api\Etemplate;
|
|
|
|
|
2013-08-26 20:25:43 +02:00
|
|
|
/**
|
2014-03-12 13:49:28 +01:00
|
|
|
* UI for admin ACL
|
2013-08-28 14:52:47 +02:00
|
|
|
*
|
2014-03-12 13:49:28 +01:00
|
|
|
* Will also be extended by preferences_acl for user ACL
|
2013-08-26 20:25:43 +02:00
|
|
|
*/
|
|
|
|
class admin_acl
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Methods callable via menuaction
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $public_functions = array(
|
|
|
|
'index' => true,
|
|
|
|
);
|
|
|
|
|
2013-09-04 11:48:18 +02:00
|
|
|
/**
|
2016-04-27 21:12:20 +02:00
|
|
|
* Reference to global Acl class (instanciated for current user)
|
2013-09-04 11:48:18 +02:00
|
|
|
*
|
2016-04-27 21:12:20 +02:00
|
|
|
* @var Acl
|
2013-09-04 11:48:18 +02:00
|
|
|
*/
|
|
|
|
protected $acl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->acl = $GLOBALS['egw']->acl;
|
|
|
|
}
|
|
|
|
|
2013-08-28 14:52:47 +02:00
|
|
|
/**
|
|
|
|
* Save run rights and refresh opener
|
|
|
|
*
|
|
|
|
* @param array $content
|
|
|
|
*/
|
2013-09-04 11:48:18 +02:00
|
|
|
protected function save_run_rights(array $content)
|
2013-08-28 14:52:47 +02:00
|
|
|
{
|
2013-09-04 11:48:18 +02:00
|
|
|
$old_apps = array_keys($this->acl->get_user_applications($content['acl_account'], false, false));
|
2013-08-28 14:52:47 +02:00
|
|
|
// add new apps
|
|
|
|
$added_apps = array_diff($content['apps'], $old_apps);
|
|
|
|
foreach($added_apps as $app)
|
2013-08-27 19:58:38 +02:00
|
|
|
{
|
2013-09-04 11:48:18 +02:00
|
|
|
$this->acl->add_repository($app, 'run', $content['acl_account'], 1);
|
2013-08-27 19:58:38 +02:00
|
|
|
}
|
2013-08-28 14:52:47 +02:00
|
|
|
// remove no longer checked apps
|
|
|
|
$removed_apps = array_diff($old_apps, $content['apps']);
|
|
|
|
$deleted_ids = array();
|
|
|
|
foreach($removed_apps as $app)
|
|
|
|
{
|
2013-09-04 11:48:18 +02:00
|
|
|
$this->acl->delete_repository($app, 'run', $content['acl_account']);
|
2013-08-28 14:52:47 +02:00
|
|
|
$deleted_ids[] = $app.':'.$content['acl_account'].':run';
|
|
|
|
}
|
|
|
|
//error_log(__METHOD__."() apps=".array2string($content['apps']).", old_apps=".array2string($old_apps).", added_apps=".array2string($added_apps).", removed_apps=".array2string($removed_apps));
|
2013-08-27 19:58:38 +02:00
|
|
|
|
2013-08-28 14:52:47 +02:00
|
|
|
if (!$added_apps && !$removed_apps)
|
2013-08-27 19:58:38 +02:00
|
|
|
{
|
2013-08-28 14:52:47 +02:00
|
|
|
// nothing changed --> nothing to do/notify
|
2013-08-27 19:58:38 +02:00
|
|
|
}
|
2013-08-28 14:52:47 +02:00
|
|
|
elseif (!$old_apps)
|
2013-08-27 19:58:38 +02:00
|
|
|
{
|
2016-04-27 21:12:20 +02:00
|
|
|
Framework::refresh_opener(lang('ACL added.'), 'admin', null, 'add');
|
2013-08-27 19:58:38 +02:00
|
|
|
}
|
2013-08-28 14:52:47 +02:00
|
|
|
elseif (!$added_apps)
|
2013-08-27 19:58:38 +02:00
|
|
|
{
|
2016-04-27 21:12:20 +02:00
|
|
|
Framework::refresh_opener(lang('ACL deleted.'), 'admin', $deleted_ids, 'delete');
|
2013-08-27 19:58:38 +02:00
|
|
|
}
|
2013-08-28 14:52:47 +02:00
|
|
|
else
|
|
|
|
{
|
2016-04-27 21:12:20 +02:00
|
|
|
Framework::refresh_opener(lang('ACL updated.'), 'admin', null, 'edit');
|
2013-08-28 14:52:47 +02:00
|
|
|
}
|
|
|
|
}
|
2013-08-27 19:58:38 +02:00
|
|
|
|
2013-08-28 14:52:47 +02:00
|
|
|
/**
|
|
|
|
* Save rights and refresh opener
|
|
|
|
*
|
|
|
|
* @param array $content
|
|
|
|
*/
|
2013-09-04 11:48:18 +02:00
|
|
|
protected function save_rights(array $content)
|
2013-08-28 14:52:47 +02:00
|
|
|
{
|
|
|
|
// assamble rights again
|
|
|
|
$rights = (int)$content['preserve_rights'];
|
|
|
|
foreach($content['acl'] as $right)
|
|
|
|
{
|
|
|
|
$rights |= $right;
|
|
|
|
}
|
|
|
|
$id = !empty($content['id']) ? $content['id'] :
|
|
|
|
$content['acl_appname'].':'.$content['acl_account'].':'.$content['acl_location'];
|
|
|
|
//error_log(__METHOD__."() id=$id, acl=".array2string($content['acl'])." --> rights=$rights");
|
|
|
|
|
2013-09-04 11:48:18 +02:00
|
|
|
if ($this->acl->get_specific_rights_for_account($content['acl_account'], $content['acl_location'], $content['acl_appname']) == $rights)
|
2013-08-28 14:52:47 +02:00
|
|
|
{
|
|
|
|
// nothing changed --> nothing to do
|
|
|
|
}
|
|
|
|
elseif (!$rights) // all rights removed --> delete it
|
|
|
|
{
|
2013-09-04 11:48:18 +02:00
|
|
|
$this->acl->delete_repository($content['acl_appname'], $content['acl_location'], $content['acl_account']);
|
2016-04-27 21:12:20 +02:00
|
|
|
Framework::refresh_opener(lang('ACL deleted.'), 'admin', $id, 'delete');
|
2013-08-28 14:52:47 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-04 11:48:18 +02:00
|
|
|
$this->acl->add_repository($content['acl_appname'], $content['acl_location'], $content['acl_account'], $rights);
|
2013-08-28 14:52:47 +02:00
|
|
|
if ($content['id'])
|
|
|
|
{
|
2016-04-27 21:12:20 +02:00
|
|
|
Framework::refresh_opener(lang('ACL updated.'), 'admin', $id, 'edit');
|
2013-08-28 14:52:47 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-27 21:12:20 +02:00
|
|
|
Framework::refresh_opener(lang('ACL added.'), 'admin', $id, 'add');
|
2013-08-28 14:52:47 +02:00
|
|
|
}
|
|
|
|
}
|
2013-08-27 19:58:38 +02:00
|
|
|
}
|
|
|
|
|
2013-08-26 20:25:43 +02:00
|
|
|
/**
|
2016-04-27 21:12:20 +02:00
|
|
|
* Callback for nextmatch to fetch Acl
|
2013-08-26 20:25:43 +02:00
|
|
|
*
|
|
|
|
* @param array $query
|
|
|
|
* @param array &$rows=null
|
|
|
|
* @return int total number of rows available
|
|
|
|
*/
|
2014-03-03 17:51:37 +01:00
|
|
|
public static function get_rows(array $query, array &$rows=null)
|
2013-08-26 20:25:43 +02:00
|
|
|
{
|
2016-04-27 21:12:20 +02:00
|
|
|
$so_sql = new Api\Storage\Base('phpgwapi', Acl::TABLE, null, '', true);
|
2013-08-26 20:25:43 +02:00
|
|
|
|
2013-08-27 19:58:38 +02:00
|
|
|
// client queries destinct rows by their row-id
|
|
|
|
if (isset($query['col_filter']['id']))
|
2013-08-26 20:25:43 +02:00
|
|
|
{
|
2013-08-27 19:58:38 +02:00
|
|
|
$query['col_filter'][] = $GLOBALS['egw']->db->concat('acl_appname',"':'",'acl_account',"':'",'acl_location').
|
|
|
|
' IN ('.implode(',', array_map(array($GLOBALS['egw']->db, 'quote'), (array)$query['col_filter']['id'])).')';
|
|
|
|
unset($query['col_filter']['id']);
|
2013-08-26 20:25:43 +02:00
|
|
|
}
|
2013-08-27 19:58:38 +02:00
|
|
|
else
|
2013-08-26 20:25:43 +02:00
|
|
|
{
|
2013-08-27 19:58:38 +02:00
|
|
|
$memberships = $GLOBALS['egw']->accounts->memberships($query['account_id'], true);
|
|
|
|
$memberships[] = $query['account_id'];
|
2013-08-26 20:25:43 +02:00
|
|
|
|
2016-04-27 21:12:20 +02:00
|
|
|
Api\Cache::setSession(__CLASS__, 'state', array(
|
2013-08-27 19:58:38 +02:00
|
|
|
'account_id' => $query['account_id'],
|
|
|
|
'filter' => $query['filter'],
|
2013-09-04 11:48:18 +02:00
|
|
|
'acl_appname' => $query['filter2'],
|
2013-08-27 19:58:38 +02:00
|
|
|
));
|
2013-08-26 20:25:43 +02:00
|
|
|
|
2013-08-27 19:58:38 +02:00
|
|
|
if ($GLOBALS['egw_info']['user']['preferences']['admin']['acl_filter'] != $query['filter'])
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->preferences->add('admin', 'acl_filter', $query['filter']);
|
|
|
|
$GLOBALS['egw']->preferences->save_repository(false,'user',false);
|
|
|
|
}
|
|
|
|
switch($query['filter'])
|
|
|
|
{
|
|
|
|
case 'run':
|
|
|
|
$query['col_filter']['acl_location'] = 'run';
|
2013-09-04 11:48:18 +02:00
|
|
|
$query['col_filter']['acl_account'] = $memberships;
|
2013-08-27 19:58:38 +02:00
|
|
|
break;
|
2013-09-04 11:48:18 +02:00
|
|
|
default:
|
2013-09-02 11:19:49 +02:00
|
|
|
case 'other':
|
2013-08-27 19:58:38 +02:00
|
|
|
//$query['col_filter'][] = "acl_location!='run'";
|
|
|
|
// remove everything not an account-id in location, like category based acl
|
2016-12-01 12:59:53 +01:00
|
|
|
if (substr($GLOBALS['egw']->db->Type, 0, 5) == 'mysql')
|
2013-08-27 19:58:38 +02:00
|
|
|
{
|
|
|
|
$query['col_filter'][] = "acl_location REGEXP '^-?[0-9]+$'";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$query['col_filter'][] = "acl_location SIMILAR TO '-?[0-9]+'";
|
|
|
|
}
|
2013-09-04 11:48:18 +02:00
|
|
|
// get apps not using group-acl (eg. Addressbook) or using it only partialy (eg. InfoLog)
|
2016-04-27 21:12:20 +02:00
|
|
|
$not_enum_group_acls = Api\Hooks::process('not_enum_group_acls', array(), true);
|
2013-09-04 11:48:18 +02:00
|
|
|
//error_log(__METHOD__."(filter=$query[filter]) not_enum_group_acl=".array2string($not_enum_group_acls));
|
|
|
|
if ($not_enum_group_acls)
|
2013-08-27 19:58:38 +02:00
|
|
|
{
|
2013-09-04 11:48:18 +02:00
|
|
|
$sql = '(CASE acl_appname';
|
|
|
|
foreach($not_enum_group_acls as $app => $groups)
|
|
|
|
{
|
2014-03-27 19:58:44 +01:00
|
|
|
if ($groups === true)
|
|
|
|
{
|
|
|
|
$check = $query['account_id'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$check = array_diff($memberships, $groups);
|
|
|
|
//error_log(__METHOD__."() app=$app, array_diff(memberships=".array2string($memberships).", groups=".array2string($groups).")=".array2string($check));
|
|
|
|
if (!$check) continue; // would give sql error otherwise!
|
|
|
|
}
|
2016-04-27 21:12:20 +02:00
|
|
|
$sql .= ' WHEN '.$GLOBALS['egw']->db->quote($app).' THEN '.$GLOBALS['egw']->db->expression(Acl::TABLE, array(
|
2014-03-27 19:58:44 +01:00
|
|
|
'acl_account' => $check,
|
2013-09-04 11:48:18 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
$sql .= ' ELSE ';
|
2013-08-27 19:58:38 +02:00
|
|
|
}
|
2016-04-27 21:12:20 +02:00
|
|
|
$sql .= $GLOBALS['egw']->db->expression(Acl::TABLE, array(
|
2013-09-04 11:48:18 +02:00
|
|
|
'acl_account' => $memberships,
|
|
|
|
));
|
|
|
|
if ($not_enum_group_acls) $sql .= ' END)';
|
|
|
|
$query['col_filter'][] = $sql;
|
2013-08-27 19:58:38 +02:00
|
|
|
break;
|
2013-08-26 20:25:43 +02:00
|
|
|
|
2013-09-02 11:19:49 +02:00
|
|
|
case 'own':
|
2013-09-04 11:48:18 +02:00
|
|
|
$query['col_filter']['acl_location'] = $memberships;
|
2013-08-27 19:58:38 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// do NOT list group-memberships and other non-ACL stuff here
|
2013-09-04 11:48:18 +02:00
|
|
|
$query['col_filter']['acl_appname'] = $query['filter2'];
|
2013-08-27 19:58:38 +02:00
|
|
|
if (empty($query['col_filter']['acl_appname']) && $query['filter'] != 'run')
|
|
|
|
{
|
|
|
|
//$query['col_filter'][] = "NOT acl_appname IN ('phpgw_group','sqlfs')";
|
|
|
|
$query['col_filter']['acl_appname'] = array_keys($query['acl_rights']);
|
|
|
|
}
|
|
|
|
}
|
2014-03-03 17:51:37 +01:00
|
|
|
$readonlys = array();
|
2013-08-27 19:58:38 +02:00
|
|
|
$total = $so_sql->get_rows($query, $rows, $readonlys);
|
2013-08-26 20:25:43 +02:00
|
|
|
|
2014-03-03 17:51:37 +01:00
|
|
|
foreach($rows as &$row)
|
2013-08-26 20:25:43 +02:00
|
|
|
{
|
|
|
|
// generate a row-id
|
2013-08-27 19:58:38 +02:00
|
|
|
$row['id'] = $row['acl_appname'].':'.$row['acl_account'].':'.$row['acl_location'];
|
2013-08-26 20:25:43 +02:00
|
|
|
|
2013-08-28 14:52:47 +02:00
|
|
|
if ($row['acl_location'] == 'run')
|
2013-08-26 20:25:43 +02:00
|
|
|
{
|
|
|
|
$row['acl1'] = lang('run');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-27 21:12:20 +02:00
|
|
|
if ($app !== $row['acl_appname']) Api\Translation::add_app($row['app_name']);
|
2013-08-27 19:58:38 +02:00
|
|
|
foreach($query['acl_rights'][$row['acl_appname']] as $val => $label)
|
2013-08-26 20:25:43 +02:00
|
|
|
{
|
|
|
|
if ($row['acl_rights'] & $val)
|
|
|
|
{
|
|
|
|
$row['acl'.$val] = lang($label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-02 11:19:49 +02:00
|
|
|
if (!self::check_access($row['acl_account'], $row['acl_location'], false)) // false: do NOT throw an exception!
|
2013-08-27 19:58:38 +02:00
|
|
|
{
|
|
|
|
$row['class'] = 'rowNoEdit';
|
|
|
|
}
|
|
|
|
//error_log(__METHOD__."() $n: ".array2string($row));
|
2013-08-26 20:25:43 +02:00
|
|
|
}
|
2013-08-27 19:58:38 +02:00
|
|
|
//error_log(__METHOD__."(".array2string($query).") returning ".$total);
|
2014-06-25 12:47:26 +02:00
|
|
|
|
2015-09-16 01:59:31 +02:00
|
|
|
// Get supporting or all apps for filter2 depending on filter
|
|
|
|
if($query['filter'] == 'run')
|
|
|
|
{
|
|
|
|
$rows['sel_options']['filter2'] = array(
|
|
|
|
'' => lang('All applications'),
|
2016-05-05 19:59:31 +02:00
|
|
|
)+Etemplate\Widget\Select::app_options('enabled');
|
2015-09-16 01:59:31 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$rows['sel_options']['filter2'] = array(
|
|
|
|
array('value' => '', 'label' => lang('All applications'))
|
|
|
|
);
|
2016-04-27 21:12:20 +02:00
|
|
|
$apps = Api\Hooks::process(array(
|
2015-09-16 01:59:31 +02:00
|
|
|
'location' => 'acl_rights',
|
|
|
|
'owner' => $query['account_id'],
|
|
|
|
), array(), true);
|
2016-02-25 09:42:33 +01:00
|
|
|
foreach(array_keys($apps) as $appname)
|
2015-09-16 01:59:31 +02:00
|
|
|
{
|
|
|
|
$rows['sel_options']['filter2'][] = array(
|
|
|
|
'value' => $appname,
|
|
|
|
'label' => lang($appname)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
usort($rows['sel_options']['filter2'], function($a,$b) {
|
|
|
|
return strcasecmp($a['label'], $b['label']);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-08-26 20:25:43 +02:00
|
|
|
return $total;
|
|
|
|
}
|
|
|
|
|
2013-08-27 19:58:38 +02:00
|
|
|
/**
|
|
|
|
* Check if current user has access to ACL setting of a given location
|
|
|
|
*
|
2013-09-02 11:19:49 +02:00
|
|
|
* @param int $account_id numeric account-id
|
2016-02-25 09:42:33 +01:00
|
|
|
* @param int|string $location =null numeric account-id or "run"
|
|
|
|
* @param boolean $throw =true if true, throw an exception if no access, instead of just returning false
|
2013-08-27 19:58:38 +02:00
|
|
|
* @return boolean true if access is granted, false if notification_bo
|
2016-04-27 21:12:20 +02:00
|
|
|
* @throws Api\Exception\NoPermission
|
2013-08-27 19:58:38 +02:00
|
|
|
*/
|
2013-09-02 11:19:49 +02:00
|
|
|
public static function check_access($account_id, $location=null, $throw=true)
|
2013-08-27 19:58:38 +02:00
|
|
|
{
|
2014-03-03 17:51:37 +01:00
|
|
|
static $admin_access=null;
|
|
|
|
static $own_access=null;
|
2013-08-27 19:58:38 +02:00
|
|
|
if (is_null($admin_access))
|
|
|
|
{
|
|
|
|
$admin_access = isset($GLOBALS['egw_info']['user']['apps']['admin']) &&
|
|
|
|
!$GLOBALS['egw']->acl->check('account_access', 64, 'admin'); // ! because this denies access!
|
|
|
|
$own_access = $admin_access || isset($GLOBALS['egw_info']['user']['apps']['preferences']);
|
|
|
|
}
|
2014-09-18 15:53:34 +02:00
|
|
|
if (!(int)$account_id || !((int)$account_id == (int)$GLOBALS['egw_info']['user']['account_id'] && $location !== 'run' ?
|
|
|
|
$own_access : $admin_access))
|
2013-08-27 19:58:38 +02:00
|
|
|
{
|
2016-04-27 21:12:20 +02:00
|
|
|
if ($throw) throw new Api\Exception\NoPermission(lang('Permission denied!!!'));
|
2013-08-27 19:58:38 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-04-30 17:20:32 +02:00
|
|
|
/**
|
|
|
|
* Get the list of applications allowed for the given user
|
|
|
|
*
|
|
|
|
* The list of applications is added to the json response
|
|
|
|
*
|
|
|
|
* @param int $account_id
|
|
|
|
*/
|
|
|
|
public static function ajax_get_app_list($account_id)
|
|
|
|
{
|
|
|
|
$list = array();
|
|
|
|
if(self::check_access((int)$account_id,'run',false))
|
|
|
|
{
|
|
|
|
$list = array_keys($GLOBALS['egw']->acl->get_user_applications((int)$account_id,false,false));
|
|
|
|
}
|
2016-04-27 21:12:20 +02:00
|
|
|
Api\Json\Response::get()->data($list);
|
2014-04-30 17:20:32 +02:00
|
|
|
}
|
|
|
|
|
2013-08-27 19:58:38 +02:00
|
|
|
/**
|
|
|
|
* Change (add, modify, delete) an ACL entry
|
|
|
|
*
|
|
|
|
* Checks access and throws an exception, if a change is attempted without proper access
|
|
|
|
*
|
|
|
|
* @param string|array $ids "$app:$account:$location" string used as row-id in list
|
2016-02-25 09:42:33 +01:00
|
|
|
* @param int $rights =null null to delete, or new rights
|
2016-04-27 21:12:20 +02:00
|
|
|
* @throws Api\Exception\NoPermission
|
2013-08-27 19:58:38 +02:00
|
|
|
*/
|
|
|
|
public static function ajax_change_acl($ids, $rights=null)
|
|
|
|
{
|
2014-09-18 15:53:34 +02:00
|
|
|
try {
|
|
|
|
foreach((array)$ids as $id)
|
|
|
|
{
|
|
|
|
list($app, $account_id, $location) = explode(':', $id, 3);
|
2013-08-27 19:58:38 +02:00
|
|
|
|
2014-09-18 15:53:34 +02:00
|
|
|
self::check_access($account_id, $location); // throws exception, if no rights
|
2013-08-27 19:58:38 +02:00
|
|
|
|
2014-09-18 15:53:34 +02:00
|
|
|
$acl = $GLOBALS['egw']->acl;
|
2014-06-25 12:47:26 +02:00
|
|
|
|
2014-09-18 15:53:34 +02:00
|
|
|
if (!(int)$rights) // this also handles taking away all rights as delete
|
|
|
|
{
|
|
|
|
$acl->delete_repository($app, $location, $account_id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$acl->add_repository($app, $location, $account_id, $rights);
|
|
|
|
}
|
2013-08-27 19:58:38 +02:00
|
|
|
}
|
2014-09-18 15:53:34 +02:00
|
|
|
if (!(int)$rights)
|
2013-08-27 19:58:38 +02:00
|
|
|
{
|
2014-09-18 15:53:34 +02:00
|
|
|
if (count($ids) > 1)
|
|
|
|
{
|
|
|
|
$msg = lang('%1 ACL entries deleted.', count($ids));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$msg = lang('ACL entry deleted.');
|
|
|
|
}
|
2013-08-27 19:58:38 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-09-18 15:53:34 +02:00
|
|
|
$msg = lang('ACL updated');
|
2013-08-27 19:58:38 +02:00
|
|
|
}
|
2016-04-27 21:12:20 +02:00
|
|
|
Api\Json\Response::get()->data(array(
|
2014-09-18 15:53:34 +02:00
|
|
|
'msg' => $msg,
|
|
|
|
'ids' => $ids,
|
|
|
|
'type' => !(int)$rights ? 'delete' : 'add',
|
|
|
|
));
|
2013-08-27 19:58:38 +02:00
|
|
|
}
|
2014-09-18 15:53:34 +02:00
|
|
|
catch (Exception $e) {
|
2016-04-27 21:12:20 +02:00
|
|
|
Api\Json\Response::get()->call('egw.message', $e->getMessage(), 'error');
|
2013-08-27 19:58:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-26 20:25:43 +02:00
|
|
|
/**
|
|
|
|
* New index page
|
|
|
|
*
|
2016-02-25 09:42:33 +01:00
|
|
|
* @param array $_content =null
|
2013-08-26 20:25:43 +02:00
|
|
|
*/
|
2016-02-25 09:42:33 +01:00
|
|
|
public function index(array $_content=null)
|
2013-08-26 20:25:43 +02:00
|
|
|
{
|
2016-02-25 09:42:33 +01:00
|
|
|
unset($_content); // not used, required by function signature
|
|
|
|
|
2016-04-27 21:12:20 +02:00
|
|
|
$tpl = new Etemplate('admin.acl');
|
2013-08-26 20:25:43 +02:00
|
|
|
|
|
|
|
$content = array();
|
2014-03-03 17:51:37 +01:00
|
|
|
$account_id = isset($_GET['account_id']) && (int)$_GET['account_id'] ?
|
|
|
|
(int)$_GET['account_id'] : $GLOBALS['egw_info']['user']['account_id'];
|
2013-08-26 20:25:43 +02:00
|
|
|
$content['nm'] = array(
|
|
|
|
'get_rows' => 'admin_acl::get_rows',
|
|
|
|
'no_cat' => true,
|
2013-09-04 11:48:18 +02:00
|
|
|
'filter' => !empty($_GET['acl_filter']) ? $_GET['acl_filter'] :
|
2013-10-02 18:29:08 +02:00
|
|
|
($GLOBALS['egw_info']['flags']['currentapp'] != 'admin' ? 'other' :
|
|
|
|
$GLOBALS['egw_info']['user']['preferences']['admin']['acl_filter']),
|
2013-09-04 11:48:18 +02:00
|
|
|
'filter2' => !empty($_GET['acl_app']) ? $_GET['acl_app'] : '',
|
2013-08-26 20:25:43 +02:00
|
|
|
'lettersearch' => false,
|
2013-09-04 11:48:18 +02:00
|
|
|
'order' => 'acl_appname',
|
2013-08-26 20:25:43 +02:00
|
|
|
'sort' => 'ASC',
|
|
|
|
'row_id' => 'id',
|
2014-03-03 17:51:37 +01:00
|
|
|
'account_id' => $account_id,
|
2013-08-26 20:25:43 +02:00
|
|
|
'actions' => self::get_actions(),
|
2016-04-27 21:12:20 +02:00
|
|
|
'acl_rights' => Api\Hooks::process(array(
|
2013-08-27 19:58:38 +02:00
|
|
|
'location' => 'acl_rights',
|
2014-03-03 17:51:37 +01:00
|
|
|
'owner' => $account_id,
|
2013-08-27 19:58:38 +02:00
|
|
|
), array(), true),
|
2013-08-26 20:25:43 +02:00
|
|
|
);
|
2016-04-27 21:12:20 +02:00
|
|
|
$user = Api\Accounts::username($content['nm']['account_id']);
|
2013-08-26 20:25:43 +02:00
|
|
|
$sel_options = array(
|
|
|
|
'filter' => array(
|
2013-09-04 11:48:18 +02:00
|
|
|
'other' => lang('Access to %1 data by others', $user),
|
|
|
|
'own' => lang('%1 access to other data', $user),
|
|
|
|
'run' => lang('%1 run rights for applications', $user),
|
2015-09-16 01:59:31 +02:00
|
|
|
)
|
2013-08-26 20:25:43 +02:00
|
|
|
);
|
2016-02-25 09:42:33 +01:00
|
|
|
|
|
|
|
$tpl->exec('admin.admin_acl.index', $content, $sel_options, array(), array(), 2);
|
2013-08-26 20:25:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get actions for ACL
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
static function get_actions()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'edit' => array(
|
2013-09-02 11:19:49 +02:00
|
|
|
'caption' => 'Edit',
|
2013-08-26 20:25:43 +02:00
|
|
|
'default' => true,
|
|
|
|
'allowOnMultiple' => false,
|
2014-09-18 17:01:08 +02:00
|
|
|
'disableClass' => 'rowNoEdit',
|
2013-08-27 19:58:38 +02:00
|
|
|
'onExecute' => 'javaScript:app.admin.acl',
|
2013-08-26 20:25:43 +02:00
|
|
|
),
|
|
|
|
'add' => array(
|
2013-09-02 11:19:49 +02:00
|
|
|
'caption' => 'Add',
|
2014-09-18 17:01:08 +02:00
|
|
|
'disableClass' => 'rowNoEdit',
|
2013-08-27 19:58:38 +02:00
|
|
|
'onExecute' => 'javaScript:app.admin.acl',
|
2013-08-26 20:25:43 +02:00
|
|
|
),
|
|
|
|
'delete' => array(
|
2013-09-02 11:19:49 +02:00
|
|
|
'confirm' => 'Delete this access control',
|
|
|
|
'caption' => 'Delete',
|
2013-08-26 20:25:43 +02:00
|
|
|
'disableClass' => 'rowNoEdit',
|
2013-08-27 19:58:38 +02:00
|
|
|
'onExecute' => 'javaScript:app.admin.acl',
|
2013-08-26 20:25:43 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|