ZMorek
ZMorek

Reputation: 681

Dropdown to view a page as different user roles while admin

I currently have a view simplified below...

<% if can? :manage, @task %>
  Admin 
<% elsif can? :update, @task %>
  Moderator
<% elsif current_user %>
  User
<% else %>
  Not logged in
<% end %>

This view has a large number of fields that are wrapped in similar conditionals for each user and I currently have to log in and out of test accounts to check formatting.

I want to be logged in as an admin but have a dropdown to select whether the page is rendered as Admin or Moderator or User or Not logged in

I have some rough ideas of solutioning, but don't know which to follow...

Is there a best practice around this?

Upvotes: 0

Views: 134

Answers (1)

Gary Wright
Gary Wright

Reputation: 121

How about if you implemented something like the real/effective user dichotomy of Unix?

You're existing infrastructure is the 'real' user based on whatever authentication has occurred but you also associate an 'effective user' with each session.

The effective user starts out the same as the real user but can be changed to something else. Changing the effective user should be conditioned on the real user having admin rights.

Condition all your layout on the effective user and not on the real user. Condition your 'change effective user' drop down on the real user.

Upvotes: 1

Related Questions