Class: Admin::UsersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Admin::UsersController
- Defined in:
- app/controllers/admin/users_controller.rb
Overview
Fat Free CRM Copyright © 2008-2011 by Michael Dvorkin
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <www.gnu.org/licenses/>.
Instance Method Summary collapse
-
#confirm ⇒ Object
GET /admin/users/1/confirm AJAX —————————————————————————-.
-
#create ⇒ Object
POST /admin/users POST /admin/users.xml AJAX —————————————————————————-.
-
#destroy ⇒ Object
DELETE /admin/users/1 DELETE /admin/users/1.xml AJAX —————————————————————————-.
-
#edit ⇒ Object
GET /admin/users/1/edit AJAX —————————————————————————-.
-
#index ⇒ Object
GET /admin/users GET /admin/users.xml HTML —————————————————————————-.
-
#new ⇒ Object
GET /admin/users/new GET /admin/users/new.xml AJAX —————————————————————————-.
-
#reactivate ⇒ Object
PUT /admin/users/1/reactivate PUT /admin/users/1/reactivate.xml AJAX —————————————————————————-.
-
#show ⇒ Object
GET /admin/users/1 GET /admin/users/1.xml —————————————————————————-.
-
#suspend ⇒ Object
PUT /admin/users/1/suspend PUT /admin/users/1/suspend.xml AJAX —————————————————————————-.
-
#update ⇒ Object
PUT /admin/users/1 PUT /admin/users/1.xml AJAX —————————————————————————-.
Instance Method Details
#confirm ⇒ Object
GET /admin/users/1/confirm AJAX
120 121 122 123 124 125 |
# File 'app/controllers/admin/users_controller.rb', line 120 def confirm @user = User.find(params[:id]) rescue ActiveRecord::RecordNotFound respond_to_not_found(:js, :xml) end |
#create ⇒ Object
POST /admin/users POST /admin/users.xml AJAX
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/controllers/admin/users_controller.rb', line 79 def create params[:user][:password_confirmation] = nil if params[:user][:password_confirmation].blank? @user = User.new(params[:user]) @user.admin = (params[:user][:admin] == "1") respond_to do |format| if @user.save_without_session_maintenance @users = get_users format.js # create.js.rjs format.xml { render :xml => @user, :status => :created, :location => @user } else format.js # create.js.rjs format.xml { render :xml => @user.errors, :status => :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /admin/users/1 DELETE /admin/users/1.xml AJAX
130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'app/controllers/admin/users_controller.rb', line 130 def destroy @user = User.find(params[:id]) respond_to do |format| if @user.destroy format.js # destroy.js.rjs format.xml { head :ok } else flash[:warning] = t(:msg_cant_delete_user, @user.full_name) format.js # destroy.js.rjs format.xml { render :xml => @user.errors, :status => :unprocessable_entity } end end end |
#edit ⇒ Object
GET /admin/users/1/edit AJAX
64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/admin/users_controller.rb', line 64 def edit @user = User.find(params[:id]) if params[:previous].to_s =~ /(\d+)\z/ @previous = User.find($1) end rescue ActiveRecord::RecordNotFound @previous ||= $1.to_i respond_to_not_found(:js) unless @user end |
#index ⇒ Object
GET /admin/users GET /admin/users.xml HTML
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/admin/users_controller.rb', line 24 def index @users = get_users(:page => params[:page]) respond_to do |format| format.html # index.html.haml format.js # index.js.rjs format.xml { render :xml => User.all } format.xls { send_data @users.to_xls, :type => :xls } format.csv { send_data @users.to_csv, :type => :csv } format.rss { render "shared/index.rss.builder" } format.atom { render "shared/index.atom.builder" } end end |
#new ⇒ Object
GET /admin/users/new GET /admin/users/new.xml AJAX
53 54 55 56 57 58 59 60 |
# File 'app/controllers/admin/users_controller.rb', line 53 def new @user = User.new respond_to do |format| format.js # new.js.rjs format.xml { render :xml => @user } end end |
#reactivate ⇒ Object
PUT /admin/users/1/reactivate PUT /admin/users/1/reactivate.xml AJAX
168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'app/controllers/admin/users_controller.rb', line 168 def reactivate @user = User.find(params[:id]) @user.update_attribute(:suspended_at, nil) respond_to do |format| format.js # reactivate.js.rjs format.xml { render :xml => @user } end rescue ActiveRecord::RecordNotFound respond_to_not_found(:js, :xml) end |
#show ⇒ Object
GET /admin/users/1 GET /admin/users/1.xml
41 42 43 44 45 46 47 48 |
# File 'app/controllers/admin/users_controller.rb', line 41 def show @user = User.find(params[:id]) respond_to do |format| format.html # show.html.haml format.xml { render :xml => @user } end end |
#suspend ⇒ Object
PUT /admin/users/1/suspend PUT /admin/users/1/suspend.xml AJAX
152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'app/controllers/admin/users_controller.rb', line 152 def suspend @user = User.find(params[:id]) @user.update_attribute(:suspended_at, Time.now) if @user != @current_user respond_to do |format| format.js # suspend.js.rjs format.xml { render :xml => @user } end rescue ActiveRecord::RecordNotFound respond_to_not_found(:js, :xml) end |
#update ⇒ Object
PUT /admin/users/1 PUT /admin/users/1.xml AJAX
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/controllers/admin/users_controller.rb', line 99 def update params[:user][:password_confirmation] = nil if params[:user][:password_confirmation].blank? @user = User.find(params[:id]) @user.admin = (params[:user][:admin] == "1") respond_to do |format| if @user.update_attributes(params[:user]) format.js # update.js.rjs format.xml { head :ok } else format.js # update.js.rjs format.xml { render :xml => @user.errors, :status => :unprocessable_entity } end end rescue ActiveRecord::RecordNotFound respond_to_not_found(:js, :xml) end |