X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttUser.class.php;h=6bac7cb468232b622ac728c9709e694ac346bb83;hb=280d6ea0ee096843551d7734b23377ec06d42e81;hp=b7ea34f07a6b7de9509b4f9dd9c1713b1702f79b;hpb=b134135b685422ddcdc2d6856972c60ea15f661f;p=timetracker.git diff --git a/WEB-INF/lib/ttUser.class.php b/WEB-INF/lib/ttUser.class.php index b7ea34f0..6bac7cb4 100644 --- a/WEB-INF/lib/ttUser.class.php +++ b/WEB-INF/lib/ttUser.class.php @@ -192,10 +192,11 @@ class ttUser { $result = array(); $mdb2 = getConnection(); + $group_id = $this->behalf_group_id ? $this->behalf_group_id : $this->group_id; // Do a query with inner join to get assigned projects. $sql = "select p.id, p.name, p.description, p.tasks, upb.rate from tt_projects p inner join tt_user_project_binds upb on (upb.user_id = ".$this->getActiveUser()." and upb.project_id = p.id and upb.status = 1) - where p.group_id = $this->group_id and p.status = 1 order by p.name"; + where p.group_id = $group_id and p.status = 1 order by p.name"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { while ($val = $res->fetchRow()) { @@ -429,13 +430,32 @@ class ttUser { } // checkBehalfId checks whether behalf_id is appropriate. - // On behalf user must be active and have lower rank. + // On behalf user must be active and have lower rank if the user is from home group, + // otherwise: + // - subgroup must ve valid; + // - user should be a member of it. function checkBehalfId() { - $options = array('status'=>ACTIVE,'max_rank'=>$this->rank-1); - $users = $this->getUsers($options); - foreach($users as $one_user) { - if ($one_user['id'] == $this->behalf_id) - return true; + if (!$this->behalf_group_id) { + // Checking user from home group. + $options = array('status'=>ACTIVE,'max_rank'=>$this->rank-1); + $users = $this->getUsers($options); + foreach($users as $one_user) { + if ($one_user['id'] == $this->behalf_id) + return true; + } + } else { + // Checking user from a subgroup. + $group_id = $this->behalf_group_id; + if (!$this->isSubgroupValid($group_id)) + return false; + + // So far, so good. Check user now. + $options = array('group_id'=>$group_id,'status'=>ACTIVE,'max_rank'=>MAX_RANK); + $users = $this->getUsers($options); + foreach($users as $one_user) { + if ($one_user['id'] == $this->behalf_id) + return true; + } } return false; } @@ -446,8 +466,13 @@ class ttUser { // Needed for situations when user does not have do_own_something right. // Example: has view_charts but does not have view_own_charts. // In this case we still allow access to charts, but set behalf_id to someone else. + // Another example: working in a subgroup on behalf of someone else. function adjustBehalfId() { - $options = array('status'=>ACTIVE,'max_rank'=>$this->rank-1); + $group_id = $this->behalf_group_id ? $this->behalf_group_id : $this->group_id; + $rank = $this->getMaxRankForGroup($group_id); + + // Adjust to first found user in group. + $options = array('group_id'=>$group_id,'status'=>ACTIVE,'max_rank'=>$rank); $users = $this->getUsers($options); foreach($users as $one_user) { // Fake loop to access first element.