Change in "Users" page
Added by Federico Hernandez almost 15 years ago
I want to change the "Users" page for registered users to display no only the Activate link but also the Lock link to be able to directly lock an account that signed up for spamming (I currently do this by running a mysql script on the command line).
I found the following in app/helpers/users_helper.rb:
if user.locked? link_to l(:button_unlock), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :post, :class => 'icon icon-unlock' elsif user.registered? link_to l(:button_activate), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :post, :class => 'icon icon-unlock' elsif user != User.current link_to l(:button_lock), url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :post, :class => 'icon icon-lock' end
and did change it to
if user.locked? link_to l(:button_unlock), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :post, :class => 'icon icon-unlock' elsif user.registered? link_to l(:button_activate), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :post, :class => 'icon icon-unlock' link_to l(:button_lock), url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :post, :class => 'icon icon-lock' elsif user != User.current link_to l(:button_lock), url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :post, :class => 'icon icon-lock' end
Though it didn't work as now only the Lock link is displayed. What am I doing wrong? As you see I'm not the most experienced ruby hacker.
Thanks in advance.
Replies (3)
RE: Change in "Users" page - Added by Felix Schäfer almost 15 years ago
The output of any proc/method/loop in ruby is the "output of the last command that created an output" (it's obviously simplified, don't take that as a holy script when beginning to learn ruby or something ;-). Anyway, I think it would be enough to replace your two lines with one like that:
link_to l(:button_activate), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :post, :class => 'icon icon-unlock' + link_to l(:button_lock), url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :post, :class => 'icon icon-lock'
RE: Change in "Users" page - Added by Federico Hernandez almost 15 years ago
Thank you. clarifying the output. Appreciated. Unfortunately your suggestion doesn't work:
Internal error An error occurred on the page you were trying to access. If you continue to experience problems please contact your redMine administrator for assistance.
I will try to start small now and build a "working solution" with static links first and see if I can expand it to this dynamic approach.
Nevertheless I'm still appreciating more suggestions. :-)
RE: Change in "Users" page - Added by Federico Hernandez almost 15 years ago
Anyway, I have now solved my problem in a different way:
I created in app/helpers/users_helper.rb
a
def change_status_link2(user) url = {:action => 'edit', :id => user, :page => params[:page], :status => params[:status]} if user.registered? link_to l(:button_lock), url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :post, :class => 'icon icon-lock' end end
and then in app/views/users/list.rhtml
and app/views/users/edit.rhtml
I have changed
<%= change_status_link(user) %>
to
<%= change_status_link(user) %><%= change_status_link2(user) %>
This does what I want to do: have an lock and unlock button together just for registered users.