Commit cddfd0d4 authored by lphuberdeau's avatar lphuberdeau

[MRG] Automatic merge, branches/7.x 34402 to 34406

parent 96e6fc09
......@@ -121,4 +121,17 @@ class Perms_Accessor implements ArrayAccess
public function offsetExists( $name ) {
return true;
}
public function applicableGroups() {
if( $this->checkSequence ) {
$groups = array();
foreach( $this->checkSequence as $check ) {
$groups = array_merge( $groups, $check->applicableGroups( $this->resolver ) );
}
return array_unique($groups);
} else {
return $this->resolver->applicableGroups();
}
}
}
......@@ -8,4 +8,6 @@
interface Perms_Check
{
function check( Perms_Resolver $resolver, array $context, $name, array $groups );
function applicableGroups( Perms_Resolver $resolver );
}
......@@ -9,6 +9,7 @@ class Perms_Check_Alternate implements Perms_Check
{
private $permission;
private $resolver;
private $applicableCache = null;
function __construct( $permission ) {
$this->permission = $permission;
......@@ -24,5 +25,26 @@ class Perms_Check_Alternate implements Perms_Check
function setResolver( $resolver ) {
$this->resolver = $resolver;
$this->applicableCache = null;
}
function applicableGroups( Perms_Resolver $resolver ) {
if( ! is_null( $this->applicableCache ) ) {
return $this->applicableCache;
}
$this->applicableCache = array();
if ($this->resolver) {
$groups = $this->resolver->applicableGroups();
foreach( $groups as $group ) {
if( $this->resolver->check( $this->permission, array($group) ) ) {
$this->applicableCache[] = $group;
}
}
}
return $this->applicableCache;
}
}
......@@ -24,4 +24,8 @@ class Perms_Check_Creator implements Perms_Check
return false;
}
function applicableGroups( Perms_Resolver $resolver ) {
return $resolver->applicableGroups();
}
}
......@@ -10,4 +10,8 @@ class Perms_Check_Direct implements Perms_Check
function check( Perms_Resolver $resolver, array $context, $name, array $groups ) {
return $resolver->check( $name, $groups );
}
function applicableGroups( Perms_Resolver $resolver ) {
return $resolver->applicableGroups();
}
}
......@@ -25,4 +25,8 @@ class Perms_Check_Fixed implements Perms_Check
function setResolver( $resolver ) {
$this->resolver = $resolver;
}
function applicableGroups( Perms_Resolver $resolver ) {
return $this->resolver->applicableGroups();
}
}
......@@ -20,4 +20,8 @@ class Perms_Check_Indirect implements Perms_Check
return false;
}
}
function applicableGroups( Perms_Resolver $resolver ) {
return $resolver->applicableGroups();
}
}
......@@ -8,12 +8,10 @@
class Search_GlobalSource_PermissionSource implements Search_GlobalSource_Interface
{
private $perms;
private $additionalCheck;
function __construct(Perms $perms, $additionalCheck = array())
function __construct(Perms $perms)
{
$this->perms = $perms;
$this->additionalCheck = (array) $additionalCheck;
}
function getProvidedFields()
......@@ -94,12 +92,7 @@ class Search_GlobalSource_PermissionSource implements Search_GlobalSource_Interf
private function getCheckList($accessor)
{
$toCheck = $accessor->getResolver()->applicableGroups();
if (count($this->additionalCheck)) {
$toCheck = array_merge($toCheck, $this->additionalCheck);
$toCheck = array_unique($toCheck);
}
$toCheck = $accessor->applicableGroups();
return $toCheck;
}
......
......@@ -59,7 +59,6 @@ class Search_Index_Lucene implements Search_Index_Interface
function find(Search_Expr_Interface $query, Search_Query_Order $sortOrder, $resultStart, $resultCount)
{
$query = $this->buildQuery($query);
//echo 'FIND:'.$query;
$hits = $this->lucene->find($query, $this->getSortField($sortOrder), $this->getSortType($sortOrder), $this->getSortOrder($sortOrder));
$result = array();
......
......@@ -52,7 +52,10 @@ class QueueLib extends TikiDb_Bridge
// Strip duplicate messages
$messages = array_unique($messages);
return array_map('json_decode', $messages, array_fill(0, count($messages), true));
if (count($messages)) {
return array_map('json_decode', $messages, array_fill(0, count($messages), true));
} else {
} return array();
}
}
......@@ -210,10 +210,7 @@ class UnifiedSearchLib
}
if ($mode == 'indexing') {
$adminGroups = TikiDb::get()->table('users_grouppermissions')->fetchColumn('groupName', array(
'permName' => 'tiki_p_admin',
));
$aggregator->addGlobalSource(new Search_GlobalSource_PermissionSource(Perms::getInstance(), $adminGroups));
$aggregator->addGlobalSource(new Search_GlobalSource_PermissionSource(Perms::getInstance()));
}
}
......
......@@ -120,5 +120,38 @@ class Perms_AccessorTest extends TikiTestCase
$this->assertTrue( $accessor['tiki_p_view'] );
$this->assertFalse( $accessor['tiki_p_view_history'] );
}
function testApplicableGroupsInsideAccessor() {
$accessor = new Perms_Accessor;
$static = new Perms_Resolver_Static( array(
'Anonymous' => array( 'view' ),
'Registered' => array( 'view', 'edit' ),
) );
$accessor->setResolver($static);
$this->assertEquals(array('Anonymous', 'Registered'), $accessor->applicableGroups());
}
function testApplicableGroupsThroughCheckSequence() {
$accessor = new Perms_Accessor;
$static = new Perms_Resolver_Static( array(
'Anonymous' => array( 'view' ),
'Registered' => array( 'view', 'edit' ),
) );
$global = new Perms_Resolver_Static( array(
'Admins' => array( 'admin' ),
) );
$accessor->setResolver($static);
$accessor->setCheckSequence(array(
$g = new Perms_Check_Alternate('admin'),
new Perms_Check_Direct,
));
$g->setResolver($global);
$this->assertEquals(array('Admins', 'Anonymous', 'Registered'), $accessor->applicableGroups());
}
}
......@@ -98,42 +98,6 @@ class Search_GlobalSource_PermissionSourceTest extends PHPUnit_Framework_TestCas
$this->assertEquals($typeFactory->multivalue(array()), $document['allowed_groups']);
}
function testWithAdditionalGroup()
{
$contentSource = new Search_ContentSource_Static(array(
'HomePage' => array('view_permission' => 'tiki_p_view'),
), array('view_permission' => 'identifier'));
$this->globalAlternate->setResolver(new Perms_Resolver_Default(true));
$this->indexer->addGlobalSource(new Search_GlobalSource_PermissionSource($this->perms, 'Admins'));
$this->indexer->addContentSource('wiki page', $contentSource);
$this->indexer->rebuild();
$document = $this->index->getDocument(0);
$typeFactory = $this->index->getTypeFactory();
$this->assertEquals($typeFactory->multivalue(array('Anonymous', 'Registered', 'Admins')), $document['allowed_groups']);
}
function testWithMultipleAdditionalGroups()
{
$contentSource = new Search_ContentSource_Static(array(
'HomePage' => array('view_permission' => 'tiki_p_view'),
), array('view_permission' => 'identifier'));
$this->globalAlternate->setResolver(new Perms_Resolver_Default(true));
$this->indexer->addGlobalSource(new Search_GlobalSource_PermissionSource($this->perms, array('SubAdmins', 'Admins', 'Registered')));
$this->indexer->addContentSource('wiki page', $contentSource);
$this->indexer->rebuild();
$document = $this->index->getDocument(0);
$typeFactory = $this->index->getTypeFactory();
$this->assertEquals($typeFactory->multivalue(array('Anonymous', 'Registered', 'SubAdmins', 'Admins')), $document['allowed_groups']);
}
function testWithParentPermissionSpecified()
{
$contentSource = new Search_ContentSource_Static(array(
......
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