Skip to content

Commit

Permalink
Merge pull request #80 from pixelant/2.3_dev
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
Andriy Oprysko authored Mar 31, 2020
2 parents 484afab + c9ad3b8 commit a77e1be
Show file tree
Hide file tree
Showing 37 changed files with 683 additions and 82 deletions.
139 changes: 120 additions & 19 deletions Classes/Controller/AdministrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
use Pixelant\PxaSocialFeed\Domain\Model\Configuration;
use Pixelant\PxaSocialFeed\Domain\Model\Feed;
use Pixelant\PxaSocialFeed\Domain\Model\Token;
use Pixelant\PxaSocialFeed\Domain\Repository\AbstractBackendRepository;
use Pixelant\PxaSocialFeed\Domain\Repository\BackendUserGroupRepository;
use Pixelant\PxaSocialFeed\Domain\Repository\ConfigurationRepository;
use Pixelant\PxaSocialFeed\Domain\Repository\FeedRepository;
use Pixelant\PxaSocialFeed\Domain\Repository\TokenRepository;
use Pixelant\PxaSocialFeed\Service\Task\ImportFeedsTaskService;
use Pixelant\PxaSocialFeed\Utility\ConfigurationUtility;
use TYPO3\CMS\Backend\Routing\UriBuilder as BackendUriBuilder;
use TYPO3\CMS\Backend\View\BackendTemplateView;
use TYPO3\CMS\Core\Messaging\FlashMessage;
Expand All @@ -18,6 +22,7 @@
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
use TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

/***************************************************************
Expand Down Expand Up @@ -66,6 +71,11 @@ class AdministrationController extends ActionController
*/
protected $feedRepository = null;

/**
* @var BackendUserGroupRepository
*/
protected $backendUserGroupRepository = null;

/**
* BackendTemplateContainer
*
Expand All @@ -80,6 +90,15 @@ class AdministrationController extends ActionController
*/
protected $defaultViewObjectName = BackendTemplateView::class;

/**
* @param BackendUserGroupRepository $backendUserGroupRepository
*/
public function __construct(BackendUserGroupRepository $backendUserGroupRepository)
{
parent::__construct();
$this->backendUserGroupRepository = $backendUserGroupRepository;
}

/**
* @param ConfigurationRepository $configurationRepository
*/
Expand Down Expand Up @@ -148,13 +167,14 @@ protected function initializeView(ViewInterface $view): void
*/
public function indexAction($activeTokenTab = false): void
{
$tokens = $this->tokenRepository->findAll();
$tokens = $this->findAllByRepository($this->tokenRepository);

$this->view->assignMultiple([
'tokens' => $tokens,
'configurations' => $this->configurationRepository->findAll(),
'configurations' => $this->findAllByRepository($this->configurationRepository),
'activeTokenTab' => $activeTokenTab,
'isTokensValid' => $this->isTokensValid($tokens)
'isTokensValid' => $this->isTokensValid($tokens),
'isAdmin' => $GLOBALS['BE_USER']->isAdmin(),
]);
}

Expand All @@ -180,6 +200,7 @@ public function editTokenAction(Token $token = null, int $type = Token::FACEBOOK
}

$this->view->assignMultiple(compact('token', 'type', 'isNew', 'availableTypes'));
$this->assignBEGroups();
}

/**
Expand All @@ -194,7 +215,7 @@ public function updateTokenAction(Token $token): void

$this->tokenRepository->{$isNew ? 'add' : 'update'}($token);

$this->redirectToIndex(true, $this->translate('action_changes_saved'));
$this->redirectToIndexTokenTab($this->translate('action_changes_saved'));
}

/**
Expand All @@ -207,7 +228,7 @@ public function resetAccessTokenAction(Token $token): void
$token->setAccessToken('');
$this->tokenRepository->update($token);

$this->redirectToIndex(true);
$this->redirectToIndexTokenTab();
}

/**
Expand All @@ -223,11 +244,10 @@ public function deleteTokenAction(Token $token): void
if ($tokenConfigurations->count() === 0) {
$this->tokenRepository->remove($token);

$this->redirectToIndex(true, $this->translate('action_delete'));
$this->redirectToIndexTokenTab($this->translate('action_delete'));
}

$this->redirectToIndex(
true,
$this->redirectToIndexTokenTab(
$this->translate('error_token_configuration_exist', [$tokenConfigurations->getFirst()->getName()]),
FlashMessage::ERROR
);
Expand All @@ -241,9 +261,10 @@ public function deleteTokenAction(Token $token): void
*/
public function editConfigurationAction(Configuration $configuration = null): void
{
$tokens = $this->tokenRepository->findAll();
$tokens = $this->findAllByRepository($this->tokenRepository);

$this->view->assignMultiple(compact('configuration', 'tokens'));
$this->assignBEGroups();
}

/**
Expand Down Expand Up @@ -272,7 +293,7 @@ public function updateConfigurationAction(Configuration $configuration): void
$this->redirect('editConfiguration', null, null, ['configuration' => $configuration]);
}

$this->redirectToIndex(false, $this->translate('action_changes_saved'));
$this->redirectToIndex($this->translate('action_changes_saved'));
}

/**
Expand All @@ -292,7 +313,57 @@ public function deleteConfigurationAction(Configuration $configuration): void

$this->configurationRepository->remove($configuration);

$this->redirectToIndex(false, $this->translate('action_delete'));
$this->redirectToIndex($this->translate('action_delete'));
}

/**
* Test run of import configuration
*
* @param Configuration $configuration
*/
public function runConfigurationAction(Configuration $configuration)
{
$importService = GeneralUtility::makeInstance(ImportFeedsTaskService::class);
$importService->import([$configuration->getUid()]);

$this->redirectToIndex($this->translate('single_import_end'));
}

/**
* Check if editor restriction feature is enabled
* If so find all with backend group access restriction
*
* @param AbstractBackendRepository $repository
* @return QueryResultInterface
*/
protected function findAllByRepository(AbstractBackendRepository $repository): QueryResultInterface
{
return ConfigurationUtility::isFeatureEnabled('editorRestriction')
? $repository->findAllBackendGroupRestriction()
: $repository->findAll();
}

/**
* Assign BE groups to template
* If admin all are available
*/
protected function assignBEGroups()
{
if (!ConfigurationUtility::isFeatureEnabled('editorRestriction')) {
return;
}

$excludeGroups = $this->getExcludeGroups();

if ($GLOBALS['BE_USER']->isAdmin()) {
$groups = $this->backendUserGroupRepository->findAll($excludeGroups);
} else {
$groups = array_filter($GLOBALS['BE_USER']->userGroups, function ($group) use ($excludeGroups) {
return !in_array($group['uid'], $excludeGroups);
});
}

$this->view->assign('beGroups', $groups);
}

/**
Expand Down Expand Up @@ -394,18 +465,33 @@ protected function getInlineSettings(): string
]);
}

/**
* Shortcut to redirect to index on tokens tab with flash message
*
* @param string|null $message
* @param int $severity
*/
protected function redirectToIndexTokenTab(string $message = null, int $severity = FlashMessage::OK)
{
if (!empty($message)) {
$this->addFlashMessage(
$message,
'',
$severity
);
}

$this->redirect('index', null, null, ['activeTokenTab' => true]);
}

