Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove admin deprecations #248

Merged
merged 2 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"ext-json": "*",
"nucleos/user-bundle": "^1.6",
"psr/log": "^1.0",
"sonata-project/admin-bundle": "^3.57",
"sonata-project/admin-bundle": "^3.90",
"sonata-project/doctrine-extensions": "^1.5.1",
"symfony/config": "^4.4",
"symfony/dependency-injection": "^4.4",
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/Model/GroupAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct($code, $class, $baseControllerName, GroupManagerInte
$this->groupManager = $groupManager;
}

public function getNewInstance()
protected function createNewInstance(): object
{
return $this->groupManager->createGroup('');
}
Expand Down
52 changes: 26 additions & 26 deletions src/Admin/Model/UserAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,6 @@ public function __construct($code, $class, $baseControllerName, UserManagerInter
$this->userManager = $userManager;
}

public function getNewInstance()
{
$instance = $this->userManager->createUser();

// TODO: Find a better way to create editabe form models
// BC layer
try {
$instance->getUsername();
} catch (DomainException $exception) {
$instance->setUsername('');
}

try {
$instance->getEmail();
} catch (DomainException $exception) {
$instance->setEmail('');
}

return $instance;
}

public function getFormBuilder(): FormBuilderInterface
{
$this->formOptions['data_class'] = $this->getClass();
Expand All @@ -87,21 +66,42 @@ public function getFormBuilder(): FormBuilderInterface
return $formBuilder;
}

public function getExportFields(): array
public function preUpdate($user): void
{
$this->userManager->updateCanonicalFields($user);
$this->userManager->updatePassword($user);
}

protected function configureExportFields(): array
{
// avoid security field to be exported
return array_filter(
parent::getExportFields(),
parent::configureExportFields(),
static function ($v): bool {
return !\in_array($v, ['password', 'salt'], true);
}
);
}

public function preUpdate($user): void
protected function createNewInstance(): object
{
$this->userManager->updateCanonicalFields($user);
$this->userManager->updatePassword($user);
$instance = $this->userManager->createUser();

// TODO: Find a better way to create editabe form models
// BC layer
try {
$instance->getUsername();
} catch (DomainException $exception) {
$instance->setUsername('');
}

try {
$instance->getEmail();
} catch (DomainException $exception) {
$instance->setEmail('');
}

return $instance;
}

protected function configureListFields(ListMapper $listMapper): void
Expand Down
18 changes: 0 additions & 18 deletions tests/Form/Type/RolesMatrixTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,6 @@ public function testSubmitValidData(): void
static::assertContains('ROLE_FOO', $form->getData());
}

public function testSubmitInvalidData(): void
{
$form = $this->factory->create(
RolesMatrixType::class,
null,
[
'multiple' => true,
'expanded' => true,
'required' => false,
]
);

$form->submit([0 => 'ROLE_NOT_EXISTS']);

static::assertFalse($form->isSynchronized());
static::assertNull($form->getData());
}

/**
* @return PreloadedExtension[]
*/
Expand Down
18 changes: 0 additions & 18 deletions tests/Form/Type/SecurityRolesTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,6 @@ public function testSubmitValidData(): void
static::assertContains('ROLE_FOO', $form->getData());
}

public function testSubmitInvalidData(): void
{
$form = $this->factory->create(
$this->getSecurityRolesTypeName(),
null,
[
'multiple' => true,
'expanded' => true,
'required' => false,
]
);

$form->submit([0 => 'ROLE_NOT_EXISTS']);

static::assertFalse($form->isSynchronized());
static::assertNull($form->getData());
}

public function testSubmitWithHiddenRoleData(): void
{
$originalRoles = ['ROLE_SUPER_ADMIN', 'ROLE_USER'];
Expand Down