-
-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* master: Video thumbnail fix (#1179) [AdminBundle] fix regex to check if admin preview (#1182) Fix adminlist SimpleItemAction template [AdminListBundle] Updated list template to use an icon for the View link Fix translation (#1177) [AdminBundle] OAuthUserCreator Should query on username and email (#1154) [All bundle] Translation fixes (#1172) Added `update ACL command` to update specific role with given permission(s) for all nodes [ArticleBundle] Added ability to select which overview page to add an article page to (#1160)
- Loading branch information
Showing
41 changed files
with
561 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
namespace Kunstmaan\AdminBundle\Command; | ||
|
||
use Doctrine\ORM\EntityManager; | ||
use Symfony\Component\Console\Question\ChoiceQuestion; | ||
use Symfony\Component\Security\Acl\Domain\Acl; | ||
use Symfony\Component\Security\Acl\Domain\Entry; | ||
use Symfony\Component\Security\Acl\Model\ObjectIdentityRetrievalStrategyInterface; | ||
use Symfony\Component\Security\Acl\Model\MutableAclProviderInterface; | ||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity; | ||
|
||
/** | ||
* Permissions update of ACL entries for all nodes for given role. | ||
*/ | ||
class UpdateAclCommand extends ContainerAwareCommand | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
parent::configure(); | ||
|
||
$this->setName('kuma:acl:update') | ||
->setDescription('Permissions update of ACL entries for all nodes for given role') | ||
->setHelp("The <info>kuma:update:acl</info> will update ACL entries for the nodes of the current project" . | ||
"with given role and permissions"); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$helper = $this->getHelper('question'); | ||
|
||
// Select Role | ||
$roles = $this->getContainer()->getParameter('security.role_hierarchy.roles'); | ||
$question = new ChoiceQuestion('Select role', array_keys($roles)); | ||
$question->setErrorMessage('Role %s is invalid.'); | ||
$role = $helper->ask($input, $output, $question); | ||
|
||
// Select Permission(s) | ||
$permissionMap = $this->getContainer()->get('security.acl.permission.map'); | ||
$question = new ChoiceQuestion('Select permissions(s) (seperate by ",")', | ||
$permissionMap->getPossiblePermissions()); | ||
$question->setMultiselect(true); | ||
$mask = array_reduce($helper->ask($input, $output, $question), function ($a, $b) use ($permissionMap) { | ||
return $a | $permissionMap->getMasks($b, null)[0]; | ||
}, 0); | ||
|
||
/* @var EntityManager $em */ | ||
$em = $this->getContainer()->get('doctrine.orm.entity_manager'); | ||
/* @var MutableAclProviderInterface $aclProvider */ | ||
$aclProvider = $this->getContainer()->get('security.acl.provider'); | ||
/* @var ObjectIdentityRetrievalStrategyInterface $oidStrategy */ | ||
$oidStrategy = $this->getContainer()->get('security.acl.object_identity_retrieval_strategy'); | ||
|
||
// Fetch all nodes & grant access | ||
$nodes = $em->getRepository('KunstmaanNodeBundle:Node')->findAll(); | ||
|
||
foreach ($nodes as $node) { | ||
$objectIdentity = $oidStrategy->getObjectIdentity($node); | ||
|
||
/** @var Acl $acl */ | ||
$acl = $aclProvider->findAcl($objectIdentity); | ||
$securityIdentity = new RoleSecurityIdentity($role); | ||
|
||
/** @var Entry $ace */ | ||
foreach ($acl->getObjectAces() as $index => $ace) { | ||
if (!$ace->getSecurityIdentity()->equals($securityIdentity)) { | ||
continue; | ||
} | ||
$acl->updateObjectAce($index, $mask); | ||
break; | ||
} | ||
$aclProvider->updateAcl($acl); | ||
} | ||
$output->writeln(count($nodes) . ' nodes processed.'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/Kunstmaan/AdminBundle/Helper/Security/OAuth/OAuthUserCreatorInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Kunstmaan\AdminBundle\Helper\Security\OAuth; | ||
|
||
/** | ||
* Interface OAuthUserCreatorInterface | ||
*/ | ||
interface OAuthUserCreatorInterface | ||
{ | ||
/** | ||
* Returns an implementation of AbstractUser defined by the $userClass parameter. | ||
* Checks if there already exists an account for the given googleId or email. If yes updates | ||
* the access levels accordingly and returns that user. If no creates a new user with the | ||
* configured access levels. | ||
* | ||
* Returns Null if email is not in configured domains | ||
* | ||
* @param string email | ||
* @param string googleId | ||
* | ||
* @return mixed AbstractUser Implementation | ||
*/ | ||
public function getOrCreateUser($email, $googleId); | ||
} |
51 changes: 51 additions & 0 deletions
51
src/Kunstmaan/AdminBundle/Helper/Security/OAuth/OAuthUserFinder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Kunstmaan\AdminBundle\Helper\Security\OAuth; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
|
||
class OAuthUserFinder implements OAuthUserFinderInterface | ||
{ | ||
|
||
/** @var EntityManager */ | ||
private $em; | ||
|
||
/** @var string */ | ||
private $userClass; | ||
|
||
/** | ||
* OAuthUserCreator constructor. | ||
* @param EntityManagerInterface $em | ||
* @param $userClass | ||
*/ | ||
public function __construct(EntityManagerInterface $em, $userClass) | ||
{ | ||
$this->em = $em; | ||
$this->userClass = $userClass; | ||
} | ||
|
||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function findUserByGoogleSignInData($email, $googleId) | ||
{ | ||
//Check if already logged in before via Google auth | ||
$user = $this->em->getRepository($this->userClass) | ||
->findOneBy(array('googleId' => $googleId)); | ||
|
||
if (!$user instanceof $this->userClass) { | ||
//Check if Email was already present in database but not logged in via Google auth | ||
$user = $this->em->getRepository($this->userClass) | ||
->findOneBy(array('email' => $email)); | ||
|
||
if(!$user instanceof $this->userClass) { | ||
//Last chance try looking for email address in username field | ||
$user = $this->em->getRepository($this->userClass) | ||
->findOneBy(array('username' => $email)); | ||
} | ||
} | ||
|
||
return $user; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Kunstmaan/AdminBundle/Helper/Security/OAuth/OAuthUserFinderInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Kunstmaan\AdminBundle\Helper\Security\OAuth; | ||
|
||
/** | ||
* Interface OAuthUserFinderInterface | ||
*/ | ||
interface OAuthUserFinderInterface | ||
{ | ||
|
||
/** | ||
* Tries to find a user in database based on email and googleId fields. | ||
* Returns null when nothing has been found. | ||
* | ||
* @param string email | ||
* @param string googleId | ||
* | ||
* @return mixed AbstractUser Implementation | ||
*/ | ||
public function findUserByGoogleSignInData($email, $googleId); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.