TASK: Remove custom filter for fe group filtering

As this didn't work on first use. Also no tests are available for this
feature yet.

As we remove the whole feature in a single commit, we can revert this
commit later. This way we can upgrade Elasticsearch and provide this
feature later on.
This commit is contained in:
Daniel Siepmann 2018-12-29 17:59:23 +01:00
parent 6f34ca273b
commit 9c2db0b5ba
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
9 changed files with 0 additions and 254 deletions

View file

@ -66,9 +66,6 @@ class PagesIndexer extends TcaIndexer
{
parent::prepareRecord($record);
// Override access from parent rootline
$record['search_access'] = $this->fetchAccess($record['uid'], (array)$record['search_access']);
$possibleTitleFields = ['nav_title', 'tx_tqseo_pagetitle_rel', 'title'];
foreach ($possibleTitleFields as $searchTitleField) {
if (isset($record[$searchTitleField]) && trim($record[$searchTitleField])) {
@ -140,41 +137,6 @@ class PagesIndexer extends TcaIndexer
return $this->fetchSysFileReferenceUids($uid, 'pages', 'media');
}
protected function fetchAccess(int $uid, array $pageAccess): array
{
try {
$rootline = $this->objectManager->get(RootlineUtility::class, $uid)->get();
} catch (\RuntimeException $e) {
$this->logger->notice(
sprintf('Could not fetch rootline for page %u, because: %s', $uid, $e->getMessage()),
[$pageAccess, $e]
);
return $pageAccess;
}
$access = [$pageAccess];
$extended = false;
foreach ($rootline as $pageInRootLine) {
if ($pageInRootLine['extendToSubpages'] && (!empty($pageInRootLine['fe_group']))) {
$extended = true;
$access[] = GeneralUtility::intExplode(
',',
$pageInRootLine['fe_group'],
true
);
}
}
// Return combined rootline extended access and return unique id's
$access = array_unique(array_merge(...$access));
// Remove public value if fe_group is extended to this page
if ($extended && ($key = array_search(0, $access, true)) !== false) {
unset($access[$key]);
}
return array_values($access);
}
protected function fetchSysFileReferenceUids(int $uid, string $tablename, string $fieldname): array
{
$imageRelationUids = [];

View file

@ -146,19 +146,6 @@ class TcaTableService implements TcaTableServiceInterface
if (isset($record[$this->tca['ctrl']['label']]) && !isset($record['search_title'])) {
$record['search_title'] = $record[$this->tca['ctrl']['label']];
}
if (isset(
$this->tca['ctrl']['enablecolumns']['fe_group'],
$record[$this->tca['ctrl']['enablecolumns']['fe_group']]
)) {
$groups = GeneralUtility::intExplode(
',',
$record[$this->tca['ctrl']['enablecolumns']['fe_group']],
true
);
// Always fallback on public visibility when configured
$record['search_access'] = !empty($groups) ? $groups : [0];
}
}
protected function getWhereClause(): Where

View file

@ -1,74 +0,0 @@
<?php
namespace Codappix\SearchCore\Domain\Search\Filter;
/*
* Copyright (C) 2018 Benjamin Serfhos <benjamin@serfhos.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
/**
* Filter: FrontendUserAccess
*/
class FrontendUserAccessFilter implements SearchFilterInterface
{
public function add(array $query, array $config, $value): array
{
return $this->addAccessFilter($query, $value);
}
/**
* Add simple boolean lookup for filtering on access groups
*/
protected function addAccessFilter(array $query, string $field): array
{
$query['query']['bool']['must'][] = [
'terms' => [$field => $this->getUserGroups()]
];
return $query;
}
/**
* Get inherited user groups from logged in user or simulated user
*/
protected function getUserGroups(): array
{
$feUser = $this->getFrontendUserAuthentication();
if ($feUser !== null) {
// If groups is not yet rendered, make sure the group data are fetched
if (!isset($feUser->groupData['uid'])) {
$feUser->fetchGroupData();
}
$values = $feUser->groupData['uid'];
if (!empty($values)) {
// Add public content with values
return array_merge([0], $values);
}
}
// Fallback on public content
return [0];
}
protected function getFrontendUserAuthentication(): FrontendUserAuthentication
{
return $GLOBALS['TSFE']->fe_user ?? null;
}
}

View file

@ -1,26 +0,0 @@
<?php
namespace Codappix\SearchCore\Domain\Search\Filter;
/*
* Copyright (C) 2018 Benjamin Serfhos <benjamin@serfhos.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
class InvalidSearchFilterException extends \InvalidArgumentException
{
}

View file

@ -1,33 +0,0 @@
<?php
namespace Codappix\SearchCore\Domain\Search\Filter;
/*
* Copyright (C) 2018 Benjamin Serfhos <benjamin@serfhos.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
interface SearchFilterInterface
{
/**
* @param array $query
* @param array $config
* @param mixed $value
* @return array Adjusted $query
*/
public function add(array $query, array $config, $value): array;
}

View file

@ -25,8 +25,6 @@ use Codappix\SearchCore\Configuration\ConfigurationContainerInterface;
use Codappix\SearchCore\Configuration\ConfigurationUtility;
use Codappix\SearchCore\Configuration\InvalidArgumentException;
use Codappix\SearchCore\Connection\SearchRequestInterface;
use Codappix\SearchCore\Domain\Search\Filter\InvalidSearchFilterException;
use Codappix\SearchCore\Domain\Search\Filter\SearchFilterInterface;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
@ -252,18 +250,6 @@ class QueryFactory
return $query;
}
if ($config['custom'] && $config['type'] === 'custom') {
$customFilter = $this->objectManager->get($config['custom']);
if (!($customFilter instanceof SearchFilterInterface)) {
throw new InvalidSearchFilterException(
'Custom filter (' . $config['custom'] . ') not instance of SearchFilterInterface',
1539876182018
);
}
return $customFilter->add($query, $config, $value);
}
$filter = [];
if (isset($config['fields'])) {
foreach ($config['fields'] as $elasticField => $inputField) {

View file

@ -36,19 +36,6 @@ plugin.tx_searchcore {
# Default query fields (leave empty for all)
query =
}
filter {
frontendUserAccess = search_access
}
mapping {
filter {
frontendUserAccess {
type = custom
custom = Codappix\SearchCore\Domain\Search\Filter\FrontendUserAccessFilter
}
}
}
}
}
}

View file

@ -1,14 +0,0 @@
Feature "Added frontend user authentication access"
===================================================
Indexation added based on page access via ``fe_group`` and inherited
from ```extendToSubpages```.
The searching is added via typoscript using the UserFunc filter::
frontendUserAccess {
type = custom
custom = Codappix\SearchCore\Domain\Search\Filter\FrontendUserAccessFilter
}
To bypass this filter simply unset default filter in searching.filter

View file

@ -1,29 +0,0 @@
Feature "Manipulate search filter"
==================================
You can manipulate the filter via a custom class through the ``custom`` type typoscript
mapping.::
plugin.tx_searchcore.settings.searching {
mapping {
filter {
frontendUserAccess {
type = custom
custom = Codappix\SearchCore\Domain\Search\Filter\FrontendUserAccessFilter
}
}
}
}
If you want to force this filter on searching make sure to define them as default filters like:::
plugin.tx_searchcore.settings.searching {
filter {
frontendUserAccess = search_access
}
}
Example
-------
See ``Codappix\SearchCore\Domain\Search\Filter\FrontendUserAccessFilter`` as example.