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

Tregonia created an issue. See original summary.

randalv’s picture

Hi 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

  • 4541dae3 committed on 1.0.x
    Issue #3400290 by RandalV: Ability to create a "Masquerade as <role>"...
randalv’s picture

Hi 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

  • RandalV committed 67edd576 on 1.0.x
    Issue #3400290 by RandalV: Ability to create a "Masquerade as <role>"...

  • RandalV committed a03d4c2e on 1.0.x
    Issue #3400290 by RandalV: Ability to create a "Masquerade as <role>"...
randalv’s picture

Oops. 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 = []): Url
The arguments are all self explanatory.
Url options you could use to add a destination to the query parameter or something like that.

Example usage:

\Drupal::service('msqrole.manager')->generateUrl(['editor', 'visitor'], FALSE, [
  'query' => [
    'destination' => '/path/to/page',
  ],
];
randalv’s picture

Version: 1.0.11 » 1.0.x-dev
Priority: Normal » Minor
Status: Active » Needs review

  • 0d954076 committed on 1.0.x
    Issue #3400290 by RandalV: Ability to create a "Masquerade as <role>"...

  • 6d2192ee committed on 1.0.x
    Issue #3400290 by RandalV: Ability to create a "Masquerade as <role>"...
randalv’s picture

@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.

randalv’s picture

Status: Needs review » Fixed

I'm closing this issue, it's been committed to the next release and it seems to work fine.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.