diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2010-12-20 17:45:09 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2010-12-20 17:45:09 +0000 |
commit | 599bc450730b91769f878d38b76110ce5c8fbca7 (patch) | |
tree | 1626b75596f1fd3a52cb54ce0e6008214cedb3e2 /app/controllers/users_controller.rb | |
parent | 84dd413f22b9a3900ceaa33d63758f285908ecb1 (diff) | |
download | redmine-599bc450730b91769f878d38b76110ce5c8fbca7.tar.gz redmine-599bc450730b91769f878d38b76110ce5c8fbca7.zip |
Adds support for requesting information about current user using /users/current (#7141).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4544 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/users_controller.rb')
-rw-r--r-- | app/controllers/users_controller.rb | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8bdc10614..2a213f5e8 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -19,6 +19,7 @@ class UsersController < ApplicationController layout 'admin' before_filter :require_admin, :except => :show + before_filter :find_user, :only => [:show, :edit, :update, :edit_membership, :destroy_membership] accept_key_auth :index, :show, :create, :update helper :sort @@ -61,8 +62,6 @@ class UsersController < ApplicationController end def show - @user = User.find(params[:id]) - # show projects based on current user visibility @memberships = @user.memberships.all(:conditions => Project.visible_by(User.current)) @@ -80,8 +79,6 @@ class UsersController < ApplicationController format.html { render :layout => 'base' } format.api end - rescue ActiveRecord::RecordNotFound - render_404 end def new @@ -130,16 +127,12 @@ class UsersController < ApplicationController end def edit - @user = User.find(params[:id]) - @auth_sources = AuthSource.find(:all) @membership ||= Member.new end verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } def update - @user = User.find(params[:id]) - @user.admin = params[:user][:admin] if params[:user][:admin] @user.login = params[:user][:login] if params[:user][:login] if params[:user][:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?) @@ -185,7 +178,6 @@ class UsersController < ApplicationController end def edit_membership - @user = User.find(params[:id]) @membership = Member.edit_membership(params[:membership_id], params[:membership], @user) @membership.save if request.post? respond_to do |format| @@ -208,7 +200,6 @@ class UsersController < ApplicationController end def destroy_membership - @user = User.find(params[:id]) @membership = Member.find(params[:membership_id]) if request.post? && @membership.deletable? @membership.destroy @@ -218,4 +209,17 @@ class UsersController < ApplicationController format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} } end end + + private + + def find_user + if params[:id] == 'current' + require_login || return + @user = User.current + else + @user = User.find(params[:id]) + end + rescue ActiveRecord::RecordNotFound + render_404 + end end |