Skip to content

Allow impersonating regular users + big refactoring of impersonations#3226

Merged
mrcasals merged 71 commits intomasterfrom
feature/impersonations_everywhere
Apr 19, 2018
Merged

Allow impersonating regular users + big refactoring of impersonations#3226
mrcasals merged 71 commits intomasterfrom
feature/impersonations_everywhere

Conversation

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

@deivid-rodriguez deivid-rodriguez commented Apr 15, 2018

🎩 What? Why?

This is a big branch with a lot of commits, sorry about that, but I've been doing very granular refactoring of the whole feature to make sure I don't break anything and that means a lot of tiny atomic commits. Let me know if I should break it up to make reviewing easier.

It's built on top of #3225 for convenience, but I can also detach it.

The feature

  • Every user can now be impersonated, not only managed users, but if it's a real non-managed user, the impersonating user needs to provide a reason which is logged for posterity. (I've assumed we don't want to allow impersonating admin users, we don't right?). As a result, the "Managed Users" section is now called "Impersonations", and it allows filtering users by name or their managed status in order to impersonate them (or view their impersonation logs).

The refactoring

This PR also adds a lot of refactorings of this part of the code, that I found it was hard to work with and now it's easier. This is a summary of the improvements:

  • The impersonation form is now "single step". Before there used to be an initial step to choose an authorization handler in case there were more than one. Now it's all managed together in a single form (if there's more than one authorization handler available, a select box is used which renders the correct form when the handler is changed). I find this is simpler in terms of usability and codewise too.

  • We no longer extend rectify forms in a weird ways like this one.

  • We no longer mutate rectify forms after they are created like here. This is something we hardly ever do and it means an eventual migration to a rectify alternative that depends on dry-struct and dry-types instead of virtus (which is discontinued) will be easier, since dry-struct's are read-only.

  • We no longer call commands from within commands like here. This strikes to me as a bit weird and something we hardly ever do, and it's not necessary after the refactorings.

  • The whole feature is DRY'ed up. Before all forms/controllers/commands were quasi-duplicated and they contained mostly the same code but different edge cases. Now the whole thing is unified, and the edge cases are easier to understand in my opinion.

📌 Related Issues

None.

📋 Subtasks

  • Add CHANGELOG entry

📷 Screenshots (optional)

impersonationspreview

@ghost ghost added the status: WIP label Apr 15, 2018
@deivid-rodriguez deivid-rodriguez force-pushed the feature/impersonations_everywhere branch 2 times, most recently from eaf94c1 to 91726ec Compare April 15, 2018 23:53
mrcasals
mrcasals previously approved these changes Apr 16, 2018
Copy link
Copy Markdown
Contributor

@mrcasals mrcasals left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, nice refactor! Looks good to me!

@mrcasals
Copy link
Copy Markdown
Contributor

Proposals specs are failing, I guess it's a flaky spec that fails randomly, I've rescheduled the job https://circleci.com/gh/decidim/decidim/84563

@deivid-rodriguez deivid-rodriguez force-pushed the feature/impersonations_everywhere branch 3 times, most recently from e2c7bb1 to 2352cef Compare April 16, 2018 22:44
@ghost ghost assigned josepjaume Apr 17, 2018
@josepjaume
Copy link
Copy Markdown
Contributor

@deivid-rodriguez I assume this isn't WIP anymore?

@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

It's a very big branch so I wanted to do a final self-review pass today, that's why I didn't switch the label yesterday. But it's pretty much ready!

@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

deivid-rodriguez commented Apr 17, 2018

If you want it to land it now, I can also do a followup PR later if I find anything.

@ghost ghost removed the status: WIP label Apr 17, 2018
@ghost ghost added the status: WIP label Apr 17, 2018
@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

Sorry, wrong button 😳

@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

deivid-rodriguez commented Apr 17, 2018

So I did a quick pass and I have a couple of doubts:

  • I moved the uniqueness validation down to the base authorization handler in c77d435. I partially ended up reverting that commit in b1c0479 because it was changing behavior , but the uniqueness validation stayed in the base handler. This looks more correct to me but not sure if some handlers are using the unique_id field but still relying on uniqueness not being enforced when calling valid? on the form. Thoughts? Not sure if I correctly explained the "fear".

  • I added a second dummy authorization handler in 7bb06ca. It was useful to try out the authorization handler selector but maybe it's overkill to have two dummy authorization handlers in the default generated application? I could remove it since tests don't really need it (they register an extra handler on the fly when necessary). Thoughts?

Other than these two nits (which might be ok, but I prefer to call for opinions), this looks good to me!

@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

My own answers to my questions are that the first concern shouldn't be a problem but regarding the second concern I would remove the extra dummy handler I added to not complicate the dummy app any more.

The functionality is separate from the impersonations stuff, and that
controller is already complicated enough. By splitting it, we can also
choose a more adequate name for the resource.
I forgot to add this when I worked on it at the very beginning of this
branch.
Let it receive and arbitrary scope and not limit it to organization
users.
Not sure about the specs for this, but I'll stay on the safe side.
For example the default action on the dummy component is called "Foo" so
capybara actions are likely to conflict if we use that name.
@deivid-rodriguez deivid-rodriguez force-pushed the feature/impersonations_everywhere branch from 6cf2883 to c414e29 Compare April 18, 2018 11:14
@josepjaume
Copy link
Copy Markdown
Contributor

@deivid-rodriguez it took me some time but I understood your doubts haha. As you said, I believe the first one shouldn't be a problem (famous last words) and I would, as you suggest, remove one of the two authorization handlers from the generated app.

Thanks for your work!

@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

(famous last words)

xD Indeed.

Turns out removing the extra authorization broke the tests. That was unintented, fixing now.

This reverts commit fb327d6.

I don't think we need this in the default application.

Specs were actually relying on the existance of the global extra
authorization handler, so they needed a bit of tweaking.
@deivid-rodriguez deivid-rodriguez force-pushed the feature/impersonations_everywhere branch from c414e29 to 2f60233 Compare April 18, 2018 13:48
Copy link
Copy Markdown
Contributor

@oriolgual oriolgual left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

Decidim::ImpersonationLog.create!(
admin: form.current_user,
user: user,
reason: form.reason,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When impersonating an existing user I think we should send an email to them to let them when and why an admin has impersonated them. Otherwise without an audit no one would know about it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to also notify the user when the impersonation has finished.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uff, that seems reasonable but this is a new spec for me and I have no more availability to work on this... 😞

Copy link
Copy Markdown
Contributor Author

@deivid-rodriguez deivid-rodriguez Apr 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note though that the idea of impersonations (at least as I see them), is that the impersonated user is present during the impersonation. I mean, that's why we ask for authorization every time, right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do it in another PR @deivid-rodriguez, don't worry.

And yes, the user should be present during the impersonation, but and admin could know (or make a note) the user's data and impersonate them later.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do it in another PR @deivid-rodriguez, don't worry.

Thanks, and sorry for overlooking that!

And yes, the user should be present during the impersonation, but and admin could know (or make a note) the user's data and impersonate them later.

Ok, just wanted to make sure we're on the same page! 👍

oriolgual
oriolgual previously approved these changes Apr 18, 2018
@mrcasals
Copy link
Copy Markdown
Contributor

Merging!

@mrcasals mrcasals merged commit 103b9f3 into master Apr 19, 2018
@mrcasals mrcasals deleted the feature/impersonations_everywhere branch April 19, 2018 07:10
@ghost ghost removed the status: WIP label Apr 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants