Skip to content

Commit

Permalink
enclose filter and login filters in brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
mind84 committed Oct 4, 2024
1 parent bd1a551 commit 4f3bac3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lizmap/modules/lizmap/lib/Project/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ public function getLoginFilters($layers, $edition = false)

$filters[$layerName] = array_merge(
(array) $loginFilteredConfig,
array('filter' => $filter, 'layername' => $lName)
array('filter' => '( '.$filter.' )', 'layername' => $lName)
);
}

Expand Down
4 changes: 2 additions & 2 deletions lizmap/modules/lizmap/lib/Request/WFSRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ public function parameters()
// Get client exp_filter parameter
$clientExpFilter = $this->param('exp_filter', '');
if (!empty($clientExpFilter)) {
$expFilters[] = $clientExpFilter;
$expFilters[] = '( '.$clientExpFilter.' )';
}

// Merge login filter
$attribute = '';
foreach ($loginFilters as $typename => $lfilter) {
$expFilters[] = $lfilter['filter'];
$expFilters[] = '( '.$lfilter['filter'].' )';
$attribute = $lfilter['filterAttribute'];
}

Expand Down
4 changes: 2 additions & 2 deletions lizmap/modules/lizmap/lib/Request/WMSRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ public function parameters()
$lname = trim($b[0]);
$lfilter = trim($b[1]);
if (array_key_exists($lname, $loginFilters)) {
$loginFilters[$lname]['filter'] .= ' AND '.$lfilter;
$loginFilters[$lname]['filter'] .= ' AND ( '.$lfilter.' )';
} else {
$loginFilters[$lname] = array('filter' => $lfilter, 'layername' => $lname);
$loginFilters[$lname] = array('filter' => '( '.$lfilter.' )', 'layername' => $lname);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions tests/units/classes/Project/ProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,16 @@ public static function getFiltersData()
'userIsConnected' => false,
);
//$filter1 = '"descr" IN ( \'admin\' , \'groups\' , \'lizmap\' , \'all\' )';
$filter1 = '"descr" = \'admin\' OR "descr" LIKE \'admin,%\' OR "descr" LIKE \'%,admin\' OR "descr" LIKE \'%,admin,%\'';
$filter1 = '( "descr" = \'admin\' OR "descr" LIKE \'admin,%\' OR "descr" LIKE \'%,admin\' OR "descr" LIKE \'%,admin,%\'';
$filter1 .= ' OR ';
$filter1 .= '"descr" = \'groups\' OR "descr" LIKE \'groups,%\' OR "descr" LIKE \'%,groups\' OR "descr" LIKE \'%,groups,%\'';
$filter1 .= ' OR ';
$filter1 .= '"descr" = \'lizmap\' OR "descr" LIKE \'lizmap,%\' OR "descr" LIKE \'%,lizmap\' OR "descr" LIKE \'%,lizmap,%\'';
$filter1 .= ' OR ';
$filter1 .= '"descr" = \'all\' OR "descr" LIKE \'all,%\' OR "descr" LIKE \'%,all\' OR "descr" LIKE \'%,all,%\'';
$filter1 .= '"descr" = \'all\' OR "descr" LIKE \'all,%\' OR "descr" LIKE \'%,all\' OR "descr" LIKE \'%,all,%\' )';

//$filter2 = '"Group" = \'all\'';
$filter2 = '"descr" = \'all\' OR "descr" LIKE \'all,%\' OR "descr" LIKE \'%,all\' OR "descr" LIKE \'%,all,%\'';
$filter2 = '( "descr" = \'all\' OR "descr" LIKE \'all,%\' OR "descr" LIKE \'%,all\' OR "descr" LIKE \'%,all,%\' )';

return array(
array($aclData1, $filter1),
Expand Down Expand Up @@ -338,8 +338,8 @@ public static function getFiltersDataNotMultiple()
$aclData2 = array(
'userIsConnected' => false,
);
$filter1 = '"descr" = \'admin\' OR "descr" = \'groups\' OR "descr" = \'lizmap\' OR "descr" = \'all\'';
$filter2 = '"descr" = \'all\'';
$filter1 = '( "descr" = \'admin\' OR "descr" = \'groups\' OR "descr" = \'lizmap\' OR "descr" = \'all\' )';
$filter2 = '( "descr" = \'all\' )';

return array(
array($aclData1, $filter1),
Expand Down
4 changes: 2 additions & 2 deletions tests/units/classes/Request/WFSRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function getParametersWithFiltersData()
'map' => null,
'Lizmap_User' => '',
'Lizmap_User_Groups' => '',
'exp_filter' => 'filter AND test',
'exp_filter' => '( filter ) AND ( test )',
);

$params2 = array(
Expand All @@ -60,7 +60,7 @@ public static function getParametersWithFiltersData()
'map' => null,
'Lizmap_User' => '',
'Lizmap_User_Groups' => '',
'exp_filter' => 'testParam AND filter AND test',
'exp_filter' => '( testParam ) AND ( filter ) AND ( test )',
'propertyname' => 'prop,test attr'
);
return array(
Expand Down

0 comments on commit 4f3bac3

Please sign in to comment.