17 include_once (
'Class.DbObj.php');
18 include_once (
'Class.QueryDb.php');
19 include_once (
'Class.Application.php');
20 include_once (
'Class.Action.php');
21 include_once (
'Class.Acl.php');
22 include_once (
'Class.User.php');
23 include_once (
'Class.Group.php');
41 private $upprivileges =
false;
42 private $unprivileges =
false;
43 private $gprivileges =
false;
45 create table permission (id_user int not null,
46 id_application int not null,
48 computed boolean default false);
49 create index permission_idx1 on permission(id_user);
50 create index permission_idx2 on permission(id_application);
51 create index permission_idx3 on permission(id_acl);
52 create index permission_idx4 on permission(computed);
66 if ($id && $id[0] && $id[1]) {
73 if (is_array($id) && $id[0] && $id[1]) {
76 "id_application" => $id[1],
77 "computed" => (!empty($id[2]))
103 if ($this->
Exists($this->id_user, $this->id_application, $this->id_acl))
return "Permission ({$this->id_user},{$this->id_application},{$this->id_acl}) already exists...";
109 if (!$this->computed) {
110 $this->
exec_query(sprintf(
"delete from permission where id_application=%d and abs(id_acl)=%d and computed", $this->id_application, abs($this->id_acl)));
124 $query->basic_elem->sup_where = array(
125 "id_user='{$user->id}'",
126 "id_application='{$app->id}'"
131 while ($i < $query->nb) {
141 $query->basic_elem->sup_where = array(
142 "id_user='{$user->id}'"
148 while ($i < $query->nb) {
149 $this->log->debug(
"ListUserApplicaion");
159 $query->basic_elem->sup_where = array(
160 "id_application='{$app->id}'"
166 while ($i < $query->nb) {
173 function Exists($userid, $applicationid, $aclid = 0)
176 $query->basic_elem->sup_where = array(
177 "id_application='$applicationid'",
178 "id_user='{$userid}'",
179 "( computed = FALSE OR computed IS NULL )"
183 $query->AddQuery(
"(id_acl={$aclid}) OR (id_acl= {$naclid}) ");
185 $query->Query(0, 0,
"TABLE");
193 $query->basic_elem->sup_where = array(
194 "id_application='{$application->id}'",
195 "id_user='{$user->id}'"
198 if (
$query->nb == 0)
return FALSE;
199 $aclu =
new Acl($this->dbaccess,
$list[0]->id_acl);
200 return ($aclu->grant_level >= $acl->grant_level);
206 $query->basic_elem->sup_where = array(
207 "id_application='{$application->id}'",
208 "id_user='{$user->id}'"
211 if (
$query->nb == 0)
return (0);
212 $acl =
new Acl($this->dbaccess,
$list[0]->id_acl);
213 return ($acl->grant_level);
219 $query->basic_elem->sup_where = array(
223 $this->log->debug(
"DEL APP PERM");
228 foreach (
$list as $v) {
232 $this->log->debug(
"NO PERM");
240 if ($this->upprivileges ===
false) {
243 return $this->upprivileges;
250 if ($this->unprivileges ===
false) {
253 return $this->unprivileges;
260 if ($this->gprivileges ===
false) {
263 return $this->gprivileges;
271 $query->basic_elem->sup_where = array(
272 "id_application = '" .
$appid .
"'"
277 foreach (
$res as $v) {
290 $query->basic_elem->sup_where = array(
291 "id_application = '" .
$appid .
"'",
292 "id_user = '" . $uid .
"'",
295 $computedAcl = array();
298 foreach (
$list as $v) {
299 $computedAcl[abs($v->id_acl) ] = $v->id_acl;
303 foreach ($allAclList as $acl) {
304 if (!array_key_exists($acl, $computedAcl)) {
308 return array_values($computedAcl);
317 $db->exec_query(sprintf(
"SELECT computePerm(%d, %d, %d)", $uid,
$appid, abs($acl)));
318 $perm =
$db->fetch_array(0);
319 return $perm[
'computeperm'];
340 $this->privileges = array();
341 $this->upprivileges = array();
342 $this->unprivileges = array();
343 $this->gprivileges = array();
345 $ugroup =
new Group($this->dbaccess, $this->id_user);
347 foreach ($ugroup->groups as $gid) {
349 $gperm =
new permission($this->dbaccess, array(
351 $this->id_application,
355 foreach ($gperm->privileges as $gacl) {
356 if (!in_array($gacl, $this->privileges)) {
357 $this->gprivileges[] = $gacl;
358 $this->privileges[] = $gacl;
364 $query->basic_elem->sup_where = array(
365 "id_application='{$this->id_application}'",
366 "id_user='{$this->id_user}'",
367 (!
$computed) ?
"( computed = FALSE OR computed IS NULL )" :
"true"
371 foreach (
$list as $v) {
372 if ($v->id_acl > 0) {
374 $this->upprivileges[] = $v->id_acl;
375 if (!in_array($v->id_acl, $this->privileges)) {
376 $this->privileges[] = $v->id_acl;
380 $this->unprivileges[] = - ($v->id_acl);
382 $nk = array_search(-($v->id_acl) , $this->privileges,
false);
383 if (is_integer($nk)) {
384 unset($this->privileges[$nk]);
390 return ($this->privileges);
400 $grant = (($this->id_user == 1) ||
401 (in_array($idacl, $this->privileges)));
402 if ($grant)
return true;
413 $u =
new Account($this->dbaccess, $this->id_user);
414 $incumbents = $u->getIncumbents();
415 foreach ($incumbents as $aIncumbent) {
418 $this->id_application
420 $grant = $p->hasPrivilege($idacl,
true);
421 if ($grant)
return true;
432 $this->id_application =
$appid;
434 $acl =
new Acl($this->dbaccess);
435 if ($acl->Set($aclname, $this->id_application)) {
436 $this->id_acl = $acl->id;
450 $this->actions = array();
454 if (!count($acls))
return array();
456 $sSql =
" select distinct action.name from action inner join acl on
457 action.acl = acl.name where ";
458 $sSql.=
" action.id_application = '" . $this->id_application .
"' AND ";
459 $sSql.=
" acl.id in ('" . implode(
"','", $acls) .
"')";
461 $res = pg_query($this->dbid, $sSql);
464 while ($arr = pg_fetch_array(
$res, $i)) {
465 $this->actions[] = $arr[0];
477 $sqlCond[] = sprintf(
"( id_user = %d )", pg_escape_string(
$id_user));
480 $sqlCond[] = sprintf(
"( id_application = %d )", pg_escape_string(
$id_application));
483 $sqlCond[] = sprintf(
"( abs(id_acl) = abs(%d) )", pg_escape_string(
$id_acl));
487 $sqlCond[] =
"( computed = TRUE )";
489 $sqlCond[] =
"( computed = FALSE OR computed IS NULL )";
493 if (count($sqlCond) > 0) {
494 return $this->
exec_query(sprintf(
"DELETE FROM permission WHERE ( %s )", join(
" AND ", $sqlCond)));
ListUserApplications($user)
hasPrivilege($idacl, $strict=false)
ListApplicationUsers($app)
exec_query($sql, $lvl=0, $prepare=false)
GetComputedPrivileges($uid, $appid)
Add($nopost=false, $nopre=false)
GrantLevel($user, $application)
getAllAclForApplication($appid)
IsOver($user, $application, $acl)
substituteHasPrivilege($idacl)
GetPrivileges($force=false, $computed=true)
AddUserPermission($appname, $aclname)
Exists($userid, $applicationid, $aclid=0)
__construct($dbaccess= '', $id= '', $res= '', $dbid=0, $computed=true)
if(($docid!==0)&&(!is_numeric($docid))) $query
computePerm($uid, $appid, $acl)
deletePermission($id_user=null, $id_application=null, $id_acl=null, $computed=null)
ListUserPermissions($user, $app)