User::getRoles() returns ROLE_USER twice for new users

Open Beginner friendly
#73 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
php, symfony
Domain
backend

Research direction

The duplicate comes from getRoles() in src/Entity/User.php, which merges ROLE_USER into the stored roles (around line 173). Start there and replace the merge with a deduplicated, re-indexed array. The test to update is the user creation case in tests/Api/UserManagementTest.php, which currently pins the duplicate under a NOTE: current behaviour marker. Done means getRoles() returns ROLE_USER once and that test passes with the corrected expectation.

Written by the indexing model from the issue text.

Description

Backend bug severity: low

Problem

getRoles() returns array_merge($this->roles, ['ROLE_USER']). Users created with ROLE_USER already stored therefore get it twice. It is harmless for access checks, but it shows up in admin responses.

Expected

Return unique roles (array_values(array_unique(...))).

Where

src/Entity/User.php getRoles() (around line 173). Pinned in tests/Api/UserManagementTest.php (user creation tests).


Found by the API test suite added for #57 (branch feature/57-symfony-7.4); the behaviour is the same before and after the Symfony 7.4 upgrade. The current behaviour is pinned in the test named above (marked NOTE: current behaviour), so update that test together with the fix.

Dominant language
PHP
Stars
1
Forks
0
Avg merge
7h 58m
Merged PRs (30d)
3

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from RunningJoke/allipunkte

All issues in RunningJoke/allipunkte

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.