diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-10-18 17:08:42 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-10-18 17:08:42 +0000 |
commit | 7729178d9d50c6854e4602f4955f9e7f0598001c (patch) | |
tree | ef407662e58d5a99e9cf5d345269922dd0e2c550 | |
parent | 50037b18c49267229048c9b8126708a30626bde7 (diff) | |
download | redmine-7729178d9d50c6854e4602f4955f9e7f0598001c.tar.gz redmine-7729178d9d50c6854e4602f4955f9e7f0598001c.zip |
Adds links to locked users when current user is admin.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10673 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/helpers/application_helper.rb | 4 | ||||
-rw-r--r-- | app/models/user.rb | 11 | ||||
-rw-r--r-- | app/views/users/index.html.erb | 2 | ||||
-rw-r--r-- | public/stylesheets/application.css | 1 | ||||
-rw-r--r-- | test/test_helper.rb | 9 | ||||
-rw-r--r-- | test/unit/helpers/application_helper_test.rb | 20 |
6 files changed, 38 insertions, 9 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0911fdfc2..b9fcf9291 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -47,8 +47,8 @@ module ApplicationHelper def link_to_user(user, options={}) if user.is_a?(User) name = h(user.name(options[:format])) - if user.active? - link_to name, :controller => 'users', :action => 'show', :id => user + if user.active? || (User.current.admin? && user.logged?) + link_to name, {:controller => 'users', :action => 'show', :id => user}, :class => user.css_classes else name end diff --git a/app/models/user.rb b/app/models/user.rb index 348ae120d..87db4eb5a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -387,6 +387,17 @@ class User < Principal name end + CSS_CLASS_BY_STATUS = { + STATUS_ANONYMOUS => 'anon', + STATUS_ACTIVE => 'active', + STATUS_REGISTERED => 'registered', + STATUS_LOCKED => 'locked' + } + + def css_classes + "user #{CSS_CLASS_BY_STATUS[status]}" + end + # Returns the current day according to user's time zone def today if time_zone.nil? diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index f88b5231e..4f77a6493 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -36,7 +36,7 @@ </tr></thead> <tbody> <% for user in @users -%> - <tr class="user <%= cycle("odd", "even") %> <%= %w(anon active registered locked)[user.status] %>"> + <tr class="<%= user.css_classes %> <%= cycle("odd", "even") %>"> <td class="username"><%= avatar(user, :size => "14") %><%= link_to h(user.login), edit_user_path(user) %></td> <td class="firstname"><%= h(user.firstname) %></td> <td class="lastname"><%= h(user.lastname) %></td> diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 97b3d0312..9bfc09624 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -107,6 +107,7 @@ a img{ border: 0; } a.issue.closed, a.issue.closed:link, a.issue.closed:visited { color: #999; text-decoration: line-through; } a.project.closed, a.project.closed:link, a.project.closed:visited { color: #999; } +a.user.locked, a.user.locked:link, a.user.locked:visited {color: #999;} #sidebar a.selected {line-height:1.7em; padding:1px 3px 2px 2px; margin-left:-2px; background-color:#9DB9D5; color:#fff; border-radius:2px;} #sidebar a.selected:hover {text-decoration:none;} diff --git a/test/test_helper.rb b/test/test_helper.rb index 66a6f2646..3c2cece7b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -114,6 +114,15 @@ class ActiveSupport::TestCase saved_settings.each {|k, v| Setting[k] = v} if saved_settings end + # Yields the block with user as the current user + def with_current_user(user, &block) + saved_user = User.current + User.current = user + yield + ensure + User.current = saved_user + end + def change_user_password(login, new_password) user = User.first(:conditions => {:login => login}) user.password, user.password_confirmation = new_password, new_password diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index 9855efa27..4bf191f01 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -1010,15 +1010,23 @@ RAW def test_link_to_user user = User.find(2) - t = link_to_user(user) - assert_equal "<a href=\"/users/2\">#{ user.name }</a>", t + assert_equal '<a href="/users/2" class="user active">John Smith</a>', link_to_user(user) end def test_link_to_user_should_not_link_to_locked_user - user = User.find(5) - assert user.locked? - t = link_to_user(user) - assert_equal user.name, t + with_current_user nil do + user = User.find(5) + assert user.locked? + assert_equal 'Dave2 Lopper2', link_to_user(user) + end + end + + def test_link_to_user_should_link_to_locked_user_if_current_user_is_admin + with_current_user User.find(1) do + user = User.find(5) + assert user.locked? + assert_equal '<a href="/users/5" class="user locked">Dave2 Lopper2</a>', link_to_user(user) + end end def test_link_to_user_should_not_link_to_anonymous |