Commit 46841601 authored by alexpott's avatar alexpott

Issue #2540568 by Lendude, mikeyk, geertvd, DuaelFr, pjonckiere, dawehner:...

Issue #2540568 by Lendude, mikeyk, geertvd, DuaelFr, pjonckiere, dawehner: ManyToOne 'not' operator throws InvalidArgumentException ("Is none of" choice in UI)
parent bbc772ae
......@@ -94,11 +94,14 @@ public function getValueOptions() {
public function query() {
// @todo user_role_names() should maybe support multiple permissions.
$rids = array();
// Get all roles, that have the configured permissions.
// Get all role IDs that have the configured permissions.
foreach ($this->value as $permission) {
$roles = user_role_names(FALSE, $permission);
$rids += array_keys($roles);
// user_role_names() returns an array with the role IDs as keys, so take
// the array keys and merge them with previously found role IDs.
$rids = array_merge($rids, array_keys($roles));
}
// Remove any duplicate role IDs.
$rids = array_unique($rids);
$this->value = $rids;
......
......@@ -62,6 +62,31 @@ public function testFilterPermission() {
$this->assertIdenticalResultset($view, $expected, $column_map);
$view->destroy();
// Filter by not a permission.
$view->initHandlers();
$view->filter['permission']->operator = 'not';
$view->filter['permission']->value = array('administer users');
$this->executeView($view);
$this->assertEqual(count($view->result), 3);
$expected = array();
$expected[] = array('uid' => 1);
$expected[] = array('uid' => 2);
$expected[] = array('uid' => 3);
$this->assertIdenticalResultset($view, $expected, $column_map);
$view->destroy();
// Filter by not multiple permissions, that are present in multiple roles.
$view->initHandlers();
$view->filter['permission']->operator = 'not';
$view->filter['permission']->value = array('administer users', 'administer permissions');
$this->executeView($view);
$this->assertEqual(count($view->result), 2);
$expected = array();
$expected[] = array('uid' => 1);
$expected[] = array('uid' => 2);
$this->assertIdenticalResultset($view, $expected, $column_map);
$view->destroy();
// Filter by another permission of a role with multiple permissions.
$view->initHandlers();
$view->filter['permission']->value = array('administer users');
......
......@@ -236,7 +236,7 @@ public function ensureMyTable() {
$join = $this->getJoin();
$join->type = 'LEFT';
$join->extra = array();
$join->extra_type = 'OR';
$join->extraOperator = 'OR';
foreach ($this->handler->value as $value) {
$join->extra[] = array(
'field' => $this->handler->realField,
......@@ -311,10 +311,21 @@ public function addFilter() {
$placeholder = $this->placeholder();
if (count($this->handler->value) > 1) {
$placeholder .= '[]';
$this->handler->query->addWhereExpression(0, "$field $operator($placeholder)", array($placeholder => $value));
if ($operator == 'IS NULL') {
$this->handler->query->addWhereExpression(0, "$field $operator");
}
else {
$this->handler->query->addWhereExpression(0, "$field $operator($placeholder)", array($placeholder => $value));
}
}
else {
$this->handler->query->addWhereExpression(0, "$field $operator $placeholder", array($placeholder => $value));
if ($operator == 'IS NULL') {
$this->handler->query->addWhereExpression(0, "$field $operator");
}
else {
$this->handler->query->addWhereExpression(0, "$field $operator $placeholder", array($placeholder => $value));
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment