Problem/Motivation

Provide support for Masquerade module in Drupal 8 || 9 version.
Another support thread in Masquerade module: #3190347: Add support for the password policy module

CommentFileSizeAuthor
#7 3213457-7.patch853 byteslarisse
#4 3213457-4.patch1007 byteslarisse
#2 3213457-2.patch1.01 KBlarisse
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

larisse created an issue. See original summary.

larisse’s picture

Assigned: larisse » Unassigned
Status: Active » Needs review
StatusFileSize
new1.01 KB

I think this patch can help.

andypost’s picture

Instead of moduleExists call the cleaner approach is to use hasService(masquerade) and use it

larisse’s picture

StatusFileSize
new1007 bytes

Changing the patch to what @andypost said in comment #3.

andypost’s picture

Status: Needs review » Needs work

That looks better @larisse

Needs work for

- $module_handler variable name needs change, $has_masquerade or kinda
- coding standards, report at https://www.drupal.org/pift-ci-job/2059338

andypost’s picture

Code comment (which breaks coding standards) is useless - please remove it entirely. There's git history for thst purpose

larisse’s picture

Status: Needs work » Needs review
StatusFileSize
new853 bytes

Hello @andypost!
Follows the patch with the changes.

hmendes’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed patch from #7 and it worked fine, requesting the password update only when logging with the user, not when masquerading with it, changing to RTBC.
Tested with Drupal 9.1.6, Masquerade 8.x-2.x-dev and Password_policy 8.x-3.x-dev.

nerdstein’s picture

Status: Reviewed & tested by the community » Needs work

Thanks for posting this and helping us get more interoperability between the modules.

@hmendes - I am curious what experience we are offering the end users. Should we proactively show a masqueraded users a message when they get to the edit form with the password? Should we hide any of the form elements? Maybe this is managed upstream through the masquerade module, but I'd like more details if this patch needs to be improved.

The patch only seems to block masqueraded users from leveraging the service. We should consider having an automated test as well.

I am going to move back to "needs work" until I get some clarity on the experience and hopefully a test.

hmendes’s picture

Hello @nerdstein, thank you for the reply.

I think the patch was made to let the administrator masquerade as the user without having to reset its password ( when the password is expired ) and for this specific problem I think the patch works the way it should.

Steps:

  • Create a password policy for a Role 'x'
  • Create a user with this Role
  • As admin, masquerade as this user
  • Before applying the patch
    • If the password is expired it will require the admin to change the password
  • After applying the patch
    • the admin can masquerade as the user without having to change the password

I'm not a masquerade maintainer, but from what i see, the module is mainly for site designers to see what their site look like for their users, so I don't think we should let the admin know that the user password is expired when masquerading with it, but I do think that if the administrator wants to change the password of the user, it should respect the constraints added before and that is happening even when the masqueraded user tries to change the password.

Also, if I'm masking myself as a user with an expired password, I can't unmask until I update the password, so if we're letting the admin see that the password has expired, he should let him unmask since we're not logged in with the user, just masking as it.

gngn’s picture

#7 worked for me.

NigelCunningham made their first commit to this issue’s fork.

Sophie.SK made their first commit to this issue’s fork.

sophie.sk’s picture

Status: Needs work » Needs review

One of my clients has run into this problem this week.

I've updated the issue fork - rebased against the latest dev version, reverted a previous commit (as this changed comparison operators and didn't have the Masquerade support in it), and added the changes from https://www.drupal.org/project/password_policy/issues/3213457#comment-14...

I agree with @hmendes in https://www.drupal.org/project/password_policy/issues/3213457#comment-14... - this is so that administrators can masquerade as users and browse the site without needing to know or change a user's password. At the moment our administrators are unable to perform their normal tasks (checking that customers have access to the right information) because the customer needs to change their password, but it's not possible to do that.

sophie.sk’s picture

Noticed this was no longer applying, so updated the patch.

paulocs’s picture

Status: Needs review » Needs work

Hello Sophie.SK,
Can we use Dependency Injection instead?

Optional parameter reference: https://symfony.com/doc/2.0/book/service_container.html#making-references-optional

sophie.sk’s picture

Ahh you called me out on being lazy lol. Yes I can do that this morning :)

sophie.sk’s picture

Status: Needs work » Needs review

Okay, added DI - I didn't know you could make arguments optional like that, thank you for the link (though you linked to Symfony 2.0 so had to go digging!). Back to review.

paulocs’s picture

Sorry Sophie.SK, I did not notice the version.
I'll review it.

paulocs’s picture

Status: Needs review » Fixed

Thank you all!

Status: Fixed » Closed (fixed)

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

gngn’s picture

@paulocs: Is this included in 8.x-3.2?
I did not find anything with Masquerade or #3213457 in the release notes https://www.drupal.org/project/password_policy/releases/8.x-3.2