diff --git a/tracks/app/controllers/users_controller.rb b/tracks/app/controllers/users_controller.rb
index 9ff49a2f..0a099172 100644
--- a/tracks/app/controllers/users_controller.rb
+++ b/tracks/app/controllers/users_controller.rb
@@ -5,20 +5,37 @@ class UsersController < ApplicationController
before_filter :begin_open_id_auth, :only => :update_auth_type
end
- before_filter :admin_login_required, :only => [ :index, :destroy ]
+ before_filter :admin_login_required, :only => [ :index, :show, :destroy ]
skip_before_filter :login_required, :only => [ :new, :create ]
prepend_before_filter :login_optional, :only => [ :new, :create ]
+ # GET /users
+ # GET /users.xml
def index
- @page_title = "TRACKS::Manage Users"
- @user_pages, @users = paginate :users, :order => 'login ASC', :per_page => 10
- @total_users = User.find(:all).size
- # When we call users/signup from the admin page
- # we store the URL so that we get returned here when signup is successful
- expires_now
- store_location
+ respond_to do |format|
+ format.html do
+ @page_title = "TRACKS::Manage Users"
+ @user_pages, @users = paginate :users, :order => 'login ASC', :per_page => 10
+ @total_users = User.count
+ # When we call users/signup from the admin page
+ # we store the URL so that we get returned here when signup is successful
+ store_location
+ end
+ format.xml do
+ @users = User.find(:all)
+ render :xml => @users.to_xml(:except => [ :password ])
+ end
+ end
+ end
+
+ # GET /users/somelogin
+ # GET /users/somelogin.xml
+ def show
+ @user = User.find_by_login(params[:id])
+ render :xml => @user.to_xml(:except => [ :password ])
end
+ # GET /users/new
def new
if User.no_users_yet?
@page_title = "TRACKS::Sign up as the admin user"
@@ -42,6 +59,8 @@ class UsersController < ApplicationController
# -d 'usernameabc123'
# http://our.tracks.host/users
#
+ # POST /users
+ # POST /users.xml
def create
if params['exception']
render_failure "Expected post format is valid xml like so: usernameabc123."
@@ -94,29 +113,24 @@ class UsersController < ApplicationController
end
end
+ # DELETE /users/somelogin
+ # DELETE /users/somelogin.xml
def destroy
@deleted_user = User.find_by_id(params[:id])
@saved = @deleted_user.destroy
@total_users = User.find(:all).size
- respond_to do |wants|
-
- wants.html do
+ respond_to do |format|
+ format.html do
if @saved
notify :notice, "Successfully deleted user #{@deleted_user.login}", 2.0
- redirect_to :action => 'index'
else
notify :error, "Failed to delete user #{@deleted_user.login}", 2.0
- redirect_to :action => 'index'
end
+ redirect_to users_url
end
-
- wants.js do
- render
- end
-
- wants.xml { render :text => '200 OK. User deleted.', :status => 200 }
-
+ format.js
+ format.xml { head :ok }
end
end
diff --git a/tracks/app/models/user.rb b/tracks/app/models/user.rb
index 8a0f5d93..29a2f337 100644
--- a/tracks/app/models/user.rb
+++ b/tracks/app/models/user.rb
@@ -68,6 +68,10 @@ class User < ActiveRecord::Base
find(:first, :conditions => [ "is_admin = ?", true ])
end
+ def to_param
+ login
+ end
+
def display_name
if first_name.blank? && last_name.blank?
return login
diff --git a/tracks/config/routes.rb b/tracks/config/routes.rb
index 8a11edb1..9a4b3ae1 100644
--- a/tracks/config/routes.rb
+++ b/tracks/config/routes.rb
@@ -1,18 +1,4 @@
ActionController::Routing::Routes.draw do |map|
- # Add your own custom routes here.
- # The priority is based upon order of creation: first created -> highest priority.
-
- # Here's a sample route:
- # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
- # Keep in mind you can assign values other than :controller and :action
-
- # You can have the root of your site routed by hooking up ''
- # -- just remember to delete public/index.html.
- # map.connect '', :controller => "welcome"
-
- # Allow downloading Web Service WSDL as a file with an extension
- # instead of a file named 'wsdl'
- #map.connect ':controller/service.wsdl', :action => 'wsdl'
# Mobile/lite version
map.connect 'mobile', :controller => 'mobile', :action => 'index'
diff --git a/tracks/test/functional/users_controller_test.rb b/tracks/test/functional/users_controller_test.rb
index 286747f9..f00a6e26 100644
--- a/tracks/test/functional/users_controller_test.rb
+++ b/tracks/test/functional/users_controller_test.rb
@@ -1,6 +1,5 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'users_controller'
-require 'user'
# Re-raise errors caught by the controller.
class UsersController; def rescue_action(e) raise e end; end
@@ -34,6 +33,9 @@ class UsersControllerTest < Test::Unit::TestCase
login_as @admin_user
get :index
assert_response :success
+ assert_equal "TRACKS::Manage Users", assigns['page_title']
+ assert_equal 3, assigns['total_users']
+ assert_equal "/users", session['return-to']
end
def test_destroy_user
@@ -154,7 +156,6 @@ class UsersControllerTest < Test::Unit::TestCase
def assert_number_of_users_is_unchanged
assert_equal User.count, @num_users_in_fixture
- end
-
+ end
end
diff --git a/tracks/test/integration/create_user_api_test.rb b/tracks/test/integration/users_xml_api_test.rb
similarity index 81%
rename from tracks/test/integration/create_user_api_test.rb
rename to tracks/test/integration/users_xml_api_test.rb
index db58790d..634c3739 100644
--- a/tracks/test/integration/create_user_api_test.rb
+++ b/tracks/test/integration/users_xml_api_test.rb
@@ -4,7 +4,7 @@ require 'users_controller'
# Re-raise errors caught by the controller.
class UsersController; def rescue_action(e) raise e end; end
-class CreateUserControllerTest < ActionController::IntegrationTest
+class UsersXmlApiTest < ActionController::IntegrationTest
fixtures :users
@@foobar_postdata = "foobar"
@@ -73,9 +73,30 @@ class CreateUserControllerTest < ActionController::IntegrationTest
def test_fails_with_get_verb
authenticated_get_xml "/users", users(:admin_user).login, 'abracadabra', {}
end
+
+ def test_get_users_as_xml
+ get '/users.xml', {}, basic_auth_headers()
+ #puts @response.body
+ assert_response :success
+ assert_tag :tag => "users",
+ :children => { :count => 3, :only => { :tag => "user" } }
+ assert_no_tag :tag => "password"
+ end
+
+ def test_get_user_as_xml
+ get "/users/#{users(:other_user).login}.xml", {}, basic_auth_headers()
+ puts @response.body
+ assert_response :success
+ assert_tag :tag => "user"
+ assert_no_tag :tag => "password"
+ end
private
+ def basic_auth_headers(username = users(:admin_user).login, password = 'abracadabra')
+ {'AUTHORIZATION' => "Basic " + Base64.encode64("#{username}:#{password}") }
+ end
+
def authenticated_post_xml_to_user_create(postdata = @@foobar_postdata, user = users(:admin_user).login, password = 'abracadabra', headers = {})
authenticated_post_xml "/users", user, password, postdata, headers
end
diff --git a/tracks/test/selenium/login/first_run_shows_signup.rsel b/tracks/test/selenium/login/first_run_shows_signup.rsel
new file mode 100644
index 00000000..8f3f00ce
--- /dev/null
+++ b/tracks/test/selenium/login/first_run_shows_signup.rsel
@@ -0,0 +1,10 @@
+setup :clear_tables => [:users, :preferences]
+open '/'
+assert_title 'exact:TRACKS::Sign up as the admin user'
+type "user_login", "admin"
+type "user_password", "abracadabra"
+type "user_password_confirmation", "abracadabra"
+click_and_wait "signup"
+assert_title 'exact:TRACKS::Login'
+include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
+assert_title 'exact:TRACKS::List tasks'
diff --git a/tracks/test/unit/user_test.rb b/tracks/test/unit/user_test.rb
index 3b8a85d4..807dac38 100644
--- a/tracks/test/unit/user_test.rb
+++ b/tracks/test/unit/user_test.rb
@@ -138,5 +138,10 @@ class UserTest < Test::Unit::TestCase
def test_prefs_is_short_for_preference
assert_equal @admin_user.preference, @admin_user.prefs
end
+
+ def test_to_param_returns_login
+ assert_equal @admin_user.login, @admin_user.to_param
+ end
+
end