Skip to content

Instantly share code, notes, and snippets.

@dfeyer
Created January 25, 2013 19:27
Show Gist options
  • Save dfeyer/4637101 to your computer and use it in GitHub Desktop.
Save dfeyer/4637101 to your computer and use it in GitHub Desktop.
<?php
namespace Ttree\Medialib\Core\Security;
/* *
* This script belongs to the FLOW3 package "Ttree.Medialib". *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License, either version 3 *
* of the License, or (at your option) any later version. *
* *
* The TYPO3 project - inspiring people to share! *
* */
use Doctrine\Common\Collections\ArrayCollection;
use TYPO3\Flow\Mvc\ActionRequest;
use TYPO3\Flow\Annotations as Flow;
use Ttree\Medialib\Core\Domain\Model\User;
use Ttree\Medialib\Core\Exception\RuntimeException;
/**
* @Flow\Aspect
*/
class DomainAffiliateAspect {
/**
* @var \TYPO3\Flow\Log\LoggerInterface A logger implementation
*/
protected $logger;
/**
* @param \TYPO3\Flow\Log\SystemLoggerInterface $systemLogger
*/
public function injectSystemLogger(\TYPO3\Flow\Log\SystemLoggerInterface $systemLogger) {
$this->logger = $systemLogger;
}
/**
* @Flow\Inject
* @var \TYPO3\Flow\Security\Context
*/
protected $securityContext;
/**
* @Flow\Inject
* @var \Ttree\Medialib\Core\Domain\Service\DomainService
*/
protected $domainService;
/**
* @Flow\Inject
* @var \TYPO3\Flow\Persistence\Doctrine\PersistenceManager
*/
protected $persistenceManager;
/**
* @Flow\Pointcut("evaluate(current.securityContext.roles contains ('UserManager')) && !evaluate(current.securityContext.roles contains ('Manager'))")
*/
public function basicUserManagerPointcut() {}
/**
* @Flow\Pointcut("method(Ttree\Medialib\Core\Domain\Model\Domain->getAffiliates())")
*/
public function getAffiliatesPointCut() {}
/**
* @Flow\Pointcut("Ttree\Medialib\Core\Security\DomainAffiliateAspect->basicUserManagerPointcut && Ttree\Medialib\Core\Security\DomainAffiliateAspect->getAffiliatesPointCut")
*/
public function filteredAffiliatedEntitiesPointcut() {}
/**
* @param \TYPO3\Flow\AOP\JoinPointInterface $joinPoint
* @return void
* @Flow\After("method(public Ttree\Medialib\Backoffice\Controller\UserController->(update|create|delete)Action())")
*/
public function updateDomainConfiguration(\TYPO3\Flow\AOP\JoinPointInterface $joinPoint) {
$this->persistenceManager->persistAll();
/** @var $domain \Ttree\Medialib\Core\Domain\Model\Domain */
$domain = $this->securityContext->getDomain();
$this->domainService->updateAttachedUser($domain);
$logMessage = sprintf('Domain (%s) attributed quota updated by method (%s) call in class (%s)', (string)$domain, $joinPoint->getMethodName(), $joinPoint->getClassName());
$this->logger->log($logMessage);
}
/**
* @param \TYPO3\Flow\AOP\JoinPointInterface $joinPoint
* @return \Doctrine\Common\Collections\Collection
* @Flow\Around("Ttree\Medialib\Core\Security\DomainAffiliateAspect->filteredAffiliatedEntitiesPointcut")
*/
public function getAffiliates(\TYPO3\Flow\AOP\JoinPointInterface $joinPoint) {
if (!$this->securityContext->getAccount()) {
return $joinPoint->getAdviceChain()->proceed($joinPoint);
}
/** @var $party User */
$party = $this->securityContext->getAccount()->getParty();
$domainAffiliates = $party->getDomainAffiliates();
if (!$domainAffiliates->count()) {
$domainAffiliates = new ArrayCollection();
$domainAffiliates->add($party->getMainDomainAffiliates());
}
return $domainAffiliates;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment