Skip to content

Commit

Permalink
BH-681: Fix migrations tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmleroux committed Sep 3, 2021
1 parent ce13cac commit 248a594
Show file tree
Hide file tree
Showing 8 changed files with 662 additions and 692 deletions.
1,316 changes: 650 additions & 666 deletions composer.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ includes:
- vendor/phpstan/phpstan-webmozart-assert/extension.neon
parameters:
reportUnmatchedIgnoredErrors: false
checkGenericClassInNonGenericObjectType: false
symfony:
container_xml_path: %rootDir%/../../../var/cache/dev/srcKernelDevDebugContainer.xml
ignoreErrors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Akeneo\Connectivity\Connection\Application\Webhook;

use Doctrine\Persistence\ObjectRepository;
use Akeneo\UserManagement\Component\Repository\UserRepositoryInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Core\User\UserInterface;
Expand All @@ -15,11 +15,11 @@
*/
class WebhookUserAuthenticator
{
private ObjectRepository $userRepository;
private UserRepositoryInterface $userRepository;

private TokenStorageInterface $tokenStorage;

public function __construct(ObjectRepository $userRepository, TokenStorageInterface $tokenStorage)
public function __construct(UserRepositoryInterface $userRepository, TokenStorageInterface $tokenStorage)
{
$this->userRepository = $userRepository;
$this->tokenStorage = $tokenStorage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Akeneo\Pim\Enrichment\Component\Product\Repository\ReferenceDataRepositoryResolverInterface;
use Akeneo\Pim\Structure\Component\ReferenceData\ConfigurationRegistryInterface;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectRepository;

/**
* Resolves the repository given a reference data type
Expand All @@ -29,7 +30,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function resolve($referenceDataType)
public function resolve(string $referenceDataType): ObjectRepository
{
$referenceDataConf = $this->configurationRegistry->get($referenceDataType);
$referenceDataClass = $referenceDataConf->getClass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,5 @@
*/
interface ReferenceDataRepositoryResolverInterface
{
/**
* @param string $referenceDataType
*
* @return ObjectRepository
*/
public function resolve($referenceDataType);
public function resolve(string $referenceDataType): ObjectRepository;
}
12 changes: 0 additions & 12 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@
"src/Repository/.gitignore"
]
},
"doctrine/doctrine-cache-bundle": {
"version": "1.4.0"
},
"doctrine/doctrine-fixtures-bundle": {
"version": "3.0",
"recipe": {
Expand Down Expand Up @@ -151,9 +148,6 @@
"doctrine/persistence": {
"version": "v1.1.0"
},
"doctrine/reflection": {
"version": "v1.0.0"
},
"doctrine/sql-formatter": {
"version": "1.1.1"
},
Expand Down Expand Up @@ -217,9 +211,6 @@
"ref": "370bcf99b04c0dfd0b545745aad622d757af5e1b"
}
},
"friendsofsymfony/oauth-server-bundle": {
"version": "1.6.2"
},
"friendsofsymfony/oauth2-php": {
"version": "1.2.3"
},
Expand Down Expand Up @@ -280,9 +271,6 @@
"instaclick/php-webdriver": {
"version": "1.4.6"
},
"jdorn/sql-formatter": {
"version": "v1.2.17"
},
"justinrainbow/json-schema": {
"version": "5.2.9"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Pim\Upgrade\Schema;

use Akeneo\UserManagement\Component\Model\Role;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
Expand All @@ -22,6 +23,7 @@ final class Version_4_1_20200127171059_unauthorized_view_all_jobs_permission ext
public function up(Schema $schema) : void
{
$aclManager = $this->container->get('oro_security.acl.manager');
/** @var Role[] $roles */
$roles = $this->container->get('pim_user.repository.role')->findAll();

foreach ($roles as $role) {
Expand All @@ -32,7 +34,7 @@ public function up(Schema $schema) : void
->addPermission(new AclPermission('EXECUTE', 0));

$aclManager->getPrivilegeRepository()
->savePrivileges(new RoleSecurityIdentity($role), new ArrayCollection([$privilege]));
->savePrivileges(new RoleSecurityIdentity($role->getRole()), new ArrayCollection([$privilege]));
}

$aclManager->flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public function testItForbidToViewAllJobsForAllRoles()

private function findAccessLevelForRole(Role $role): ?int
{
$aclPrivileges = $this->aclManager->getPrivilegeRepository()->getPrivileges(new RoleSecurityIdentity($role));
$aclPrivileges = $this->aclManager->getPrivilegeRepository()
->getPrivileges(new RoleSecurityIdentity($role->getRole()));
foreach ($aclPrivileges as $aclPrivilege) {
if ($aclPrivilege->getIdentity()->getId() === static::PRIVILEGE_ID) {
return $aclPrivilege->getPermissions()->get('EXECUTE')->getAccessLevel();
Expand All @@ -126,7 +127,7 @@ private function authorizedPermission(Role $role): void
$this
->aclManager
->getPrivilegeRepository()
->savePrivileges(new RoleSecurityIdentity($role), new ArrayCollection([$privilege]));
->savePrivileges(new RoleSecurityIdentity($role->getRole()), new ArrayCollection([$privilege]));
}

private function getMigrationLabel(): string
Expand Down

0 comments on commit 248a594

Please sign in to comment.