/**
* Shortcut to redirect to index with flash message
*
* @param bool $activeTokenTab
* @param string $message
* @param string|null $message
* @param int $severity
*/
protected function redirectToIndex(
bool $activeTokenTab = false,
string $message = null,
int $severity = FlashMessage::OK
): void {
protected function redirectToIndex(string $message = null, int $severity = FlashMessage::OK)
{
if (!empty($message)) {
$this->addFlashMessage(
$message,
Expand All @@ -414,6 +500,21 @@ protected function redirectToIndex(
);
}

$this->redirect('index', null, null, ['activeTokenTab' => $activeTokenTab]);
$this->redirect('index');
}

/**
* Return exclude user group uids from ext configuration
*
* @return array
*/
protected function getExcludeGroups()
{
$configuration = ConfigurationUtility::getExtensionConfiguration();
if (isset($configuration['excludeBackendUserGroups'])) {
return GeneralUtility::intExplode(',', $configuration['excludeBackendUserGroups'], true);
}

return [];
}
}
65 changes: 65 additions & 0 deletions Classes/Database/Query/Restriction/BackendGroupRestriction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);

namespace Pixelant\PxaSocialFeed\Database\Query\Restriction;

use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression;
use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
use TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Restrict access by BE user group
*/
class BackendGroupRestriction implements QueryRestrictionInterface
{
/**
* @var string
*/
protected $groupFieldName = 'be_group';

/**
* @var BackendUserAuthentication|null
*/
protected $backendUserAuth = null;

/**
* Initialize
*/
public function __construct()
{
if (isset($GLOBALS['BE_USER'])) {
$this->backendUserAuth = $GLOBALS['BE_USER'];
}
}

/**
* @inheritDoc
*/
public function buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder): CompositeExpression
{
$constraints = [];
if ($this->backendUserAuth !== null && !$this->backendUserAuth->isAdmin()) {
foreach ($queriedTables as $tableAlias => $tableName) {
$fieldName = $tableAlias . '.' . $this->groupFieldName;
// Allow records where no group access has been configured (field values NULL, 0 or empty string)
$constraints = [
$expressionBuilder->isNull($fieldName),
$expressionBuilder->eq($fieldName, $expressionBuilder->literal('')),
$expressionBuilder->eq($fieldName, $expressionBuilder->literal('0')),
];

$backendGroupIds = GeneralUtility::intExplode(',', $this->backendUserAuth->groupList);
foreach ($backendGroupIds as $backendGroupId) {
$constraints[] = $expressionBuilder->inSet(
$fieldName,
$expressionBuilder->literal((string)$backendGroupId)
);
}
}
}

return $expressionBuilder->orX(...$constraints);
}
}
31 changes: 31 additions & 0 deletions Classes/Domain/Model/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
use TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;

/**
* Configuration
Expand Down Expand Up @@ -73,6 +74,36 @@ class Configuration extends AbstractEntity
*/
protected $token = null;

/**
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup>
* @lazy
*/
protected $beGroup= null;

/**
* Initialize
*/
public function __construct()
{
$this->beGroup = new ObjectStorage();
}

/**
* @return ObjectStorage
*/
public function getBeGroup(): ObjectStorage
{
return $this->beGroup;
}

/**
* @param ObjectStorage $beGroup
*/
public function setBeGroup(ObjectStorage $beGroup): void
{
$this->beGroup = $beGroup;
}

/**
* @return string
*/
Expand Down
Loading

1 comment on commit a77e1be

@NamelessCoder
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • NamelessCoder\GizzleGitPlugins\GizzlePlugins\ClonePlugin:00000000409a3b01000000006e38cae8:
    • 0: Executing Git clone command: /usr/bin/git clone --depth 1 --single-branch --branch 'v2.3.0' 'https://github.com/pixelant/pxa_social_feed.git' /tmp/a77e1bee0d4f07edf77a0d59a542be57d3284b81/pxa_social_feed
    • NamelessCoder\TYPO3RepositoryGizzle\GizzlePlugins\ExtensionRepositoryReleasePlugin:00000000409a3b1f000000006e38cae8:
      • resultCode: 10504
      • resultMessages:
        • 0: Please note that it might take a while (up to an hour) until your extension and the documentation appear on TYPO3.org.
        • version: 2.3.0

Please sign in to comment.