##// END OF EJS Templates
AccountController#show (/account/show/:id) moved to UsersController#show (/users/:id)....
Jean-Philippe Lang -
r2874:a842769c3f38
parent child
Show More
@@ -1,5 +1,5
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
@@ -20,28 +20,7 class AccountController < ApplicationController
20 include CustomFieldsHelper
20 include CustomFieldsHelper
21
21
22 # prevents login action to be filtered by check_if_login_required application scope filter
22 # prevents login action to be filtered by check_if_login_required application scope filter
23 skip_before_filter :check_if_login_required, :only => [:login, :lost_password, :register, :activate]
23 skip_before_filter :check_if_login_required
24
25 # Show user's account
26 def show
27 @user = User.active.find(params[:id])
28 @custom_values = @user.custom_values
29
30 # show only public projects and private projects that the logged in user is also a member of
31 @memberships = @user.memberships.select do |membership|
32 membership.project.is_public? || (User.current.member_of?(membership.project))
33 end
34
35 events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
36 @events_by_day = events.group_by(&:event_date)
37
38 if @user != User.current && !User.current.admin? && @memberships.empty? && events.empty?
39 render_404 and return
40 end
41
42 rescue ActiveRecord::RecordNotFound
43 render_404
44 end
45
24
46 # Login request and validation
25 # Login request and validation
47 def login
26 def login
@@ -1,5 +1,5
1 # redMine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
@@ -16,7 +16,7
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class UsersController < ApplicationController
18 class UsersController < ApplicationController
19 before_filter :require_admin
19 before_filter :require_admin, :except => :show
20
20
21 helper :sort
21 helper :sort
22 include SortHelper
22 include SortHelper
@@ -51,6 +51,26 class UsersController < ApplicationController
51
51
52 render :action => "list", :layout => false if request.xhr?
52 render :action => "list", :layout => false if request.xhr?
53 end
53 end
54
55 def show
56 @user = User.active.find(params[:id])
57 @custom_values = @user.custom_values
58
59 # show only public projects and private projects that the logged in user is also a member of
60 @memberships = @user.memberships.select do |membership|
61 membership.project.is_public? || (User.current.member_of?(membership.project))
62 end
63
64 events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
65 @events_by_day = events.group_by(&:event_date)
66
67 if @user != User.current && !User.current.admin? && @memberships.empty? && events.empty?
68 render_404 and return
69 end
70
71 rescue ActiveRecord::RecordNotFound
72 render_404
73 end
54
74
55 def add
75 def add
56 if request.get?
76 if request.get?
@@ -47,7 +47,7 module ApplicationHelper
47 # Display a link to user's account page
47 # Display a link to user's account page
48 def link_to_user(user, options={})
48 def link_to_user(user, options={})
49 if user.is_a?(User)
49 if user.is_a?(User)
50 !user.anonymous? ? link_to(user.name(options[:format]), :controller => 'account', :action => 'show', :id => user) : 'Anonymous'
50 !user.anonymous? ? link_to(user.name(options[:format]), :controller => 'users', :action => 'show', :id => user) : 'Anonymous'
51 else
51 else
52 user.to_s
52 user.to_s
53 end
53 end
@@ -222,8 +222,7 module ApplicationHelper
222 end
222 end
223
223
224 def authoring(created, author, options={})
224 def authoring(created, author, options={})
225 author_tag = (author.is_a?(User) && !author.anonymous?) ? link_to(h(author), :controller => 'account', :action => 'show', :id => author) : h(author || 'Anonymous')
225 l(options[:label] || :label_added_time_by, :author => link_to_user(author), :age => time_tag(created))
226 l(options[:label] || :label_added_time_by, :author => author_tag, :age => time_tag(created))
227 end
226 end
228
227
229 def time_tag(time)
228 def time_tag(time)
1 NO CONTENT: file renamed from app/views/account/show.rhtml to app/views/users/show.rhtml
NO CONTENT: file renamed from app/views/account/show.rhtml to app/views/users/show.rhtml
@@ -159,6 +159,7 ActionController::Routing::Routes.draw do |map|
159 users.with_options :conditions => {:method => :get} do |user_views|
159 users.with_options :conditions => {:method => :get} do |user_views|
160 user_views.connect 'users', :action => 'list'
160 user_views.connect 'users', :action => 'list'
161 user_views.connect 'users', :action => 'index'
161 user_views.connect 'users', :action => 'index'
162 user_views.connect 'users/:id', :action => 'show', :id => /\d+/
162 user_views.connect 'users/new', :action => 'add'
163 user_views.connect 'users/new', :action => 'add'
163 user_views.connect 'users/:id/edit/:tab', :action => 'edit', :tab => nil
164 user_views.connect 'users/:id/edit/:tab', :action => 'edit', :tab => nil
164 end
165 end
@@ -31,36 +31,6 class AccountControllerTest < ActionController::TestCase
31 User.current = nil
31 User.current = nil
32 end
32 end
33
33
34 def test_show
35 get :show, :id => 2
36 assert_response :success
37 assert_template 'show'
38 assert_not_nil assigns(:user)
39 end
40
41 def test_show_should_not_fail_when_custom_values_are_nil
42 user = User.find(2)
43
44 # Create a custom field to illustrate the issue
45 custom_field = CustomField.create!(:name => 'Testing', :field_format => 'text')
46 custom_value = user.custom_values.build(:custom_field => custom_field).save!
47
48 get :show, :id => 2
49 assert_response :success
50 end
51
52
53 def test_show_inactive
54 get :show, :id => 5
55 assert_response 404
56 assert_nil assigns(:user)
57 end
58
59 def test_show_should_not_reveal_users_with_no_visible_activity_or_project
60 get :show, :id => 9
61 assert_response 404
62 end
63
64 def test_login_should_redirect_to_back_url_param
34 def test_login_should_redirect_to_back_url_param
65 # request.uri is "test.host" in test environment
35 # request.uri is "test.host" in test environment
66 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http%3A%2F%2Ftest.host%2Fissues%2Fshow%2F1'
36 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http%3A%2F%2Ftest.host%2Fissues%2Fshow%2F1'
@@ -74,6 +74,49 class UsersControllerTest < ActionController::TestCase
74 assert_equal 1, users.size
74 assert_equal 1, users.size
75 assert_equal 'John', users.first.firstname
75 assert_equal 'John', users.first.firstname
76 end
76 end
77
78 def test_show_routing
79 assert_routing(
80 {:method => :get, :path => '/users/44'},
81 :controller => 'users', :action => 'show', :id => '44'
82 )
83 assert_recognizes(
84 {:controller => 'users', :action => 'show', :id => '44'},
85 {:method => :get, :path => '/users/44'}
86 )
87 end
88
89 def test_show
90 @request.session[:user_id] = nil
91 get :show, :id => 2
92 assert_response :success
93 assert_template 'show'
94 assert_not_nil assigns(:user)
95 end
96
97 def test_show_should_not_fail_when_custom_values_are_nil
98 user = User.find(2)
99
100 # Create a custom field to illustrate the issue
101 custom_field = CustomField.create!(:name => 'Testing', :field_format => 'text')
102 custom_value = user.custom_values.build(:custom_field => custom_field).save!
103
104 get :show, :id => 2
105 assert_response :success
106 end
107
108
109 def test_show_inactive
110 get :show, :id => 5
111 assert_response 404
112 assert_nil assigns(:user)
113 end
114
115 def test_show_should_not_reveal_users_with_no_visible_activity_or_project
116 @request.session[:user_id] = nil
117 get :show, :id => 9
118 assert_response 404
119 end
77
120
78 def test_add_routing
121 def test_add_routing
79 assert_routing(
122 assert_routing(
General Comments 0
You need to be logged in to leave comments. Login now