Problem/Motivation
To trigger the change that this module provides, is to submit a form. This is an open request to provide a service that can generate a url that triggers the same functionality.
Storytime
My site has the functionality to provide a link to a user that allows them to masquerade as users. While this is managed via the Masquerade module, there is also functionality that provides a Dropbutton link to "View as [role]", that allows a user to preview the Group module implementation, that the current user is a manager of. Until this point, a function was ran to locate a user with role within the group, and then masquerade as that user.
The greatest limitation to this setup I describe, is that our users are created and blocked, until an onboarding process is completed. Since a user cannot masquerade as a blocked user, the link that provides the "View as [role]" in my site needs to change.
Reviewing the code, it seems that the only way to trigger the change in role is via the MasqueradeRoleForm form. It would be a great enhancement for the msqrole module to provide a service that generates a url that can also trigger the change process.
Proposed resolution
Add a service to generate a url that can be clicked to change the user role.
Remaining tasks
To be determined.
User interface changes
Likely none. This would be a service that is provided, but requires a developer to implement.
API changes
Adding the ability to generate a url.
Data model changes
Likely none
Comments
Comment #2
randalv commentedHi Tregonia,
Thanks for your ticket.
I'll look into this, but I can't promise if and when this could be released.
Kind regards,
RandalV
Comment #4
randalv commentedHi Tregonia,
I've pushed a first attempt to the 1.0.x-dev version of this module.
It generates a URL with a uuid. This uuid is stored in the key_value table, and fetched when navigating to the generated URL.
You can choose which roles should be included and whether that key needs to be destroyed upon usage (single use vs multi use URLs).
Feel free to give it a try, see how it feels and report back with your findings.
If the functionality feels well and complete, I'll release it in a new version of the module.
Kind regards,
RandalV
Comment #7
randalv commentedOops. Only saw afterwards that you want to automatically generate it, and not manually by submitting the form.
The last commit on 1.0.x-dev should contain that functionality in the RoleManager service.
\Drupal\msqrole\RoleManagerInterface::generateUrl(array $roles, bool $single_usage = FALSE, array $url_options = []): UrlThe arguments are all self explanatory.
Url options you could use to add a destination to the query parameter or something like that.
Example usage:
Comment #8
randalv commentedComment #11
randalv commented@Tregonia feel free to take it for a spin and see how it feels.
Either way this will probably be committed in the next release, but I'd rather someone test it out first.
Comment #12
randalv commentedI'm closing this issue, it's been committed to the next release and it seems to work fine.