How to specify a Role for conditional display?

Added by Justin D'Onofrio over 10 years ago

Hey everyone,

I'm trying to display an iframe on only one Redmine project Overview page, in place of the Members list.

Removing the Members list and displaying the iframe is not a problem - but, I need the iframe to only be visible to members of this one Project. From a bunch of reading here, it seems like doing this via a role restriction is the easier way to go.

Problem is, I can't figure out how to create a statement that does this! For example:

<% if User.current.admin? && @members_by_role.any? %>

… will limit the code below it to display only to Admins. But apparently the Admin group is special? And me and a few other folks can't figure out how to specify a role here. Something like this, which doesn't work:

<% if User.current.role == 'Lunatics' %>

… which would limit the code below it to display only for users in the "Lunatics" Role.

Any help would be greatly appreciated!!

(Running Redmine 0.8.3.)

Replies (4)

RE: How to specify a Role for conditional display? - Added by m sword almost 10 years ago

did you ever figure this out? I'm trying to do something similar.

RE: How to specify a Role for conditional display? - Added by m sword almost 10 years ago

yeah I figured this out. I did this...
<% if current_role %>
<% myRole = current_role %>
<% if myRole.name != 'Employee' %>
<HTML> etc
<% end %>
<% end %>

You might be able to something like
if current_role
if current_role.name != 'Employee'

I just assigned it a variable because I was sick of it bombing and going back to the logs to see errors.

RE: How to specify a Role for conditional display? - Added by steven gebbie over 8 years ago

I copied & pasted this & it didnt work.
how can i do an if based on the users role?

thanks

m sword wrote:

yeah I figured this out. I did this...
<% if current_role %>
<% myRole = current_role %>
<% if myRole.name != 'Employee' %>
<HTML> etc
<% end %>
<% end %>

You might be able to something like
if current_role
if current_role.name != 'Employee'

I just assigned it a variable because I was sick of it bombing and going back to the logs to see errors.

RE: How to specify a Role for conditional display? - Added by Pavel Potcheptsov almost 6 years ago

Any suggestion how to do something like

if User.current.role.id == 10

(1-4/4)