From 599bc450730b91769f878d38b76110ce5c8fbca7 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 20 Dec 2010 17:45:09 +0000 Subject: 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 --- app/controllers/users_controller.rb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'app/controllers/users_controller.rb') 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 -- cgit v1.2.3