diff --git a/CHANGELOG.md b/CHANGELOG.md index c926ac0..efe363a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ Latest * [#119](https://github.com/cleverage/ui-process-bundle/issues/119) Launch form: a context row without key is left out of the context (reported by its `NotBlank` constraint): it gave a 500 when the process has constraints on the context, and a PHP 8.5 deprecation (`null` array offset). Add tests. * [#121](https://github.com/cleverage/ui-process-bundle/issues/121) `ListAction` / `LaunchAction`: accessed directly (`/process/list`, `/process/launch`), redirected to the dashboard (`/process?routeName=...`) instead of a 500. Add tests. * [#123](https://github.com/cleverage/ui-process-bundle/issues/123) HTTP API: the parameters of the query string are also read without body, and `queue` is read from the query string (the form data takes precedence). Add tests. +* [#125](https://github.com/cleverage/ui-process-bundle/issues/125) `ProcessSchedule::getContext()` decodes a JSON string as an array; `User::getRoles()` no longer duplicates `ROLE_USER`; `symfony/expression-language` declared (used by `Assert\When`); the `underscore_number_aware` Doctrine naming strategy prerequisite is documented. Add tests. v3.0.2 ------ diff --git a/composer.json b/composer.json index c538091..b51399c 100644 --- a/composer.json +++ b/composer.json @@ -53,6 +53,7 @@ "symfony/doctrine-messenger": "^6.4 || ^7.4 || ^8", "symfony/dotenv": "^6.4 || ^7.4 || ^8", "symfony/event-dispatcher": "^6.4 || ^7.4 || ^8", + "symfony/expression-language": "^6.4 || ^7.4 || ^8", "symfony/filesystem": "^6.4 || ^7.4 || ^8", "symfony/finder": "^6.4 || ^7.4 || ^8", "symfony/form": "^6.4 || ^7.4 || ^8", diff --git a/docs/index.md b/docs/index.md index 5fd9e7c..7c10dc7 100644 --- a/docs/index.md +++ b/docs/index.md @@ -84,6 +84,16 @@ See [users & security](reference/03-users_and_security.md). Supported databases: **MySQL / MariaDB** and **PostgreSQL** (maintained versions). +The entities of the bundle expect the `underscore_number_aware` Doctrine naming strategy (that of the Symfony recipe): +their indexes reference `snake_case` column names (e.g. `start_date`). + +```yaml +# config/packages/doctrine.yaml +doctrine: + orm: + naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware +``` + The bundle registers its own Doctrine migrations (`CleverAge\UiProcessBundle\Migrations`). Run them, then create a first user: diff --git a/src/Entity/ProcessSchedule.php b/src/Entity/ProcessSchedule.php index 34f7234..f297de4 100644 --- a/src/Entity/ProcessSchedule.php +++ b/src/Entity/ProcessSchedule.php @@ -76,7 +76,7 @@ public function setProcess(string $process): static */ public function getContext(): array { - return \is_array($this->context) ? $this->context : json_decode($this->context); + return \is_array($this->context) ? $this->context : json_decode($this->context, true); } /** diff --git a/src/Entity/User.php b/src/Entity/User.php index 11532f7..91a20be 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -136,7 +136,7 @@ public function setLocale(?string $locale): self public function getRoles(): array { - return array_merge(['ROLE_USER'], $this->roles); + return array_values(array_unique(array_merge(['ROLE_USER'], $this->roles))); } /** diff --git a/tests/Entity/ProcessScheduleTest.php b/tests/Entity/ProcessScheduleTest.php index ee989b4..30f8b44 100644 --- a/tests/Entity/ProcessScheduleTest.php +++ b/tests/Entity/ProcessScheduleTest.php @@ -72,6 +72,10 @@ public function testGetContextDecodesJsonString(): void (new \ReflectionProperty(ProcessSchedule::class, 'context'))->setValue($schedule, '["a","b"]'); self::assertSame(['a', 'b'], $schedule->getContext()); + + // A JSON object is decoded as an array (it gave a stdClass: TypeError on the return type) + (new \ReflectionProperty(ProcessSchedule::class, 'context'))->setValue($schedule, '{"key":"value"}'); + self::assertSame(['key' => 'value'], $schedule->getContext()); } /** diff --git a/tests/Entity/UserTest.php b/tests/Entity/UserTest.php index 6ddbf4a..d030b08 100644 --- a/tests/Entity/UserTest.php +++ b/tests/Entity/UserTest.php @@ -69,6 +69,14 @@ public function testGettersAndSetters(): void self::assertNull($user->getToken()); } + public function testRoleUserIsNotDuplicated(): void + { + // As stored by UserCreateCommand + $user = (new User())->setRoles(['ROLE_USER', 'ROLE_ADMIN']); + + self::assertSame(['ROLE_USER', 'ROLE_ADMIN'], $user->getRoles()); + } + public function testUserIdentifierRequiresAnEmail(): void { $user = (new User())->setEmail('');