Skip to content

Feat/user-roles : Implement user role selection with CallbackTransformer#40

Merged
Mike031289 merged 2 commits into
developfrom
feat/user-roles
Jul 16, 2026
Merged

Feat/user-roles : Implement user role selection with CallbackTransformer#40
Mike031289 merged 2 commits into
developfrom
feat/user-roles

Conversation

@Mike031289

Copy link
Copy Markdown
Owner

This PR implements the explicit selection of user roles (User vs. Administrator) during user creation and edition, as specified in the project requirements.

To achieve a clean architecture and prevent controller bloating, we implemented a form-level CallbackTransformer to seamlessly translate the user interface's single-choice selection into the array structure expected by Symfony's Security component.

Changes Checklist

  • Entity Documentation: Added complete PHPDoc annotations (@var, @param, @return) to User class properties and methods for better static analysis.
  • Form Role Choice: Integrated an expanded ChoiceType (radio buttons) into UserType with multiple => false to allow selecting exactly one role.
  • Data Transformation: Added a CallbackTransformer to map the single string value from the UI to the underlying roles array format, and vice-versa.
  • Controller Refactoring: Secured UserController actions with $form->isSubmitted() checks and added safety logic to prevent password erasure when updating other profile fields.
  • Automated Tests: Developed and corrected both unit tests (UserTest.php) and functional tests (UserControllerTest.php) ensuring credentials updates propagate properly in the database.

Test Results

All 7 tests are now passing green:

$ php vendor/bin/phpunit
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.

.......                                                             7 / 7 (100%)

Time: 3.56 seconds, Memory: 28.00 MB

OK (7 tests, 20 assertions)

…tion

- Add unique constraints for username and email on the User entity.
- Document User entity properties and methods with clean PHPDocs.
- Integrate role selection in UserType with an expanded ChoiceType (radio buttons).
- Use a CallbackTransformer in UserType to handle seamless translation between the form's single choice string and the entity's roles array.
- Refactor UserController to ensure form submission safety and prevent password erasure when editing users.

Resolves #10
…ding in assertions

- Change DomCrawler selection for 'user[roles]' from array format to a single string value to prevent InvalidArgumentException in ChoiceFormField.
- Resolve PHPUnit assertion failure by adjusting expected flash message string to match HTML-encoded apostrophe (L'utilisateur).
- All 7 PHPUnit tests are now successfully passing.
@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 4 medium

Alerts:
⚠ 4 issues (≤ 0 issues of at least minor severity)

Results:
4 new issues

Category Results
ErrorProne 4 medium

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@Mike031289
Mike031289 merged commit 8ce780f into develop Jul 16, 2026
1 of 2 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in @Mike031289's ToDo-Co Jul 16, 2026
@Mike031289
Mike031289 deleted the feat/user-roles branch July 16, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Extra attention is needed security

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant