@@ -19,6 +19,7 class UsersController < ApplicationController | |||
|
19 | 19 | layout 'admin' |
|
20 | 20 | |
|
21 | 21 | before_filter :require_admin, :except => :show |
|
22 | before_filter :find_user, :only => [:show, :edit, :update, :edit_membership, :destroy_membership] | |
|
22 | 23 | accept_key_auth :index, :show, :create, :update |
|
23 | 24 | |
|
24 | 25 | helper :sort |
@@ -61,8 +62,6 class UsersController < ApplicationController | |||
|
61 | 62 | end |
|
62 | 63 | |
|
63 | 64 | def show |
|
64 | @user = User.find(params[:id]) | |
|
65 | ||
|
66 | 65 | # show projects based on current user visibility |
|
67 | 66 | @memberships = @user.memberships.all(:conditions => Project.visible_by(User.current)) |
|
68 | 67 | |
@@ -80,8 +79,6 class UsersController < ApplicationController | |||
|
80 | 79 | format.html { render :layout => 'base' } |
|
81 | 80 | format.api |
|
82 | 81 | end |
|
83 | rescue ActiveRecord::RecordNotFound | |
|
84 | render_404 | |
|
85 | 82 | end |
|
86 | 83 | |
|
87 | 84 | def new |
@@ -130,16 +127,12 class UsersController < ApplicationController | |||
|
130 | 127 | end |
|
131 | 128 | |
|
132 | 129 | def edit |
|
133 | @user = User.find(params[:id]) | |
|
134 | ||
|
135 | 130 | @auth_sources = AuthSource.find(:all) |
|
136 | 131 | @membership ||= Member.new |
|
137 | 132 | end |
|
138 | 133 | |
|
139 | 134 | verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } |
|
140 | 135 | def update |
|
141 | @user = User.find(params[:id]) | |
|
142 | ||
|
143 | 136 | @user.admin = params[:user][:admin] if params[:user][:admin] |
|
144 | 137 | @user.login = params[:user][:login] if params[:user][:login] |
|
145 | 138 | if params[:user][:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?) |
@@ -185,7 +178,6 class UsersController < ApplicationController | |||
|
185 | 178 | end |
|
186 | 179 | |
|
187 | 180 | def edit_membership |
|
188 | @user = User.find(params[:id]) | |
|
189 | 181 | @membership = Member.edit_membership(params[:membership_id], params[:membership], @user) |
|
190 | 182 | @membership.save if request.post? |
|
191 | 183 | respond_to do |format| |
@@ -208,7 +200,6 class UsersController < ApplicationController | |||
|
208 | 200 | end |
|
209 | 201 | |
|
210 | 202 | def destroy_membership |
|
211 | @user = User.find(params[:id]) | |
|
212 | 203 | @membership = Member.find(params[:membership_id]) |
|
213 | 204 | if request.post? && @membership.deletable? |
|
214 | 205 | @membership.destroy |
@@ -218,4 +209,17 class UsersController < ApplicationController | |||
|
218 | 209 | format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} } |
|
219 | 210 | end |
|
220 | 211 | end |
|
212 | ||
|
213 | private | |
|
214 | ||
|
215 | def find_user | |
|
216 | if params[:id] == 'current' | |
|
217 | require_login || return | |
|
218 | @user = User.current | |
|
219 | else | |
|
220 | @user = User.find(params[:id]) | |
|
221 | end | |
|
222 | rescue ActiveRecord::RecordNotFound | |
|
223 | render_404 | |
|
224 | end | |
|
221 | 225 | end |
@@ -120,6 +120,20 class UsersControllerTest < ActionController::TestCase | |||
|
120 | 120 | assert project_ids.include?(2) #private project admin can see |
|
121 | 121 | end |
|
122 | 122 | |
|
123 | def test_show_current_should_require_authentication | |
|
124 | @request.session[:user_id] = nil | |
|
125 | get :show, :id => 'current' | |
|
126 | assert_response 302 | |
|
127 | end | |
|
128 | ||
|
129 | def test_show_current | |
|
130 | @request.session[:user_id] = 2 | |
|
131 | get :show, :id => 'current' | |
|
132 | assert_response :success | |
|
133 | assert_template 'show' | |
|
134 | assert_equal User.find(2), assigns(:user) | |
|
135 | end | |
|
136 | ||
|
123 | 137 | def test_new |
|
124 | 138 | get :new |
|
125 | 139 |
@@ -50,6 +50,23 class ApiTest::UsersTest < ActionController::IntegrationTest | |||
|
50 | 50 | end |
|
51 | 51 | end |
|
52 | 52 | end |
|
53 | ||
|
54 | context "GET /users/current" do | |
|
55 | context ".xml" do | |
|
56 | should "require authentication" do | |
|
57 | get '/users/current.xml' | |
|
58 | ||
|
59 | assert_response 401 | |
|
60 | end | |
|
61 | ||
|
62 | should "return current user" do | |
|
63 | get '/users/current.xml', {}, :authorization => credentials('jsmith') | |
|
64 | ||
|
65 | assert_tag :tag => 'user', | |
|
66 | :child => {:tag => 'id', :content => '2'} | |
|
67 | end | |
|
68 | end | |
|
69 | end | |
|
53 | 70 | |
|
54 | 71 | context "POST /users" do |
|
55 | 72 | context "with valid parameters" do |
@@ -286,6 +286,7 class RoutingTest < ActionController::IntegrationTest | |||
|
286 | 286 | context "users" do |
|
287 | 287 | should_route :get, "/users", :controller => 'users', :action => 'index' |
|
288 | 288 | should_route :get, "/users/44", :controller => 'users', :action => 'show', :id => '44' |
|
289 | should_route :get, "/users/current", :controller => 'users', :action => 'show', :id => 'current' | |
|
289 | 290 | should_route :get, "/users/new", :controller => 'users', :action => 'new' |
|
290 | 291 | should_route :get, "/users/444/edit", :controller => 'users', :action => 'edit', :id => '444' |
|
291 | 292 | should_route :get, "/users/222/edit/membership", :controller => 'users', :action => 'edit', :id => '222', :tab => 'membership' |
General Comments 0
You need to be logged in to leave comments.
Login now