- Merge request !6Fix stripping roles when original role field is not accessible. β (Open) created by golddragon007
- π¨π¦Canada Liam Morland Ontario, CA π¨π¦
Liam Morland β made their first commit to this issueβs fork.
- Status changed to RTBC
over 1 year ago 4:11pm 19 December 2023 - π¨π¦Canada Liam Morland Ontario, CA π¨π¦
Updated the merge request.
Patch works for me.
- π¬π§United Kingdom scott_euser
Confirming RTBC here.
To note there were also efforts in π Roles being stripped from users when saved Closed: duplicate but closed it as a duplicate as this one seems to jump in earlier in where things go wrong compared to in the final presave, but maintainers may find it useful to know there are also 11 followers there,
- First commit to issue fork.
- Status changed to Needs work
7 months ago 2:04pm 13 September 2024 - First commit to issue fork.
- π¦πΊAustralia acbramley
I was able to reproduce via the steps in the IS and got some test coverage going for this bug. Obviously the fix still isn't working (since it's breaking existing tests) but this'll give us something to test against (TDD :))
@acbramley i might be misunderstanding but the following section of code in the .module file:
<?php function role_delegation_user_form_builder(string $entity_type, UserInterface $user, array &$form, FormStateInterface $form_state) { // If the user has no access to the "role_change" or "role" field, then the // form will submit an empty array for the field, which will make later // processing think it was intentional. Set it to the empty field value to // correct this. if (!isset($form['role_change']['#access'], $form['account']['roles']['#access']) || !$form['role_change']['#access'] || !$form['account']['roles']['#access']) { $user->set('role_change', DelegatableRoles::$emptyFieldValue); } } ?>
If i am reading the text right it says that the user needs access to either the role_change field or the account roles field. However with the above code you would need access to both field for it to not submit an empty value. I believe the code should be:
<?php function role_delegation_user_form_builder(string $entity_type, UserInterface $user, array &$form, FormStateInterface $form_state) { // If the user has no access to the "role_change" or "role" field, then the // form will submit an empty array for the field, which will make later // processing think it was intentional. Set it to the empty field value to // correct this. if (!isset($form['role_change']['#access'], $form['account']['roles']['#access']) || (!$form['role_change']['#access'] && !$form['account']['roles']['#access'])) { $user->set('role_change', DelegatableRoles::$emptyFieldValue); } } ?>