Skip to content

Commit

Permalink
Fix groups isolation
Browse files Browse the repository at this point in the history
See Mibew#131 for details
  • Loading branch information
JustBlackBird committed Aug 5, 2015
1 parent 9d81661 commit 4c9f963
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
26 changes: 17 additions & 9 deletions src/mibew/libs/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,12 +517,15 @@ function get_all_groups()
function get_all_groups_for_operator($operator)
{
$db = Database::getInstance();
$query = "SELECT g.groupid AS groupid, g.parent, g.vclocalname, g.vclocaldescription "
$query = "SELECT DISTINCT g.groupid AS groupid, g.parent, g.vclocalname, g.vclocaldescription "
. "FROM {opgroup} g, "
. "(SELECT DISTINCT parent FROM {opgroup}, {operatortoopgroup} "
. "(SELECT {opgroup}.groupid, {opgroup}.parent FROM {opgroup}, {operatortoopgroup} "
. "WHERE {opgroup}.groupid = {operatortoopgroup}.groupid "
. "AND {operatortoopgroup}.operatorid = ?) i "
. "WHERE g.groupid = i.parent OR g.parent = i.parent "
. "WHERE g.groupid = i.parent "
. "OR g.parent = i.groupid "
. "OR (g.parent = i.parent AND g.parent IS NOT NULL) "
. "OR g.groupid = i.groupid "
. "ORDER BY vclocalname";

$groups = $db->query(
Expand Down Expand Up @@ -590,7 +593,7 @@ function get_groups_($check_away, $operator, $order = null)
$values = array(
':now' => time(),
);
$query = "SELECT {opgroup}.groupid AS groupid, "
$query = "SELECT DISTINCT {opgroup}.groupid AS groupid, "
. "{opgroup}.parent AS parent, "
. "vclocalname, vclocaldescription, iweight, "
. "(SELECT count(*) "
Expand All @@ -614,12 +617,14 @@ function get_groups_($check_away, $operator, $order = null)
. " FROM {opgroup} ";

if ($operator) {
$query .= ", (SELECT DISTINCT parent "
$query .= ", (SELECT {opgroup}.groupid, {opgroup}.parent "
. "FROM {opgroup}, {operatortoopgroup} "
. "WHERE {opgroup}.groupid = {operatortoopgroup}.groupid "
. "AND {operatortoopgroup}.operatorid = :operatorid) i "
. "WHERE {opgroup}.groupid = i.parent OR {opgroup}.parent = i.parent ";

. "WHERE {opgroup}.groupid = i.parent "
. "OR {opgroup}.parent = i.groupid "
. "OR ({opgroup}.parent = i.parent AND {opgroup}.parent IS NOT NULL) "
. "OR {opgroup}.groupid = i.groupid ";
$values[':operatorid'] = $operator['operatorid'];
}

Expand Down Expand Up @@ -675,10 +680,13 @@ function get_operators_from_adjacent_groups($operator)
. "WHERE {operator}.operatorid = {operatortoopgroup}.operatorid "
. "AND {operatortoopgroup}.groupid IN ("
. "SELECT g.groupid from {opgroup} g, "
. "(SELECT DISTINCT parent FROM {opgroup}, {operatortoopgroup} "
. "(SELECT {opgroup}.groupid, {opgroup}.parent FROM {opgroup}, {operatortoopgroup} "
. "WHERE {opgroup}.groupid = {operatortoopgroup}.groupid "
. "AND {operatortoopgroup}.operatorid = :operatorid) i "
. "WHERE g.groupid = i.parent OR g.parent = i.parent "
. "WHERE g.groupid = i.parent "
. "OR g.parent = i.groupid "
. "OR (g.parent = i.parent AND g.parent IS NOT NULL) "
. "OR g.groupid = i.groupid "
. ") ORDER BY vclogin";

return $db->query(
Expand Down
7 changes: 5 additions & 2 deletions src/mibew/libs/operator.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,13 @@ function get_operators_list($options = array())
. "WHERE {operator}.operatorid = {operatortoopgroup}.operatorid "
. "AND {operatortoopgroup}.groupid IN ("
. "SELECT g.groupid FROM {opgroup} g, "
. "(SELECT DISTINCT parent FROM {opgroup}, {operatortoopgroup} "
. "(SELECT {opgroup}.groupid, {opgroup}.parent FROM {opgroup}, {operatortoopgroup} "
. "WHERE {opgroup}.groupid = {operatortoopgroup}.groupid "
. "AND {operatortoopgroup}.operatorid = :operatorid) i "
. "WHERE g.groupid = i.parent OR g.parent = i.parent "
. "WHERE g.groupid = i.parent "
. "OR g.parent = i.groupid "
. "OR (g.parent = i.parent AND g.parent IS NOT NULL) "
. "OR g.groupid = i.groupid "
. ")")
. " ORDER BY " . $orderby;

Expand Down

0 comments on commit 4c9f963

Please sign in to comment.