]> source.dussan.org Git - redmine.git/commitdiff
AccountController#show (/account/show/:id) moved to UsersController#show (/users...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 29 Oct 2009 18:37:00 +0000 (18:37 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 29 Oct 2009 18:37:00 +0000 (18:37 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2988 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/account_controller.rb
app/controllers/users_controller.rb
app/helpers/application_helper.rb
app/views/account/show.rhtml [deleted file]
app/views/users/show.rhtml [new file with mode: 0644]
config/routes.rb
test/functional/account_controller_test.rb
test/functional/users_controller_test.rb

index f2d6a8d6e88abb4ff4853a45934cb8b1a8dd0677..17d113887373cb8cc5daa50d06df6e7542f3fbcc 100644 (file)
@@ -1,5 +1,5 @@
 # Redmine - project management software
-# Copyright (C) 2006-2008  Jean-Philippe Lang
+# Copyright (C) 2006-2009  Jean-Philippe Lang
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -20,28 +20,7 @@ class AccountController < ApplicationController
   include CustomFieldsHelper   
   
   # prevents login action to be filtered by check_if_login_required application scope filter
-  skip_before_filter :check_if_login_required, :only => [:login, :lost_password, :register, :activate]
-
-  # Show user's account
-  def show
-    @user = User.active.find(params[:id])
-    @custom_values = @user.custom_values
-    
-    # show only public projects and private projects that the logged in user is also a member of
-    @memberships = @user.memberships.select do |membership|
-      membership.project.is_public? || (User.current.member_of?(membership.project))
-    end
-    
-    events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
-    @events_by_day = events.group_by(&:event_date)
-    
-    if @user != User.current && !User.current.admin? && @memberships.empty? && events.empty?
-      render_404 and return
-    end
-    
-  rescue ActiveRecord::RecordNotFound
-    render_404
-  end
+  skip_before_filter :check_if_login_required
 
   # Login request and validation
   def login
index 776efb02d4f01b5bcc37f1762c96254f7334bb9c..71ceb758f07bfa52caf3675176be6a37e553472d 100644 (file)
@@ -1,5 +1,5 @@
-# redMine - project management software
-# Copyright (C) 2006-2007  Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2009  Jean-Philippe Lang
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -16,7 +16,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 class UsersController < ApplicationController
-  before_filter :require_admin
+  before_filter :require_admin, :except => :show
 
   helper :sort
   include SortHelper
@@ -51,6 +51,26 @@ class UsersController < ApplicationController
 
     render :action => "list", :layout => false if request.xhr? 
   end
+  
+  def show
+    @user = User.active.find(params[:id])
+    @custom_values = @user.custom_values
+    
+    # show only public projects and private projects that the logged in user is also a member of
+    @memberships = @user.memberships.select do |membership|
+      membership.project.is_public? || (User.current.member_of?(membership.project))
+    end
+    
+    events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
+    @events_by_day = events.group_by(&:event_date)
+    
+    if @user != User.current && !User.current.admin? && @memberships.empty? && events.empty?
+      render_404 and return
+    end
+    
+  rescue ActiveRecord::RecordNotFound
+    render_404
+  end
 
   def add
     if request.get?
index b302879fb6499acd2554d97bb57e602f1e1f8fc6..5f48944e3e4d05524e3e12e187382cdb6f6878e4 100644 (file)
@@ -47,7 +47,7 @@ module ApplicationHelper
   # Display a link to user's account page
   def link_to_user(user, options={})
     if user.is_a?(User)
-      !user.anonymous? ? link_to(user.name(options[:format]), :controller => 'account', :action => 'show', :id => user) : 'Anonymous'
+      !user.anonymous? ? link_to(user.name(options[:format]), :controller => 'users', :action => 'show', :id => user) : 'Anonymous'
     else
       user.to_s
     end
@@ -222,8 +222,7 @@ module ApplicationHelper
   end
 
   def authoring(created, author, options={})
-    author_tag = (author.is_a?(User) && !author.anonymous?) ? link_to(h(author), :controller => 'account', :action => 'show', :id => author) : h(author || 'Anonymous')
-    l(options[:label] || :label_added_time_by, :author => author_tag, :age => time_tag(created))
+    l(options[:label] || :label_added_time_by, :author => link_to_user(author), :age => time_tag(created))
   end
   
   def time_tag(time)
diff --git a/app/views/account/show.rhtml b/app/views/account/show.rhtml
deleted file mode 100644 (file)
index 8816f10..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-<div class="contextual">
-<%= link_to(l(:button_edit), {:controller => 'users', :action => 'edit', :id => @user}, :class => 'icon icon-edit') if User.current.admin? %>
-</div>
-
-<h2><%= avatar @user %> <%=h @user.name %></h2>
-
-<div class="splitcontentleft">
-<ul>
-       <% unless @user.pref.hide_mail %>
-               <li><%=l(:field_mail)%>: <%= mail_to(h(@user.mail), nil, :encode => 'javascript') %></li>
-       <% end %>
-       <% for custom_value in @custom_values %>
-       <% if !custom_value.value.blank? %>
-    <li><%=h custom_value.custom_field.name%>: <%=h show_value(custom_value) %></li>
-       <% end %>
-       <% end %>
-    <li><%=l(:label_registered_on)%>: <%= format_date(@user.created_on) %></li>
-       <% unless @user.last_login_on.nil? %>
-               <li><%=l(:field_last_login_on)%>: <%= format_date(@user.last_login_on) %></li>
-       <% end %>
-</ul>
-
-<% unless @memberships.empty? %>
-<h3><%=l(:label_project_plural)%></h3>
-<ul>
-<% for membership in @memberships %>
-       <li><%= link_to(h(membership.project.name), :controller => 'projects', :action => 'show', :id => membership.project) %>
-    (<%=h membership.roles.sort.collect(&:to_s).join(', ') %>, <%= format_date(membership.created_on) %>)</li>
-<% end %>
-</ul>
-<% end %>
-<%= call_hook :view_account_left_bottom, :user => @user %>
-</div>
-
-<div class="splitcontentright">
-
-<% unless @events_by_day.empty? %>
-<h3><%= link_to l(:label_activity), :controller => 'projects', :action => 'activity', :id => nil, :user_id => @user, :from => @events_by_day.keys.first %></h3>
-
-<p>
-<%=l(:label_reported_issues)%>: <%= Issue.count(:conditions => ["author_id=?", @user.id]) %>
-</p>
-
-<div id="activity">
-<% @events_by_day.keys.sort.reverse.each do |day| %>
-<h4><%= format_activity_day(day) %></h4>
-<dl>
-<% @events_by_day[day].sort {|x,y| y.event_datetime <=> x.event_datetime }.each do |e| -%>
-  <dt class="<%= e.event_type %>">
-  <span class="time"><%= format_time(e.event_datetime, false) %></span>
-  <%= content_tag('span', h(e.project), :class => 'project') %>
-  <%= link_to format_activity_title(e.event_title), e.event_url %></dt>
-  <dd><span class="description"><%= format_activity_description(e.event_description) %></span></dd>
-<% end -%>
-</dl>
-<% end -%>
-</div>
-
-<% other_formats_links do |f| %>
-       <%= f.link_to 'Atom', :url => {:controller => 'projects', :action => 'activity', :id => nil, :user_id => @user, :key => User.current.rss_key} %>
-<% end %>
-
-<% content_for :header_tags do %>
-               <%= auto_discovery_link_tag(:atom, :controller => 'projects', :action => 'activity', :user_id => @user, :format => :atom, :key => User.current.rss_key) %>
-<% end %>
-<% end %>
-<%= call_hook :view_account_right_bottom, :user => @user %>
-</div>
-
-<% html_title @user.name %>
diff --git a/app/views/users/show.rhtml b/app/views/users/show.rhtml
new file mode 100644 (file)
index 0000000..8816f10
--- /dev/null
@@ -0,0 +1,70 @@
+<div class="contextual">
+<%= link_to(l(:button_edit), {:controller => 'users', :action => 'edit', :id => @user}, :class => 'icon icon-edit') if User.current.admin? %>
+</div>
+
+<h2><%= avatar @user %> <%=h @user.name %></h2>
+
+<div class="splitcontentleft">
+<ul>
+       <% unless @user.pref.hide_mail %>
+               <li><%=l(:field_mail)%>: <%= mail_to(h(@user.mail), nil, :encode => 'javascript') %></li>
+       <% end %>
+       <% for custom_value in @custom_values %>
+       <% if !custom_value.value.blank? %>
+    <li><%=h custom_value.custom_field.name%>: <%=h show_value(custom_value) %></li>
+       <% end %>
+       <% end %>
+    <li><%=l(:label_registered_on)%>: <%= format_date(@user.created_on) %></li>
+       <% unless @user.last_login_on.nil? %>
+               <li><%=l(:field_last_login_on)%>: <%= format_date(@user.last_login_on) %></li>
+       <% end %>
+</ul>
+
+<% unless @memberships.empty? %>
+<h3><%=l(:label_project_plural)%></h3>
+<ul>
+<% for membership in @memberships %>
+       <li><%= link_to(h(membership.project.name), :controller => 'projects', :action => 'show', :id => membership.project) %>
+    (<%=h membership.roles.sort.collect(&:to_s).join(', ') %>, <%= format_date(membership.created_on) %>)</li>
+<% end %>
+</ul>
+<% end %>
+<%= call_hook :view_account_left_bottom, :user => @user %>
+</div>
+
+<div class="splitcontentright">
+
+<% unless @events_by_day.empty? %>
+<h3><%= link_to l(:label_activity), :controller => 'projects', :action => 'activity', :id => nil, :user_id => @user, :from => @events_by_day.keys.first %></h3>
+
+<p>
+<%=l(:label_reported_issues)%>: <%= Issue.count(:conditions => ["author_id=?", @user.id]) %>
+</p>
+
+<div id="activity">
+<% @events_by_day.keys.sort.reverse.each do |day| %>
+<h4><%= format_activity_day(day) %></h4>
+<dl>
+<% @events_by_day[day].sort {|x,y| y.event_datetime <=> x.event_datetime }.each do |e| -%>
+  <dt class="<%= e.event_type %>">
+  <span class="time"><%= format_time(e.event_datetime, false) %></span>
+  <%= content_tag('span', h(e.project), :class => 'project') %>
+  <%= link_to format_activity_title(e.event_title), e.event_url %></dt>
+  <dd><span class="description"><%= format_activity_description(e.event_description) %></span></dd>
+<% end -%>
+</dl>
+<% end -%>
+</div>
+
+<% other_formats_links do |f| %>
+       <%= f.link_to 'Atom', :url => {:controller => 'projects', :action => 'activity', :id => nil, :user_id => @user, :key => User.current.rss_key} %>
+<% end %>
+
+<% content_for :header_tags do %>
+               <%= auto_discovery_link_tag(:atom, :controller => 'projects', :action => 'activity', :user_id => @user, :format => :atom, :key => User.current.rss_key) %>
+<% end %>
+<% end %>
+<%= call_hook :view_account_right_bottom, :user => @user %>
+</div>
+
+<% html_title @user.name %>
index f3c25a791d2ce7587fd3f9906f97e35d4ee8725a..3f1024f5c35072a2ed18d9013d036999751594b9 100644 (file)
@@ -159,6 +159,7 @@ ActionController::Routing::Routes.draw do |map|
     users.with_options :conditions => {:method => :get} do |user_views|
       user_views.connect 'users', :action => 'list'
       user_views.connect 'users', :action => 'index'
+      user_views.connect 'users/:id', :action => 'show', :id => /\d+/
       user_views.connect 'users/new', :action => 'add'
       user_views.connect 'users/:id/edit/:tab', :action => 'edit', :tab => nil
     end
index 67c4d8b6c04e32d6503d655373782e7ddcda4849..17d19dfe18b3676194bc660fa00ab2fabe89d5fe 100644 (file)
@@ -31,36 +31,6 @@ class AccountControllerTest < ActionController::TestCase
     User.current = nil
   end
   
-  def test_show
-    get :show, :id => 2
-    assert_response :success
-    assert_template 'show'
-    assert_not_nil assigns(:user)
-  end
-
-  def test_show_should_not_fail_when_custom_values_are_nil
-    user = User.find(2)
-
-    # Create a custom field to illustrate the issue
-    custom_field = CustomField.create!(:name => 'Testing', :field_format => 'text')
-    custom_value = user.custom_values.build(:custom_field => custom_field).save!
-
-    get :show, :id => 2
-    assert_response :success
-  end
-  
-
-  def test_show_inactive
-    get :show, :id => 5
-    assert_response 404
-    assert_nil assigns(:user)
-  end
-  
-  def test_show_should_not_reveal_users_with_no_visible_activity_or_project
-    get :show, :id => 9
-    assert_response 404
-  end
-  
   def test_login_should_redirect_to_back_url_param
     # request.uri is "test.host" in test environment
     post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http%3A%2F%2Ftest.host%2Fissues%2Fshow%2F1'
index df87462a88f1d1de2a7fe7b9ea8ba6803153da7d..af7ba1b51df60db40efaefde3de6a6de49f0ee0a 100644 (file)
@@ -74,6 +74,49 @@ class UsersControllerTest < ActionController::TestCase
     assert_equal 1, users.size
     assert_equal 'John', users.first.firstname
   end
+  
+  def test_show_routing
+    assert_routing(
+      {:method => :get, :path => '/users/44'},
+      :controller => 'users', :action => 'show', :id => '44'
+    )
+    assert_recognizes(
+      {:controller => 'users', :action => 'show', :id => '44'},
+      {:method => :get, :path => '/users/44'}
+    )
+  end
+  
+  def test_show
+    @request.session[:user_id] = nil
+    get :show, :id => 2
+    assert_response :success
+    assert_template 'show'
+    assert_not_nil assigns(:user)
+  end
+
+  def test_show_should_not_fail_when_custom_values_are_nil
+    user = User.find(2)
+
+    # Create a custom field to illustrate the issue
+    custom_field = CustomField.create!(:name => 'Testing', :field_format => 'text')
+    custom_value = user.custom_values.build(:custom_field => custom_field).save!
+
+    get :show, :id => 2
+    assert_response :success
+  end
+  
+
+  def test_show_inactive
+    get :show, :id => 5
+    assert_response 404
+    assert_nil assigns(:user)
+  end
+  
+  def test_show_should_not_reveal_users_with_no_visible_activity_or_project
+    @request.session[:user_id] = nil
+    get :show, :id => 9
+    assert_response 404
+  end
 
   def test_add_routing
     assert_routing(