| Class | UsersController |
| In: |
app/controllers/users_controller.rb
|
| Parent: | GenericRestController |
# File app/controllers/users_controller.rb, line 28
28: def acting_as_user
29: User.acting_as_user_of_record do
30: @users = User.all_permitting :act_as
31: if !@users.include?( User.current )
32: @users = [ User.current ] + @users
33: end
34: @users = @users.sort_by &:search_name
35: if request.post?
36: assume_alias( User.find( params[:user_id].to_i ))
37: flash[:notice] = "Now acting as #{html_escape User.current.name}"
38: redirect_to :action => 'acting_as_user'
39: end
40: end
41: end
# File app/controllers/users_controller.rb, line 56
56: def edit
57: self.resource = find_resource
58: respond_to do |format|
59: format.html
60: format.js { render :layout => false }
61: end
62: end
Resources_controller doesn‘t turn off layouts for fubar.js.erb, so we have to do it here. Grumpf.
# File app/controllers/users_controller.rb, line 46
46: def show
47: self.resource = find_resource
48:
49: respond_to do |format|
50: format.html # show.rhtml
51: format.js { render :layout => false }
52: format.xml { render :xml => resource.to_xml }
53: end
54: end
# File app/controllers/users_controller.rb, line 64
64: def update
65: self.resource = find_resource
66:
67: respond_to do |format|
68: if resource.update_attributes(params[resource_name])
69: format.html do
70: flash[:notice] =
71: "#{resource_name.humanize} was successfully updated."
72: redirect_to resource_url
73: end
74: format.js { render :layout => false }
75: format.xml { head :ok }
76: else
77: format.html { render :action => "edit" }
78: format.js { render :action => "edit", :layout => false }
79: format.xml { render :xml => resource.errors.to_xml,
80: :status => :unprocessable_entity }
81: end
82: end
83: end
# File app/controllers/users_controller.rb, line 107
107: def find_resource( id = params[:id] )
108: set_instance_vars_for( User.find( id ).check_permission!( :administer ))
109: end
# File app/controllers/users_controller.rb, line 87
87: def find_resources
88: User.all_permitting :administer
89: end
# File app/controllers/users_controller.rb, line 91
91: def new_resource( attributes = params[:user] )
92:
93: user = set_instance_vars_for( User.new )
94:
95: # Setting firm before other attrs gets perms right more often
96: # on create... at least if there can be only one!
97:
98: if @firms.size == 1
99: user.firm = @firms.first
100: end
101:
102: user.attributes = attributes unless attributes.nil?
103: return user
104:
105: end